'Icon URI',
'SupportForumURI' => 'Support Forum URI',
'DocumentationURI' => 'Documentation URI',
);
$extsPages = array();
$compatible_v4_checks = array(
'advanced-uptime-monitor-extension/advanced-uptime-monitor-extension.php',
'mainwp-article-uploader-extension/mainwp-article-uploader-extension.php',
'mainwp-backwpup-extension/mainwp-backwpup-extension.php',
'boilerplate-extension/boilerplate-extension.php',
'mainwp-branding-extension/mainwp-branding-extension.php',
'mainwp-bulk-settings-manager/mainwp-bulk-settings-manager.php',
'mainwp-clean-and-lock-extension/mainwp-clean-and-lock-extension.php',
'mainwp-client-reports-extension/mainwp-client-reports-extension.php',
'mainwp-clone-extension/mainwp-clone-extension.php',
'mainwp-code-snippets-extension/mainwp-code-snippets-extension.php',
'mainwp-comments-extension/mainwp-comments-extension.php',
'mainwp-favorites-extension/mainwp-favorites-extension.php',
'mainwp-file-uploader-extension/mainwp-file-uploader-extension.php',
'mainwp-google-analytics-extension/mainwp-google-analytics-extension.php',
'mainwp-maintenance-extension/mainwp-maintenance-extension.php',
'mainwp-piwik-extension/mainwp-piwik-extension.php',
'mainwp-post-dripper-extension/mainwp-post-dripper-extension.php',
'mainwp-rocket-extension/mainwp-rocket-extension.php',
'mainwp-sucuri-extension/mainwp-sucuri-extension.php',
'mainwp-team-control/mainwp-team-control.php',
'mainwp-updraftplus-extension/mainwp-updraftplus-extension.php',
'mainwp-url-extractor-extension/mainwp-url-extractor-extension.php',
'mainwp-woocommerce-shortcuts-extension/mainwp-woocommerce-shortcuts-extension.php',
'mainwp-woocommerce-status-extension/mainwp-woocommerce-status-extension.php',
'mainwp-wordfence-extension/mainwp-wordfence-extension.php',
'wordpress-seo-extension/wordpress-seo-extension.php',
'mainwp-page-speed-extension/mainwp-page-speed-extension.php',
'mainwp-ithemes-security-extension/mainwp-ithemes-security-extension.php',
'mainwp-post-plus-extension/mainwp-post-plus-extension.php',
'mainwp-staging-extension/mainwp-staging-extension.php',
'mainwp-custom-post-types/mainwp-custom-post-types.php',
'mainwp-buddy-extension/mainwp-buddy-extension.php',
'mainwp-vulnerability-checker-extension/mainwp-vulnerability-checker-extension.php',
'mainwp-timecapsule-extension/mainwp-timecapsule-extension.php',
'activity-log-mainwp/activity-log-mainwp.php',
);
include_once ABSPATH . '/wp-admin/includes/plugin.php'; // NOSONAR - WP compatible.
$deactivated_imcompatible = array();
foreach ( $init_extensions as $extension ) {
$slug = plugin_basename( $extension['plugin'] );
$plugin_data = get_plugin_data( $extension['plugin'], true, false );
$file_data = get_file_data( $extension['plugin'], $extraHeaders );
if ( ! isset( $plugin_data['Name'] ) || ( '' === $plugin_data['Name'] ) ) {
continue;
}
if ( in_array( $slug, $compatible_v4_checks ) ) {
$check_minver = '3.99999';
if ( 'advanced-uptime-monitor-extension/advanced-uptime-monitor-extension.php' === $slug ) {
$check_minver = '4.6.2';
} elseif ( 'activity-log-mainwp/activity-log-mainwp.php' === $slug ) {
$check_minver = '1.0.5';
}
if ( isset( $plugin_data['Version'] ) && version_compare( $plugin_data['Version'], $check_minver, '<' ) ) {
$deactivated_imcompatible[] = $plugin_data['Name'];
deactivate_plugins( $slug, true );
continue;
}
}
$extension['slug'] = $slug;
if ( ! isset( $extension['name'] ) ) {
$extension['name'] = $plugin_data['Name'];
}
$extension['version'] = $plugin_data['Version'];
$extension['description'] = $plugin_data['Description'];
$extension['author'] = $plugin_data['Author'];
$extension['icon'] = isset( $extension['icon'] ) ? trim( $extension['icon'] ) : '';
$extension['iconURI'] = $file_data['IconURI'];
$extension['SupportForumURI'] = $file_data['SupportForumURI'];
$extension['DocumentationURI'] = $file_data['DocumentationURI'];
$extension['page'] = 'Extensions-' . str_replace( ' ', '-', ucwords( str_replace( '-', ' ', dirname( $slug ) ) ) );
if ( isset( $extension['apiManager'] ) && $extension['apiManager'] ) {
$api_slug = dirname( $slug );
if ( $is_cached ) {
$options = isset( $activations_cached[ $api_slug ] ) ? $activations_cached[ $api_slug ] : array();
// MWP-1546 (Codex follow-up): pre-MWP-1546 builds persisted
// the full decrypted activation array (including plaintext
// 'api_key') into mainwp_extensions_all_activation_cached.
// On upgrade those rows survive as long as the cache stays
// populated. Treat any cache-hit entry that still carries
// 'api_key' as untrusted legacy data: strip it, derive
// has_api_key, and rewrite the sanitized entry in the
// cache so the plaintext never sees another disk write.
if ( is_array( $options ) && array_key_exists( 'api_key', $options ) ) {
$had_key = ! empty( $options['api_key'] );
unset( $options['api_key'] );
$options['has_api_key'] = $had_key;
$activations_cached[ $api_slug ] = $options;
// Force the post-loop update_option write below to fire.
$is_cached = false;
}
} else {
$options = MainWP_Api_Manager::instance()->get_activation_info( $api_slug );
if ( ! is_array( $options ) ) {
$options = array();
}
// MWP-1546: the activations_cached option is persisted via
// update_option(). Storing the decrypted api_key here would
// re-leak the plaintext into another database row,
// defeating the at-rest encryption added to set_activation_info().
// Cache only the non-credential fields plus a has_api_key
// boolean so the cache-hit path knows whether a key is
// configured without ever holding the plaintext.
$cached_options = $options;
unset( $cached_options['api_key'] );
$cached_options['has_api_key'] = ! empty( $options['api_key'] );
$activations_cached[ $api_slug ] = $cached_options;
}
if ( ! is_array( $options ) ) {
$options = array();
}
// MWP-1546: stop persisting the per-extension license key
// into the aggregated mainwp_extensions option. The original
// 'api_key' field on $extension was a plaintext string sourced
// from get_activation_info(); render code that needs to know
// "is a key configured?" should consult 'has_api_key' instead.
// The deactivate flow uses a server-side sentinel-resolution
// path (see MainWP_Post_Extension_Handler::deactivate_extension)
// that fetches the real key from the per-slug option at the
// moment of use, never via the aggregate.
//
// The cache-hit path stores has_api_key directly (see above);
// the fresh-load path infers it from the decrypted plaintext.
$extension['has_api_key'] = isset( $options['has_api_key'] ) ? (bool) $options['has_api_key'] : ! empty( $options['api_key'] );
$extension['activated_key'] = isset( $options['activated_key'] ) ? $options['activated_key'] : 'Deactivated';
$extension['deactivate_checkbox'] = isset( $options['deactivate_checkbox'] ) ? $options['deactivate_checkbox'] : 'off';
$extension['product_id'] = isset( $options['product_id'] ) ? $options['product_id'] : '';
$extension['instance_id'] = isset( $options['instance_id'] ) ? $options['instance_id'] : '';
$extension['software_version'] = isset( $options['software_version'] ) ? $options['software_version'] : '';
$extension['mainwp_version'] = isset( $options['mainwp_version'] ) ? $options['mainwp_version'] : '';
if ( isset( $options['product_item_id'] ) ) {
$extension['product_item_id'] = $options['product_item_id'];
}
}
$ext_slug = dirname( $slug );
if ( isset( $all_available_extensions[ $ext_slug ] ) ) {
$extension['type'] = $all_available_extensions[ $ext_slug ]['type']; // to fix.
}
$save_extensions[] = $extension;
if ( \mainwp_current_user_can( 'extension', dirname( $slug ) ) ) {
$callback = isset( $extension['callback'] ) ? $extension['callback'] : '';
$menu_name = MainWP_Extensions_Handler::polish_ext_name( $extension );
if ( MainWP_Extensions_Handler::added_on_menu( $slug ) ) {
$_page = add_submenu_page( 'mainwp_tab', $extension['name'], $menu_name, 'read', $extension['page'], $callback );
} else {
$_page = add_submenu_page( 'mainwp_tab', $extension['name'], '
' . $extension['name'] . '
', 'read', $extension['page'], $callback );
}
if ( isset( $extension['on_load_callback'] ) && ! empty( $extension['on_load_callback'] ) ) {
add_action( 'load-' . $_page, $extension['on_load_callback'] );
}
$_item = array(
'title' => $menu_name,
'slug' => $extension['page'],
'href' => isset( $extension['href'] ) ? $extension['href'] : '',
);
$extsPages[] = $_item;
}
}
if ( ! empty( $deactivated_imcompatible ) ) {
set_transient( 'mainwp_transient_deactivated_incomtible_exts', $deactivated_imcompatible );
}
MainWP_Utility::update_option( 'mainwp_extensions', $save_extensions );
MainWP_Extensions_Handler::get_extensions( true ); // forced reload.
if ( ! $is_cached ) {
update_option( 'mainwp_extensions_all_activation_cached', $activations_cached );
}
static::init_left_menu( $extsPages );
}
/**
* Method init_left_menu()
*
* Initiate top level Extensions Menues.
*
* @param array $extPages List of extension pages.
* @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
* @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
* @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
*/
public static function init_left_menu( $extPages ) {
$subPages = array();
if ( ! MainWP_Menu::is_disable_menu_item( 2, 'Extensions' ) ) {
MainWP_Menu::add_left_menu(
array(
'title' => esc_html__( 'Add-ons', 'mainwp' ),
'parent_key' => 'mainwp_tab',
'slug' => 'Extensions',
'href' => 'admin.php?page=Extensions',
'icon' => ' ',
),
0
);
$init_sub_subleftmenu = array(
array(
'title' => esc_html__( 'Manage Add-ons', 'mainwp' ),
'parent_key' => 'Extensions',
'href' => 'admin.php?page=Extensions',
'slug' => 'Extensions',
'right' => '',
),
);
MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'Extensions', 'Extensions' );
foreach ( $init_sub_subleftmenu as $item ) {
if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
continue;
}
MainWP_Menu::add_left_menu( $item, 2 );
}
if ( ! empty( $extPages ) ) {
$init_sub_subleftmenu = array();
$slug = '';
MainWP_Menu::init_subpages_left_menu( $extPages, $init_sub_subleftmenu, 'Extensions', $slug );
foreach ( $init_sub_subleftmenu as $item ) {
if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
continue;
}
MainWP_Menu::add_left_menu( $item, 2 );
}
}
}
}
/**
* Method init_subpages_menu()
*
* Initiate Extensions Subpage Menu.
*
* @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
* @uses \MainWP\Dashboard\MainWP_Extensions_Handler::added_on_menu()
* @uses \MainWP\Dashboard\MainWP_Extensions_Handler::polish_ext_name()
*/
public static function init_subpages_menu() {
$exts = MainWP_Extensions_Handler::get_extensions();
if ( empty( $exts ) ) {
return;
}
$html = '';
foreach ( $exts as $extension ) {
if ( defined( 'MWP_TEAMCONTROL_PLUGIN_SLUG' ) && ( MWP_TEAMCONTROL_PLUGIN_SLUG === $extension['slug'] ) && ! \mainwp_current_user_can( 'extension', dirname( MWP_TEAMCONTROL_PLUGIN_SLUG ) ) ) {
continue;
}
if ( MainWP_Extensions_Handler::added_on_menu( $extension['slug'] ) ) {
continue;
}
$menu_name = MainWP_Extensions_Handler::polish_ext_name( $extension );
if ( isset( $extension['direct_page'] ) ) {
$html .= '' . $menu_name . ' ';
} else {
$html .= '' . $menu_name . ' ';
}
}
if ( empty( $html ) ) {
return;
}
?>
secure_request( 'mainwp_extension_getpurchased' );
$api_key = isset( $_POST['api_key'] ) ? trim( wp_unslash( $_POST['api_key'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// MWP-1547: the Extensions page renders the sentinel placeholder
// when a master key is already stored. The browser submits whatever
// value is in #mainwp_com_api_key, which is the sentinel for
// remembered-license dashboards. Resolve to the stored decrypted
// master key server-side rather than sending the placeholder
// upstream.
if ( MainWP_Credential_Render::is_sentinel( $api_key ) ) {
$api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key();
}
$all_available_extensions_compatible_api_response = array();
$all_free_pro_exts = array();
$all_org_exts = array();
$map_extensions_group = array();
$purchased_data = array();
$all_groups = MainWP_Extensions_View::get_extension_groups();
$grouped_exts = array(
'others' => '',
'all' => '',
);
foreach ( MainWP_Extensions_View::get_available_extensions( 'all' ) as $ext ) {
$all_available_extensions_compatible_api_response[ $ext['product_id'] ] = $ext;
$map_extensions_group[ $ext['product_id'] ] = current( $ext['group'] );
if ( 'free' === $ext['type'] || 'pro' === $ext['type'] ) {
$all_free_pro_exts[ $ext['product_id'] ] = $ext['product_id'];
} elseif ( 'org' === $ext['type'] ) {
$all_org_exts[ $ext['product_id'] ] = $ext['product_id'];
}
}
$extensions = MainWP_Extensions_Handler::get_extensions();
$installed_softwares = array();
foreach ( $extensions as $extension ) {
if ( isset( $extension['type'] ) ) {
if ( 'free' === $extension['type'] || 'pro' === $extension['type'] ) {
if ( isset( $extension['product_id'] ) && ! empty( $extension['product_id'] ) ) {
$installed_softwares[ $extension['product_id'] ] = $extension['product_id'];
}
} elseif ( 'org' === $extension['type'] ) {
$ext_slug = dirname( $extension['slug'] );
$installed_softwares[ $ext_slug ] = $ext_slug;
}
}
}
$all_disabled_extensions = MainWP_Extensions_Handler::get_extensions_disabled( true );
foreach ( $all_disabled_extensions as $ext ) {
$installed_softwares[ $ext['product_id'] ] = $ext['product_id'];
}
$not_purchased_exts = $all_free_pro_exts;
$not_installed_org_exts = array_diff_key( $all_org_exts, $installed_softwares );
$installing_exts = $not_installed_org_exts;
if ( ! empty( $api_key ) ) {
$data = MainWP_Api_Manager::instance()->get_purchased_extension( $api_key );
$result = json_decode( $data, true );
$return = array();
if ( is_array( $result ) ) {
if ( isset( $result['success'] ) && $result['success'] ) {
$purchased_data = ( isset( $result['purchased_data'] ) && is_array( $result['purchased_data'] ) ) ? $result['purchased_data'] : array();
$not_purchased_exts = array_diff_key( $all_free_pro_exts, $purchased_data );
$installing_exts = array_diff_key( $purchased_data, $installed_softwares );
$installing_exts = array_merge( $installing_exts, $not_installed_org_exts );
} elseif ( isset( $result['error'] ) ) {
$return = array( 'error' => $result['error'] );
}
} else {
$apisslverify = get_option( 'mainwp_api_sslVerifyCertificate' );
if ( 1 === $apisslverify ) {
MainWP_Utility::update_option( 'mainwp_api_sslVerifyCertificate', 0 );
$return['retry_action'] = 1;
}
}
if ( ! empty( $return ) ) {
wp_send_json( $return );
}
}
foreach ( $all_available_extensions_compatible_api_response as $product_id => $ext ) {
$item_html = '';
$error = '';
$ext_source_label = '';
$type = '';
$notice = '';
$add_on_model = '';
$model = $ext['model'];
if ( 'extension' === $model ) {
$add_on_model = 'addon-extension';
} elseif ( 'integration' === $model ) {
$add_on_model = 'addon-integration';
}
$item_slug = MainWP_Utility::get_dir_slug( $ext['slug'] );
$privacy = ' ';
$new = '';
$software_title = MainWP_Extensions_Handler::polish_string_name( $ext['title'] );
if ( ! empty( $ext['type'] ) ) {
$type = $ext['type'];
if ( 'free' === $type ) {
$ext_source_label = 'FREE ';
} elseif ( 'pro' === $type ) {
$ext_source_label = 'PRO ';
} elseif ( 'org' === $type ) {
$ext_source_label = '.ORG ';
}
}
if ( isset( $ext['release_date'] ) && ( time() - $ext['release_date'] < MONTH_IN_SECONDS ) ) {
$new = 'NEW! ';
}
if ( 'MainWP WordPress SEO Extension' === $product_id || 'seopress-for-mainwp' === $product_id ) {
$notice = ' ';
}
$ext_source_label .= ' ';
if ( isset( $installing_exts[ $product_id ] ) ) {
$product_info = isset( $installing_exts[ $product_id ] ) ? $installing_exts[ $product_id ] : array();
if ( ! is_array( $product_info ) ) {
$product_info = array();
}
if ( 'free' === $type || 'pro' === $type ) {
if ( $product_info && isset( $product_info['package'] ) && ! empty( $product_info['package'] ) ) {
/**
* API Manager Upgrade URL
*
* Filters the Upgrade URL for extensions.
*
* @since Unknown
* @ignore
*/
$package_url = apply_filters( 'mainwp_api_manager_upgrade_package_url', $product_info['package'], $product_info );
$item_html = '
';
} elseif ( isset( $product_info['error'] ) && ! empty( $product_info['error'] ) ) {
$error = MainWP_Api_Manager::instance()->check_response_for_intall_errors( $product_info, $software_title );
} else {
$error = esc_html__( 'Undefined error occurred. Please try again.', 'mainwp' );
}
if ( ! empty( $error ) ) {
$item_html = '
';
}
} elseif ( 'org' === $type ) {
$item_html = '
';
}
} elseif ( isset( $not_purchased_exts[ $product_id ] ) ) {
if ( 'free' === $type || 'pro' === $type ) {
$item_html = '
';
} elseif ( 'org' === $type ) {
$item_html = '
';
}
} elseif ( isset( $installed_softwares[ $product_id ] ) ) {
$item_html = '
';
}
$group_id = isset( $map_extensions_group[ $product_id ] ) ? $map_extensions_group[ $product_id ] : false;
if ( ! empty( $group_id ) && isset( $all_groups[ $group_id ] ) ) {
if ( isset( $grouped_exts[ $group_id ] ) ) {
$grouped_exts[ $group_id ] .= $item_html;
} else {
$grouped_exts[ $group_id ] = $item_html;
}
} else {
$grouped_exts['others'] .= $item_html;
}
$grouped_exts['all'] .= $item_html;
}
$html = '';
if ( empty( $installing_exts ) && count( $purchased_data ) === count( $all_free_pro_exts ) ) {
$html .= '
' . esc_html__( 'All purchased add-ons already installed.', 'mainwp' ) . '
';
} else {
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '';
$html .= '
';
$html .= esc_html__( 'For a cleaner dashboard and better focus, start with only the add-ons you need right now. You can always install more later.', 'mainwp' );
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
foreach ( $all_groups as $gr_id => $gr_name ) {
if ( isset( $grouped_exts[ $gr_id ] ) ) {
$html .= '
' . $gr_name . ' ';
}
}
if ( isset( $grouped_exts['others'] ) && ! empty( $grouped_exts['others'] ) ) {
$html .= '
' . esc_html__( 'Other', 'mainwp' ) . ' ';
}
$html .= '
';
$html .= '
';
$html .= '
';
$html .= esc_html__( 'Show: ', 'mainwp' );
$html .= '
' . esc_html__( 'Extensions', 'mainwp' ) . '
';
$html .= '
' . esc_html__( 'Integrations', 'mainwp' ) . '
';
$html .= '
' . esc_html__( 'What\'s the difference?', 'mainwp' ) . '';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= $grouped_exts['all'];
$html .= '
';
$html .= '
';
foreach ( $all_groups as $gr_id => $gr_name ) {
if ( isset( $grouped_exts[ $gr_id ] ) && 'all' !== $gr_id ) {
$html .= '
';
$html .= '
';
$html .= $grouped_exts[ $gr_id ];
$html .= '
';
$html .= '
';
}
}
if ( isset( $grouped_exts['others'] ) && ! empty( $grouped_exts['others'] ) ) {
$html .= '
';
$html .= '
';
$html .= $grouped_exts['others'];
$html .= '
';
$html .= '
';
}
}
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
FREE ' . esc_html__( 'Free add-on by MainWP', 'mainwp' ) . '
';
$html .= '
PRO ' . esc_html__( 'Premium add-on by MainWP', 'mainwp' ) . '
';
$html .= '
.ORG ' . esc_html__( 'Free add-on by a third party (WP.org)', 'mainwp' ) . '
';
$html .= '
' . esc_html__( 'Requires the matching plugin on too.', 'mainwp' ) . '
';
$html .= '
' . esc_html__( 'Add-on privacy info.', 'mainwp' ) . '
';
$html .= '
';
$html .= '
';
$html .= '';
$html .= '';
if ( ! empty( $installing_exts ) ) {
$html .= '
';
}
$html .= '
';
$return = array(
'result' => 'SUCCESS',
'data' => $html,
);
wp_send_json( $return );
}
/**
* Method render_header()
*
* Render page header.
*
* @param string $shownPage The page slug shown at this moment.
*
* @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
* @uses \MainWP\Dashboard\MainWP_Extensions_View::render_header()
*/
public static function render_header( $shownPage = '' ) {
MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
MainWP_Extensions_View::render_header( $shownPage );
}
/**
* Method render_footer()
*
* Render page footer.
*
* @param string $shownPage The page slug shown at this moment.
*
* @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
* @uses \MainWP\Dashboard\MainWP_Extensions_View::render_footer()
*/
public static function render_footer( $shownPage ) {
MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
MainWP_Extensions_View::render_footer( $shownPage );
}
/**
* Method render()
*
* Render page content.
*
* @uses \MainWP\Dashboard\MainWP_Extensions_View::render()
* @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
*/
public static function render() {
$params = array(
'title' => esc_html__( 'Add-ons', 'mainwp' ),
);
MainWP_UI::render_top_header( $params );
MainWP_Extensions_View::render();
echo '';
}
/**
* Method mainwp_help_content()
*
* Creates the MainWP Help Documentation List for the help component in the sidebar.
*/
public static function mainwp_help_content() {
if ( isset( $_GET['page'] ) && 'Extensions' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
?>
Your custom text
*
* @since 5.2
*/
do_action( 'mainwp_extensions_help_item' );
}
}
}