PHPUnit test plugin activation

Actually you cannot activate your plugin using WP_UnitTestCase, because in the bootstrap.php you’ve already loaded your plugin as a mu-plugin. What I can suggest you to test your plugin activation is: call the do_action(‘activate_’ . FULL_ABSPATH_TO_YOUR_PLUGIN_PHP), where FULL_ABSPATH_TO_YOUR_PLUGIN_PHP will be something like: var/www/html/wordpress/wp-content/plugins/hello-world/hello-world.php In this example the hello-world plugin revoke’s a specified user’s capabilities on … Read more

How to: get main plugin/theme file?

You can get theme’s main file using following: $theme_info_file = trailingslashit( get_template_directory() ) . ‘style.css’; To get the plugin’s main file you need to know the plugin name. And then you can use following function: function get_plugin_file( $plugin_name ) { require_once( ABSPATH . ‘/wp-admin/includes/plugin.php’ ); $plugins = get_plugins(); foreach( $plugins as $plugin_file => $plugin_info ) … Read more

How to create a dynamic page based on form data with a plugin?

Something like this should work, though I’m not sure how meta, title, etc.. will behave, you’ll want to test everything thoroughly! function my_template_redirect() { global $wp; $qvs = $wp->query_vars; if (array_key_exists( ‘laundry’, $qvs && $qvs[‘laundry’] == ‘thank-you’ ) { global $wp_query; $wp_query->set( ‘is_404’, false ); // … now what? $post = new stdClass(); $post->ID= -99; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)