id ) || empty( $admin_page_hooks ) ) {
return false;
}
$settings_page = false;
if ( ! empty( $admin_page_hooks['monsterinsights_dashboard'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_dashboard'] . '_page_monsterinsights_addons' ) {
$settings_page = true;
}
if ( ! empty( $admin_page_hooks['monsterinsights_settings'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_settings'] . '_page_monsterinsights_addons' ) {
$settings_page = true;
}
if ( ! empty( $admin_page_hooks['monsterinsights_network'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_network'] . '_page_monsterinsights_addons-network' ) {
$settings_page = true;
}
return $settings_page;
}
/**
* Maybe refreshes the addons page.
*
* @since 6.0.0
*
* @return null Return early if not refreshing the addons.
*/
function monsterinsights_maybe_refresh_addons() {
if ( ! monsterinsights_is_addons_page() ) {
return;
}
if ( empty( $_POST['google-analytics-for-wordpress-refresh-addons-submit'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST['google-analytics-for-wordpress-refresh-addons'], 'google-analytics-for-wordpress-refresh-addons' ) ) {
return;
}
monsterinsights_get_addons_data( MonsterInsights()->license->get_valid_license_key() );
}
add_action( 'current_screen', 'monsterinsights_maybe_refresh_addons' );
/**
* Callback to output the MonsterInsights addons page.
*
* @since 6.0.0
*/
function monsterinsights_addons_page() {
/**
* Developer Alert:
*
* Per the README, this is considered an internal hook and should
* not be used by other developers. This hook's behavior may be modified
* or the hook may be removed at any time, without warning.
*/
do_action('monsterinsights_head');
?>
license->get_valid_license_key() ) {
?>
0 ) {
?>
$addon ) {
monsterinsights_get_addon_card( $addon, $i, true, $installed_plugins );
}
?>
0 ) {
?>
', ' ', '' ); ?>
$addon ) {
monsterinsights_get_addon_card( $addon, $i, false, $installed_plugins );
}
?>
license->get_network_license_key() : MonsterInsights()->license->get_site_license_key();
$type = is_network_admin() ? MonsterInsights()->license->get_network_license_type() : MonsterInsights()->license->get_site_license_type();
// Get addons data from transient or perform API query if no transient.
if ( false === ( $addons = get_transient( '_monsterinsights_addons' ) ) ) {
$addons = monsterinsights_get_addons_data( $key );
}
// If no Addons exist, return false
if ( ! $addons ) {
return false;
}
// Iterate through Addons, to build two arrays:
// - Addons the user is licensed to use,
// - Addons the user isn't licensed to use.
$results = array(
'licensed' => array(),
'unlicensed'=> array(),
);
foreach ( (array) $addons as $i => $addon ) {
// Determine whether the user is licensed to use this Addon or not.
if (
empty( $type ) ||
( in_array( 'Pro', $addon->categories ) && ( $type != 'pro' && $type != 'master' ) ) ||
( in_array( 'Plus', $addon->categories ) && $type != 'plus' && $type != 'pro' && $type != 'master' ) ||
( in_array( 'Basic', $addon->categories ) && ( $type != 'basic' && $type != 'plus' && $type != 'pro' && $type != 'master' ) )
) {
// Unlicensed
$results['unlicensed'][] = $addon;
continue;
}
// Licensed
$results['licensed'][] = $addon;
}
// Return Addons, split by licensed and unlicensed.
return $results;
}
/**
* Pings the remote server for addons data.
*
* @since 6.0.0
*
* @param string $key The user license key.
* @return array Array of addon data otherwise.
*/
function monsterinsights_get_addons_data( $key ) {
$type = is_network_admin() ? MonsterInsights()->license->get_network_license_type() : MonsterInsights()->license->get_site_license_type();
// Get Addons
// If the key is valid, we'll get personalised upgrade URLs for each Addon (if necessary) and plugin update information.
if ( $key ) {
$addons = MonsterInsights()->license_actions->perform_remote_request( 'get-addons-data-v600', array( 'tgm-updater-key' => $key ) );
} else {
$addons = MonsterInsights()->license_actions->perform_remote_request( 'get-all-addons-data', array() );
}
// If there was an API error, set transient for only 10 minutes.
if ( ! $addons ) {
set_transient( '_monsterinsights_addons', false, 10 * MINUTE_IN_SECONDS );
return false;
}
// If there was an error retrieving the addons, set the error.
if ( isset( $addons->error ) ) {
set_transient( '_monsterinsights_addons', false, 10 * MINUTE_IN_SECONDS );
return false;
}
// Otherwise, our request worked. Save the data and return it.
set_transient( '_monsterinsights_addons', $addons, 4 * HOUR_IN_SECONDS );
return $addons;
}
/**
* Retrieve the plugin basename from the plugin slug.
*
* @since 6.0.0
*
* @param string $slug The plugin slug.
* @return string The plugin basename if found, else the plugin slug.
*/
function monsterinsights_get_plugin_basename_from_slug( $slug ) {
$keys = array_keys( get_plugins() );
foreach ( $keys as $key ) {
if ( preg_match( '|^' . $slug . '|', $key ) ) {
return $key;
}
}
return $slug;
}
/**
* Outputs the addon "box" on the addons page.
*
* @since 6.0.0
*
* @param object $addon Addon data from the API / transient call
* @param int $counter Index of this Addon in the collection
* @param bool $is_licensed Whether the Addon is licensed for use
* @param array $installed_plugins Installed WordPress Plugins
*/
function monsterinsights_get_addon_card( $addon, $counter = 0, $is_licensed = false, $installed_plugins = false ) {
// Setup some vars
$slug = str_replace( 'monsterinsights-', '', $addon->slug );
$slug = 'monsterinsights-' . $addon->slug;
if ( $slug === 'monsterinsights-ecommerce' ) {
$slug = 'ga-ecommerce';
}
$plugin_basename = monsterinsights_get_plugin_basename_from_slug( $slug );
$categories = implode( ',', $addon->categories );
if ( ! $installed_plugins ) {
$installed_plugins = get_plugins();
}
// If the Addon doesn't supply an upgrade_url key, it's because the user hasn't provided a license
// get_upgrade_link() will return the Lite or Pro link as necessary for us.
if ( ! isset( $addon->upgrade_url ) ) {
$addon->upgrade_url = monsterinsights_get_upgrade_link();
}
// Link user to doc to install MI pro to install addons
if ( ! monsterinsights_is_pro_version() && $is_licensed && ! isset( $installed_plugins[ $plugin_basename ] ) ) {
$addon->url = monsterinsights_get_url( 'addons-page', 'install-addons-link', "https://www.monsterinsights.com/docs/install-monsterinsights-pro-to-use-addons" );
}
// Output the card
?>
title ); ?>
image ) ) {
?>
excerpt ); ?>
url ) ) {
$addon->url = '';
}
?>