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

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 );

Related

How to Create custom woocommerce dashboard Template

I am trying to create custom woocommerce dashboard for my custom wordpress theme, but i found a error message when i am trying to create custom woocommerce dashboard template.
Deprecated: Your theme version of my-account.php template is deprecated since version 2.6! Use the latest version, which supports multiple account pages and navigation, from WC 2.6.0 instead.
I have followed the woocommerce template pattern (yourtheme/woocommerce/myaccount/my-account.php.) but nothing help . Please see the attached image. problem will gone if i edit wp-config.php with define( 'WP_DEBUG_DISPLAY', false );
Thanks
I found a solution for this.
I have to use this two function in my-account.php file.
Then the error message gone.
do_action( 'woocommerce_account_navigation' );
do_action( 'woocommerce_account_content' );

Error: Either “offers”, “review”, or “aggregateRating” should be specified, in google search console

Iam using woocommerce in my wordpress site. The Products report was added to search console in late February, and with it came an abundance of warnings and an error titled: Either “offers”, “review”, or “aggregateRating” should be specified.
The Products report can be found under the enhancements section in Google Search Console. what are the causes of this error?
If you are using Yoast, I will recommend you to disable the Schema for Yoast in general but remember that if you are using blog section then it will hurt your blog.
Following code will disable the Yoast 11+ Schema. Put that in functions.php of your theme or child theme.
add_filter( 'wpseo_json_ld_output', '__return_false' );
And following code works for earlier versions of yoast.
function disable_yoast_schema_data($data){
$data = array();
return $data;
}
add_filter('wpseo_json_ld_output', 'disable_yoast_schema_data', 10, 1);
product Schema is possibly the cause of these errors, please try adding this to your functions
/**
* Remove the generated product schema markup from Product Category and Shop pages.
*/
function wc_remove_product_schema() {
remove_action( 'woocommerce_shop_loop', array( WC()->structured_data, 'generate_product_data' ), 10, 0 );
}
add_action( 'woocommerce_init', 'wc_remove_product_schema' );
Update
As you say you are using yoast i would look into the specific yoast woocoommerce plugin and the plugin docs to add the correct schema
https://developer.yoast.com/schema-documentation/woocommerce-seo/

Error adding codesample plugin to TinyMCE in WordPress

I'm using WordPress version 5.2.1.
I've downloaded the codesample plugin, because it's not included in WordPress by default.
I've uploaded it to the /wp-includes/js/tinymce/plugins folder
I've added a reference to prism.css and prism.js to my theme, as mentioned here.
I've activated the 'Advanced TinyMCE Configuration' and updated the 'Plugins' option to include 'codesample'.
When I load a page with a TinyMCE WYSIWYG editor, it no longer renders and my console reports:
"Uncaught TypeError: Cannot read property 'registry' of undefined" in the codesample plugin.min.js file.
I've noticed that the WordPress version of TinyMCE is an old version - 4.8.0 (2018-06-27). Do I need to manually update it? Is this good practise?
I just wondered if I'm missing part of the process?
Thanks.
UPDATE
I've added the plugin via Functions.php as advised:
wp_enqueue_style( 'style', get_stylesheet_directory_uri().'/tinymce/plugins/codesample/prism.css' );
wp_enqueue_script( 'script', get_stylesheet_directory_uri().'/tinymce/plugins/codesample/prism.js' );
function my_custom_plugins( $plugins ) {
$plugins['codesample'] = get_stylesheet_directory_uri().'/tinymce/plugins/codesample/plugin.min.js';
return $plugins;
}
add_filter( 'mce_external_plugins', 'my_custom_plugins' );
But how do I go about upgrading the TinyMCE editor to v5?

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());
}

Plugin Update Hook

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 );

Resources