Plugin Update Available?

Hi Ulmo

thanks for getting back to me.

Yes, you could use the Pro Reports system to send this data as a part of reports, but this approach requires making custom tokens for Reports.

To do that, here are the provided hooks:

// Create Custom tokens
add_filter( 'mainwp_pro_reports_tokens_groups', 'mycustom_reports_tokens_groups' );
function mycustom_reports_tokens_groups( $tokens ) {
       // examples
       $tokens['plugins']['sections'][] = array( 'name' => 'section.plugins.custompluginsection', 'desc' => 'Custom plugin section descriptions' );
       $tokens['plugins']['nav_group_tokens']['custompluginsection'] = 'Custom plugin section';
       $tokens['custompluginsection'][] = array( 'name' => 'plugin.custompluginsection.tokenname1', 'desc' => 'Token1 name descriptions' );
       $tokens['custompluginsection'][] = array( 'name' => 'plugin.custompluginsection.tokenname2', 'desc' => 'Token2 name descriptions' );
       return $tokens;

}

// token values
add_filter('mainwp_pro_reports_custom_tokens', 'mycustom_reports_custom_tokens');
function mycustom_reports_custom_tokens($tokens_values, $report) {
       $tokens_values['[plugin.custompluginsection.tokenname1]'] = 'Value for custom token name1';
       $tokens_values['[plugin.custompluginsection.tokenname2]'] = 'Value for custom token name2';
       return $tokens_values;
}

Now, you just need to get values for the tokens.

Here is one basic example that shows how you can get an array of all available updates:

$all_updates = array();

$websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );

while ( $websites && ( $website  = MainWP_DB::fetch_object( $websites ) ) ) {
	$wp_upgrades                 = json_decode( MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' ), true );
	$plugin_upgrades             = json_decode( $website->plugin_upgrades, true );
	$theme_upgrades              = json_decode( $website->theme_upgrades, true );
	$translation_upgrades        = json_decode( $website->translation_upgrades, true );
	$all_updates[ $website->id ] = array(
		'wp_core'     => $wp_upgrades,
		'plugins'     => $plugin_upgrades,
		'themes'      => $theme_upgrades,
		'translation' => $translation_upgrades,
	);
}
MainWP_DB::free_result( $websites );
1 Like