acafourek
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] Draft product checkout issue@jbojang There is another filter
woocommerce_variation_is_purchasable
that you can find here: https://github.com/woocommerce/woocommerce/blob/99da8f4aa4f2dd95cca40ab11df6c460d3d1bb8c/includes/class-wc-product-variation.php#L514I haven’t tested it but the code suggests it will behave similarly. One thing to note though is that you’ll probably need to adapt the code above a bit since Variations can’t really be in
draft
orpublish
status themselves, they inherit the post status of their parent. So you probably want to adapt the code to check the post status of the parent?Forum: Plugins
In reply to: [WooCommerce] Draft product checkout issueYou can use the
woocommerce_is_purchasable
filter to add your own validation step that will prevent un-published products from being added to the cart and will also remove any from the cart.My example:
add_filter('woocommerce_is_purchasable', 'prefix_wc_is_purchasable', 10, 2); function prefix_wc_is_purchasable( $is_purchasable, $object ) { if ( get_post_status( $object->get_id() ) !== "publish" ) return false; else return true; }
Forum: Plugins
In reply to: [WP Term Images] Modal window on edit term screenCame here looking for this fix and was not disappointed.
Editing those 2 lines worked like a charm, thanks @vesterde!
This is actually a feature in a WP Network that prevents an Editor of a site from affecting other sites. A user’s profile is the same across all sites in a network, so if Bob is a member of Sites A and B, he just has to edit his profile once to change it in both places.
Say an Editor from Site A edits Bob’s bio to say that he really loves crocodiles. Well Bob’s profile on Site B would also suddenly say that he loves crocodiles. Because we don’t want editors affecting other sites, WordPress doesn’t allow profile editing.
But, of course there is a way to get around it if you are sure you need to. Check out this post/comment thread.
Forum: Plugins
In reply to: [WooTumblog] WooTumblog loop conflictOkay, so Im telling you ahead of time I have not tested this and I’ve never used a WooThemes implementation before. But I took a peek inside Twenty Ten and knowing how wordpress works, I’ve come up with some educated guesses about where your code needs to go based on what you put above.
Loop.php
126 = Line 131
134= Line 139
139= Line 143Instead of single.php (which has been changed substantially int he past few updates), use loop-single.php
loop-single.php
23= Line 26
30= Line 33Again, Im not sure if these are all 100% accurate, but you should be able to find lines that are similar to what they are telling you to look for. If it works, make sure you post an update here to educate the future generations. Last note: since you are editing core files for a theme, make sure you never update this theme (if they release an update to Twenty Ten, it will show up in your Updates page)… if you update, it will erase all your customizations.
I’m researching the same functionality- if I encounter a solution, I’ll post it here
Forum: Plugins
In reply to: [User Photo] [Plugin: User Photo] All authors imagesI’ve achieved this on BecomeANewYorker.com
Unfortunately there really isnt a good way to get this done in PHP, so you will need to make a database query in order to get the data you need. This is how I did it:
<ul class="people"> <?php $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts .' WHERE post_status = "publish"'); if($authors): foreach($authors as $author) { ?>
This section looks in the WordPress posts database and gets you all of the post authors who have at least one published post. The ‘Distinct’ part of the query means that it will remove duplicates, so you end up with a list of unique published authors IDs.
<li class="<?php the_author_meta('ID', $author->post_author); ?>"> <div class="avatar"> <?php $user = get_the_author_meta('ID', $author->post_author); if(userphoto_exists($user)) userphoto($user); ?> </div>
This section simply pulls in the userphoto for each author (checking to see if a photo exists is covered in the User Photo plugin documentation).
<h2> <a href="<?php bloginfo('url');?>/author/<?php the_author_meta('user_nicename', $author->post_author); ?>" title="Become A New Yorker posts by <?php the_author_meta('first_name', $author->post_author); ?> <?php the_author_meta('last_name', $author->post_author); ?>"> <?php the_author_meta('first_name', $author->post_author); ?> <?php the_author_meta('last_name', $author->post_author); ?> </a> </h2> </li> <?php } ?> <?php endif; ?> </ul> <!-- end people -->
This last section puts the author first and last names under the userphoto along with link title, etc. It is a bunch of code, but is actually really simple stuff that would be about 2 lines in plain HTML. There are ways to optimize this so you arent looking up the author data repeatedly, but I just havent had a chance to go back and rework it yet. Hopefully this helps. So all the code is in one place, this is exactly what is above in one chunk:
<ul class="people"> <?php $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts .' WHERE post_status = "publish"'); if($authors): foreach($authors as $author) { ?> <li class="<?php the_author_meta('ID', $author->post_author); ?>"> <div class="avatar"> <?php $user = get_the_author_meta('ID', $author->post_author); if(userphoto_exists($user)) userphoto($user); ?> </div> <h2> <a href="<?php bloginfo('url');?>/author/<?php the_author_meta('user_nicename', $author->post_author); ?>" title="Become A New Yorker posts by <?php the_author_meta('first_name', $author->post_author); ?> <?php the_author_meta('last_name', $author->post_author); ?>"> <?php the_author_meta('first_name', $author->post_author); ?> <?php the_author_meta('last_name', $author->post_author); ?> </a> </h2> </li> <?php } ?> <?php endif; ?> </ul> <!-- end people -->
Forum: Alpha/Beta/RC
In reply to: Missing current_page_parent css class for custom post typesI’m also using this pretty successfully on a few sites, though I’ve cut out the individual css files. I have my main style.css file for my theme which has all my nav css in it and the only thing I need to edit on a per-post-type basis is the menu highlighting, so I thought a whole new file was a bit bulky for what I need.
So- I used your condition code in the header, but expanded it to cover 4 custom types I have and added <style> HTML tags around it.
<!-- This adds support for current page highlighting with custom posts --> <style> <?php if (is_singular('issue')) { ?> #menu-item-500 a { <?php } elseif (is_singular('news')) { ?> #menu-item-300 a { <?php } elseif (is_singular('videos')) { ?> #menu-item-250 a { <?php } elseif (is_singular('testimonial')) { ?> #menu-item-254 a { <?php } ?> color: #ff8608; } </style> <!-- end nav styling -->
Hopefully this is useful for some others as well!
Forum: Plugins
In reply to: [Plugin: Post From Site] Post to Custom Post TypeI’ve been using this plugin for a few days now and made a couple customizations along these lines you all might find useful. I’m using this for a front-end form which visitors can use to submit questions to the site admin. I’ve created a custom post type of ‘question’ and a custom taxonomy for ‘status’,
I previously added comments and custom code to this file so unfortunately I’m not sure what the exact lines are for everyone else- sorry for the confusion- but if you Ctrl+F you will find this section easily.
$postarr = array(); $postarr['post_title'] = $title; $postarr['post_content'] = $content; $postarr['comment_status'] = $pfs_options['pfs_comment_status']; $postarr['post_status'] = $pfs_options['pfs_post_status']; $postarr['post_author'] = $user_ID; $postarr['post_category'] = $categories; $postarr['tags_input'] = implode(',',$tags); $postarr['post_type'] = 'askmark'; //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($postarr, true)."</pre>\n"; $post_id = wp_insert_post($postarr); if (0 == $post_id) { $result['error'] = __("Unable to insert post- unknown error.",'pfs_domain'); } else { $result['success'] = __("Thanks for sending in your question for Mark! We hope to answer as many of these as possible here on the site so please check back soon! <br /><br /> <a href=\"https://reelectmayorfunkhouser.com/ask-mark/\">Click here to see previous questions.</a>",'pfs_domain'); $result['post'] = $post_id; //Added this section to write form data to custom meta boxes and custom taxonomy for post -custom code add_post_meta($post_id, 'meta_askmark_name', $title); add_post_meta($post_id, 'meta_askmark_town', $town); wp_set_object_terms( $post_id, 'New', 'status', false); //set the Ask Mark status to New- end added code } } else { //Custom randomized error messages -custom code $randomvar = rand(1,3); // Random var becomes a random number from 1 to 3 if ($randomvar == 1) $result['error'] = __("It looks like you either forgot to put in your name our your question!",'pfs_domain'); if ($randomvar == 2) $result['error'] = __("Hey, it looks like you forgot to enter either your name or your question!",'pfs_domain'); if ($randomvar == 3) $result['error'] = __("Wait! Don't forget to enter your name and a question for Mark!",'pfs_domain'); } //removed login requirement -custom code return $result; }
Explanation:
In the last $postarr line I set the custom post type to ‘question’ which is easy enough. Then I decided I want to customize the success message so I edited the output for $result[‘success’]- simply add your own HTML (but remember that since you are inside an echo function, put a \ before any quotes(“) in your HTML.
Separately I’ve created custom fields for Questions: one for the askers name and another for their hometown (Previously I also added a Hometown field to the PostfromSite form- saves as the variable $town). So here I add that data to the post with add_post_meta and then I use wp_set_object_terms to set the value of my custom taxonomy (‘status’) to New.
This way, when a site admin logs in, they go to the Questions section of the admin panel and see all the New questions that need to be replied to.
Below all of this is just some fun I had with error messages- randomly pick a number between 1-3 and then cycle through these error messages depending on the random number selected… an easy way to add a bit of uniqueness.
This might be helpful to some people looking to customize the form- I try and avoid editing plugin code when I can but I just needed to get this done this week.
Forum: Plugins
In reply to: [Plugin: Sociable] Not insert in excerpts?I second the recommendation to make this configurable… I’m using the excerpt for meta descriptions and it took me forever to figure out why I was seeing 2 sociable sets on one page! But thanks for posting the answer here, its just what I needed.
Forum: Fixing WordPress
In reply to: PHP Variable for current URLTo get the current URL, you can use a pretty simple PHP snippet (explained here: https://www.webcheatsheet.com/PHP/get_current_page_url.php )
Forum: Fixing WordPress
In reply to: [Widget Logic] Conditional check parent category help!I am having an issue that I think falls into this thread, though it is using condition descendants outside of widgets.
I have a parent category called ‘Sciences’ with ID=33; and a number of sub-categories within it. Here is the end goal: For every post within a child category of ‘Sciences’, I want to display the child category’s description below the post.
So if I have a post in category ‘Biology’ (ID=11) which is a child of the category ‘Sciences’, I want the Biology cat description to display. And if another post is in category ‘Geology’ (ID=12), also a child of ‘Sciences’, I want the Geology cat description to display.
I am just having a bit of trouble understanding how to use post_is_in_descendant_category.
Right now I have this code in my single.php file:
<div id=postinfo> <?php if ( in_category( 'Sciences' ) || post_is_in_descendant_category( 33 ) ) { } ?> </div>
and I also have this code in my functions.php file:
<?php if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '<ul class="category-bg widget %2$s">', 'after_widget' => '</ul>', 'before_title' => '<h2>', 'after_title' => '</h2>', )); ?> <?php /** * Tests if any of a post's assigned categories are descendants of target categories * * @param mixed $cats The target categories. Integer ID or array of integer IDs * @param mixed $_post The post * @return bool True if at least 1 of the post's categories is a descendant of any of the target categories * @see get_term_by() You can get a category by name or slug, then pass ID to this function * @uses get_term_children() Gets descendants of target category * @uses in_category() Tests against descendant categories * @version 2.7 */ function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $cat, 'category'); if ( $descendants && in_category( $descendants, $_post ) ) return true; } return false; } ?>
As you can see, most of this is just copied from the Codex (I haven’t gotten to the description part yet) and Im a bit hung up here.
Any advice in how to yield the kind of output I’m looking for? Any help is greatly appreciated!
-Thanks
-ac