Conditional hook based on the core function that is calling it

Much probably, using debug_backtrace in this fashion is wild hackerism… Based on @toscho’s tip, the following achieves the same results: add_filter( ‘get_blogs_of_user’, ‘reorder_users_sites’ ); function reorder_users_sites( $blogs ) { if( !did_action( ‘wp_before_admin_bar_render’ ) ) uasort( $blogs, ‘bf_uasort_by_blogname’ ); else uasort( $blogs, ‘bf_uasort_by_domain’ ); return $blogs; }

Getting term_id for newly created or edited term

Use the action created_term. Its first parameter is the $term_id. It is called in wp_insert_term() in wp-includes/taxonomy.php after a term was successful created: do_action(“created_term”, $term_id, $tt_id, $taxonomy); do_action(“created_$taxonomy”, $term_id, $tt_id); The second parameter is the term_taxonomy_id from the term_taxonomy table, and the last parameter is the taxonomy. So register an action with … add_action( ‘created_term’, … Read more

Adding Second Plugin Author

You can add the author as contributor and all I know, he does not get automatically write access to your svn repository. You can also just mentioning the other author without adding him as contributor. My personal opinion is, if you’re worried that the other author steals your code, then he is the wrong helper.

How to modify product page for Jigoshop

You need to edit the loop-shop.php file under template (remember the file can be auto updated, so you need a backup.) <?php global $columns, $per_page; do_action(‘jigoshop_before_shop_loop’); $loop = 0; if (!isset($columns) || !$columns) $columns = apply_filters(‘loop_shop_columns’, 4); //if (!isset($per_page) || !$per_page) $per_page = apply_filters(‘loop_shop_per_page’, get_option(‘posts_per_page’)); //if ($per_page > get_option(‘posts_per_page’)) query_posts( array_merge( $wp_query->query, array( ‘posts_per_page’ => … Read more

Secure Pages Best Practice

Not sure about the best practices, but I have a few custom login-sensitive pages which simply display a message if user is not logged and is trying to view the page directly: $logged_in = is_user_logged_in(); if($logged_in) { ?> <article id=”post”> <?php the_content(); ?> </article> <?php } else { _e(‘You are not logged in. Please ‘, … Read more

Auto gallery from folder contents

It sounds like you just need shortcode to gather the contents of a folder and display a grid of those items. The shortcode is pretty easy to setup. $gallery = do_shortcode(‘[folder_gallery title=”XYZ” folder=”wp-content/uploads/2015/11″]’ ); echo $gallery; Then you just need to glob a directory and render your gallery from the files. I didn’t include a … Read more

Check for template part, else filter content

Two code snippets here that are pretty self explanatory: Add a template from the plugin if none is present from the theme add_filter( ‘page_template’, ‘wpse110317_append_meta’ ); function wpse110317_append_meta( $template ) { is_singular() AND ! file_exists( get_template_directory().”/{$template}” ) AND $template = plugin_dir_path( __FILE__ ).”/{$template}”; return $template; } Append something to the content until there’s a template … Read more