WordPress multiple widget in single plugin

There is absolutely no problem with registering several widgets inside one file. Widgets are separate classes, and unlike other programming languages, PHP will have no problem with your declaring two classes inside one file. add_action( ‘widgets_init’, ‘src_load_widgets’ ); function src_load_widgets() { register_widget( ‘Widget_SRC’ ); register_widget( ‘Widget_Rank ‘ ); } class Widget_SRC extends WP_Widget { // … Read more

Is there an action that is called when a post is restored from the trash?

There are multiple actions. Listed in order of appearance with their parameters: untrash_post – (int) $post_id // before restoring transition_post_status – (string) $new_status, ‘trash’, (object) $post trash_to_{$new_status} – (object) $post // useful to address a special trash to status action untrash_post_comments – (int) $post_id // before associated comments are untrashed untrashed_post_comments – (int) $post_id // … Read more

Is it possible to add an action to the currently running action?

You have to use a later (higher) priority. So use current_filter() to get the current hook and priority, add 1 to that priority, and register the next action: add_action( ‘init’, ‘func_1’ ); function func_1() { global $wp_filter; $hook = current_filter(); add_action( $hook, ‘func_2’, key( $wp_filter[ $hook ] ) + 1 ); } function func_2() { … Read more

woocommerce hook publish product

I recommand you to use the transition_post_status. See example below : add_action(‘transition_post_status’, ‘wpse_110037_new_posts’, 10, 3); function wpse_110037_new_posts($new_status, $old_status, $post) { if( $old_status != ‘publish’ && $new_status == ‘publish’ && !empty($post->ID) && in_array( $post->post_type, array( ‘product’) ) ) { //add some cde here } } This hook is really handy. It allows you to target a … Read more

Adding Button to Shop Page in WooCommerce [closed]

You need to go beyond CSS to do this. It requires hooking into the loop template like so: add_action( ‘woocommerce_after_shop_loop_item’, ‘my_112757_add_product_link’, 11 ); function my_112757_add_product_link() { global $product; echo ‘<a href=”‘ . esc_url( get_permalink( $product->id ) ) . ‘”>More Detail</a>’; } Put the above code in your theme’s functions.php file. You can also add a … Read more