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

Overrides Plugin Files on WordPress Themes

If you’ve written the plugin, then I’d suggest you add something like this: // Define these constants once in your main plugin init file define( ‘YOUR_PLUGIN_SLUG’, ‘your-plugin-slug’ ); define( ‘YOUR_PLUGIN_DIR’, plugin_dir_path( __FILE__ ) ); define( ‘YOUR_PLUGIN_TEMPLATE_DIR’, trailingslashit( YOUR_PLUGIN_DIR ) . ‘templates’ ); define( ‘YOUR_PLUGIN_THEME_TEMPLATE_OVERRIDE_PATH_DIR’, trailingslashit( get_stylesheet_directory() . “https://wordpress.stackexchange.com/” . YOUR_PLUGIN_SLUG ); // Define a function … Read more

What action is called when drafts are saved?

After WP 2.3 you have for all status an hook: {$new_status}_{$post->post_type} Alternative you can use ans if for the status on hook save_post; an example for post_type post, you can change this ‘post’ to your post_type or defaults form WP: public function set_status_private($id, $post) { if ( is_object($post) && ‘post’ === $post->post_type && ‘publish’ === … Read more

How to check if certain plugin exists and in expected version

There is is_plugin_active() function. Other method is to check if functions or classes, specific to required plugin, exist. Some plugins explicitly define their own constants for this, typically with version number and/or other identifying info. There has been some developments to make extension dependence logic more generic, such as Plugin Dependecies, but they hadn’t gained … Read more