Use wc_enqueue_js only on specific pages – nested add_action

No idea why, but for the second snippet, changing the priority of the nested add_action from the default (10) to 20, causing the parent and child add_action to have a different priority solved the problem and now everything works perfectly: add_action( ‘template_redirect’, function() use ( $args ) { acau_enqueue_script ( $args ); }, 20); The … Read more

get plugin directory url

Use plugin_dir_url( __FILE__ ); for the URL and plugin_dir_path( __FILE__ ); for the path. Pass the plugin’s main file to both functions to get similar results. Besides that, ADMIN_PATH and ADMIN_DIR are really poor names for custom code. They might result in collisions with other code in the future. Try to use better names, something … Read more

Multiple Permalinks for custom post type post

Yes this is possible using add_rewrite_rule(), something along the lines of add_rewrite_rule( ‘test-subject/(\d+)/?’, ‘index.php?post_type=CPT_slug&post_id=$matches[1]’ ); add_rewrite_rule( ‘ts/(\d+)/?’, ‘index.php?post_type=CPT_slug&post_id=$matches[1]’ ); It might be a bit trickier though, since test-subject/test-title and test-subject/post_id are quite similar. Adding the post_id-rule with the 3rd argument as ‘top’ might help.

How to include class from addon after to be sure one class exists in the main plugin?

I found this answer which seems to be good. I used the hooks plugins_loaded and _admin_menu. The hook _admin_menu is before admin_menu so I can add an admin page menu. FooAddon.php namespace PluginFoo; class FooAddon{ public function __construct(){ // Install needed components on plugin activation register_activation_hook( __FILE__, array( $this, ‘install’ ) ); // Include dependencies … Read more

How to Reload the Dashboard After Clicking Update in Quick-Edit?

We have to intercept the Ajax end point of that action. The file wp-admin/admin-ajax.php has all the possible hooks in the $core_actions_post array. The function wpse_65157_ajax_inline_save() is a copy of the Core’s, with a “force reload” script printed at the end. It has to be with Javascript, as wp_redirect() doesn’t work. add_action( ‘wp_ajax_inline-save’, ‘wpse_65157_ajax_inline_save’ , … Read more