Stop a plugin in the activation process when a certain WP version is not met then show error message in admin_notices action hook

I may be late to this party, but to stop plugin activation and have WordPress show an error message where the admin notices go, I simply output an error message and terminate execution. This has the added advantage of playing nice with wp-cli: Example: class testPlugin() { … static function activate() { //[do some stuff … Read more

Woocommerce: assign an “author” to a product

Simply use add_post_type_support: add_action(‘init’, ‘wpse_74054_add_author_woocommerce’, 999 ); function wpse_74054_add_author_woocommerce() { add_post_type_support( ‘product’, ‘author’ ); } User assigned with custom role Authors enabled in Products post type Another option, which I’m not sure of its correctness, it to hook into woocommerce_register_post_type* and register the post type first. This is a copy of the original function plus … Read more

How to Add WYSIWYG Editor (tinyMCE) to plugin options page compatible with WordPress 3.0 and up?

Pre WP 3.3: http://www.dev4press.com/2010/tutorials/wordpress/tips/add-rich-text-editor-to-your-plugin/ If you are using WP 3.3 or later you might look up wp_editor: http://codex.wordpress.org/Function_Reference/wp_editor $settings = array( ‘teeny’ => true, ‘textarea_rows’ => 15, ‘tabindex’ => 1 ); wp_editor(esc_html( __(get_option(‘whatever_you_need’, ‘whatever’))), ‘terms_wp_content’, $settings);

Is it bad practice to create own table for a plugin?

I rarely disagree with otherwise knowledgeable users, but in this case I can’t help it. In my opinion calling the usage of non-core database tables bad practice per se is just simply wrong. The choice of whether to go with core tables or add your own depends on several factors. A query’s execution time depends … Read more

wp_dequeue_style not working

Okay so I figured this one out. function custom_dequeue() { wp_dequeue_style(‘et-gf-open-sans’); wp_deregister_style(‘et-gf-open-sans’); } add_action( ‘wp_enqueue_scripts’, ‘custom_dequeue’, 9999 ); add_action( ‘wp_head’, ‘custom_dequeue’, 9999 ); @milo was right. The plugin was re-enqueueing it so the deregistering it got that file to stop loading. Then the plugin also had another check, where it would register and enqueue another … Read more

Why is it important to deactivate a plugin before deleting it?

Generally, plugins have some functionality hooked onto the deactivation action. This could be clearing cache, resetting options, you name it. Therefore the best practice is to deactivate them first, so they have the opportunity to clean up and execute whatever functionality they have hooked onto the deactivate event. Now if the plugin is broken and … Read more

Disable /wp-admin/plugin-install.php

There is a constant you can define in wp-config.php to do this. It will also disable the theme edit, however. <?php // somewhere in wp-config.php define(‘DISALLOW_FILE_MODS’, true); That will remove the plugin and theme file editor (which are a terrible idea anyway) and remove the ability to install plugins and themes from the admin area.

How to create custom message on plugin update

This message is created by W3_Total_Cache->in_plugin_update_message() hooked to “in_plugin_update_message-$file”in wp_plugin_update_row(). It does some nifties to parse readme and display info from changelog, but overall you can just echo some stuff as with any other hook.

Turn Off Auto Update for Single Plugin

you place this in your theme’s functions.php // Disable update notification for individual plugins – see my example of plugin block-spam-by-math-reloaded as to how to use this function function filter_plugin_updates( $value ) { unset( $value->response[‘plugin-folder-name/plugin-file-name.php’] ); return $value; } add_filter( ‘site_transient_update_plugins’, ‘filter_plugin_updates’ );