how to set context in WordPress for unit testing

If you have phpUnit configured for testing a WP plugin, you can use a test case like this: In your plugin-directory/tests/Some_Test_Case.php: class Plugin_Test extends WP_UnitTestCase { /** * @dataProvider post_IDs_and_expected_results */ public function test_something( $post_id, $expected_result ) { global $post; $post = get_post( $post_id ); $plugin_content = call_plugin_function(); // Your function name here $this->assertEquals( $expected_result, … Read more

How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”

I found a way to get it done but I am not very happy with this procedure. Please add your answer if you find better way. Mean while, this might be of help. add_action(‘admin_head-edit.php’,’addCustomImportButton’)); I only need this on edit page, so I am using admin_head-edit.php action, but you can use admin_head or some other … Read more

WordPress template_include filter not working properly

Ok i done by my own. I delete all above code and write this code. It works perfectly for me Code: function template_chooser($template){ global $wp_query; $plugindir = dirname(__FILE__); $post_type = get_query_var(‘post_type’); if( $post_type == ‘product’ ){ return $plugindir . ‘/themefiles/single-product.php’; } if (is_tax(‘prodcategories’)) { return $plugindir . ‘/themefiles/taxonomy-prodcategories.php’; } return $template; } add_filter(‘template_include’, ‘template_chooser’);

Custom role capabilities to administrator not taking effect (no plugin)

Capabilities are stored in database, that is why they keep active even if you remove your function. Capabilities need to be expressly removed: $admin = get_role(‘author’); $admin->remove_cap( ‘edit_teacher’ ); And, because they are stored in database, you should stop adding them in every page load (as you are doing in init event). Usually, you should … Read more