Plugin Update Hook - wordpress

My plugin needs to fire an init/build/checker function when the plugin is updated via auto updates in the WP dashboard.
Is there a WordPress hook that is fired after a plugin has been updated from the wordpress.org repository?
I'm not looking for register_activation_hook or register_deactivation_hook as those only execute on manual activation/deactivation.

Yes, upgrader_process_complete [see also: core reference] does that. Inspect the second parameter to know if it is a core, plugin or theme update; and if it is bulk or not.
add_action( 'upgrader_process_complete', function( $upgrader_object, $options ) {
// inspect $options
}, 10, 2 );

Related

Search WordPress Hook for completed Elementor Update

I am using WordPress and Elementor and looking for a hook that will fire when an Elementor update is completed.
The hook should execute the Elementor function
Regenerating CSS.
This Elementor code should be executed with it:
function clear_elementor_cache() {
// Make sure that Elementor loaded and the hook fired
if ( did_action( 'elementor/loaded' ) ) {
// Automatically purge and regenerate the Elementor CSS cache
\Elementor\Plugin::instance()->files_manager->clear_cache();
}
}
Code Source
How do I use the WordPress hook "upgrader_process_complete" to clear the Elementor cache?

Disable WP Gutenberg prepublish checks globaly

Im creating custom user edit post interface and i need to completely remove gutenberg pos prepublish checks and publish. How can i do this?
You can disable the publish sidebar completly with
wp.data.dispatch('core/editor').disablePublishSidebar();
Simply enqueue this JS with a dependance to .
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_script( 'so69031961', 'gutenberg-editor.js', [ 'wp-edit-post', 'wp-dom-ready' ] );
} );
This will have the same effect than unchecking this box :
So yes, your users might still be able to reactivate the checks, but it's better than nothing ;)

WP Bakery Page Builder loses settings in Role Manager

We are using WP Bakery Page Builder on for a client website. The plugin works fine, but sometimes the settings in Role Manager, for what post types the composer should be on just resets.
We are researching the possibility to hack the settings programmatically to set it to On be default.
Just wanted to check if anyone else have noticed this issue.
This is a bug in older versions. The developers posted a fix for it here:
https://codecanyon.net/item/visual-composer-page-builder-for-wordpress/242431/comments?utf8=%E2%9C%93&term=add_custom_post_type_here&from_buyers_and_authors_only=0
<?php
/*
You can set the post type for which the editor should be
available by adding the following code to functions.php:
*/
add_action( 'vc_before_init', 'Use_wpBakery' );
function Use_wpBakery() {
$vc_list = array('page','capabilities','add_custom_post_type_here');
vc_set_default_editor_post_types($vc_list);
vc_editor_set_post_types($vc_list);
}
Edit: Updated link to dev comment.
Just found this on another thread, which recommended adding this to your theme's custom code:
<script>$vc_list = array( ‘page’, ‘post’ ); vc_editor_set_post_types( $vc_list );
</script>

Wordpress custom hook to fetch plugin version (latest) after update it

im trying to get plugin name and plugin versions of plugins that has been recently updated and save it to a txt file.
Example in this txt file:
Jetpack had version 3.9.2 now its 3.9.4
Is there a way to make a custom hook that find the update process and retrieve the update number?
Maybe you can try it with upgrader_process_complete.
add_action( 'upgrader_process_complete', function( $upgrader_object, $options ) {
// inspect $options
}, 10, 2 );

how to display "There are updates available for your Custom Plugin" in wordpress

I have developed a custom wordpress plugin, many users have started using it, but now I have updates available for the plugin and want to display a message to the users who have older versions of the plugin on there site.
How can I modify the code of my plugin so that once I make updates to it, it should trigger a message to the users on the plugin dashboard that there are updates to available to your plugin.
Here is a scenario:
Say a user has version 1.0 of my plugin and the place where I host the plugin has version 1.2, how can I notify the user on his plugins page that my plugin has an updated version??
Although user3042036 answer is great, and very comprehensive, I thought I would entend his / her answer with a open source solution.
This is what you are looking for: WordPress Plugin Update Notifier
First, good practice is to create a constant for your current plugin version, and create an activation and deactivation hook for your plugin. This allows you to check things like version numbers, and do some general initialization.
define ( 'MY_PLUGIN_VERSION', '2.0.0');
register_activation_hook(__FILE__, 'my_plugin_activation'));
register_deactivation_hook(__FILE__, 'my_plugin_deactivation'));
function my_plugin_activation() {
// Initialize some stuff for my_plugin
}
function my_plugin_deactivation() {
// Welp, I've been deactivated - are there some things I should clean up?
}
Here is an example of a typical update function:
function my_plugin_activation() {
$version = get_option( 'my_plugin_version' );
if( version_compare($version, '2.0.0', '<')) {
// Do some special things when we update to 2.0.0.
}
update_option( 'my_plugin_version', MY_PLUGIN_VERSION );
return MY_PLUGIN_VERSION;
}
There is no hook for when your plugin is updated. You, as a plugin
author, have to manually check the plugin version. First, you want to
create a simple function which will tell you if your plugin is up to
date:
function my_plugin_is_current_version(){
$version = get_option( 'my_plugin_version' );
return version_compare($version, MY_PLUGIN_VERSION, '=') ? true : false;
}
Then, test if your plugin is up to date, and call your update function (or in this case we call the same function as we would if the plugin was updated!):
if ( !my_plugin_is_current_version() ) my_plugin_activation();
Testing the update process from one version to the next is not all that complicated, though it is kinda cumbersome. Maybe someone has a better way, if so please tell me!
You can’t really see any errors when you activate a plugin, so the first step is to create a very simple hook to store plugin activation errors. In this case, we store these errors in error_activation.html in the plugin folder
add_action('activated_plugin', 'my_plugin_activation_error');
my_plugin_activation_error() {
file_put_contents( plugin_dir_path(__FILE__) . '/error_activation.html', ob_get_contents());
}

Resources