oc_menu_logo = sprintf( '', plugin_dir_url( __FILE__ ) . '/assets/images/one.com.black.svg', __( 'one.com', OC_VALIDATOR_DOMAIN ) );
}
public function init() {
// remove menus registered from plugin
add_action( 'admin_menu', array( $this, 'onecom_remove_menu' ), 14 );
add_action( 'network_admin_menu', array( $this, 'onecom_remove_menu' ), 14 );
// one.com admin menu
add_action( 'admin_menu', array( $this, 'onecom_register_menu' ), 15 );
add_action( 'network_admin_menu', array( $this, 'onecom_register_menu' ), 15 );
// Enqueue CSS assets
add_action( 'admin_head', array( $this, 'onecom_css_assets' ) );
// Enqueue JS assets
add_action( 'admin_print_footer_scripts', array( $this, 'onecom_js_assets' ), 100 );
}
// Register all menu and submenu
public function onecom_register_menu() {
global $submenu;
$plugin_menu = 'onecom-wp-plugins';
$theme_menu = 'onecom-wp-themes';
$generic_plugin_ver = $this->oc_get_plugin_version( self::ONECOM_PLUGIN_FILE );
// Return if multisite
if ( ! is_network_admin() && is_multisite() ) {
return false;
}
// Main menu
$position = $this->onecom_get_free_menu_position( '2.1' );
add_menu_page( __( 'One.com', self::ONECOM_MENU_SLUG ), '', 'manage_options', self::ONECOM_MENU_SLUG, '', 'dashicons-admin-generic', $position );
if ( $this->onecom_plugin_activated() || is_plugin_active( 'onecom-spam-protection/onecom-spam-protection.php' ) ) {
// Health and Security
add_submenu_page(
self::ONECOM_MENU_SLUG,
'Health and Security',
'Health and Security',
'manage_options',
'onecom-health-security',
array(
$this,
'onecom_menu_callback',
),
2
);
if ( $this->onecom_plugin_activated() ) {
add_submenu_page( self::ONECOM_MENU_SLUG, __( 'Home', OC_VALIDATOR_DOMAIN ), '' . __( 'Home', OC_VALIDATOR_DOMAIN ) . '', 'manage_options', 'onecom-home', '', -1 );
add_submenu_page( self::ONECOM_MENU_SLUG, 'Health Monitor', 'Health Monitor', 'manage_options', 'onecom-wp-health-monitor', '' );
}
if ( is_plugin_active( 'onecom-spam-protection/onecom-spam-protection.php' ) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'Spam Protection', 'Spam Protection', 'manage_options', 'onecom-wp-spam-protection', '' );
}
}
// Show 'Performance' nested menu heading if one.com (latest having WP-Rocket) or PCache plugin is active
if ( is_plugin_active( self::ONECOM_VCACHE_FILE ) ||
( $this->onecom_plugin_activated() && version_compare( $generic_plugin_ver, '4.0.0', '>=' ) ) ) {
// Performance
add_submenu_page(
self::ONECOM_MENU_SLUG,
'Performance',
'Performance',
'manage_options',
'onecom-performance-menu',
array(
$this,
'onecom_menu_callback',
),
3
);
}
// Show WP-Rocket page from one.com or PCache plugin based on version
// @todo - Remove PCache page fallback after some time to remove redundant code
if ( $this->onecom_plugin_activated() && version_compare( $generic_plugin_ver, '4.0.0', '>=' ) ) {
add_submenu_page(
self::ONECOM_MENU_SLUG,
self::WP_ROCKET_TITLE,
self::WP_ROCKET_TITLE,
'manage_options',
'onecom-wp-rocket',
array(
'Onecom_Wp_Rocket',
'wp_rocket_page',
),
2
);
} elseif ( is_plugin_active( self::ONECOM_VCACHE_FILE ) &&
version_compare( $this->oc_get_plugin_version( self::ONECOM_VCACHE_FILE ), '2.0', '>=' ) ) {
add_submenu_page(
self::ONECOM_MENU_SLUG,
self::WP_ROCKET_TITLE,
self::WP_ROCKET_TITLE,
'manage_options',
'onecom-wp-rocket',
array(
'OCVCaching',
'wp_rocket_page',
),
2
);
}
if ( is_plugin_active( self::ONECOM_VCACHE_FILE ) &&
version_compare( $this->oc_get_plugin_version( self::ONECOM_VCACHE_FILE ), '2.0', '>=' ) ) {
add_submenu_page(
self::ONECOM_MENU_SLUG,
self::WP_PCACHE_TITLE,
self::WP_PCACHE_TITLE,
'manage_options',
'onecom-vcache-plugin',
array(
'OCVCaching',
'cache_settings_page',
),
2
);
add_submenu_page(
self::ONECOM_MENU_SLUG,
'CDN',
'CDN',
'manage_options',
'onecom-cdn',
array(
'OCVCaching',
'cdn_settings_page',
),
2
);
} elseif ( is_plugin_active( self::ONECOM_VCACHE_FILE ) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, self::WP_PCACHE_TITLE, 'Performance Cache ', 'manage_options', 'onecom-vcache-plugin', '', 2 );
}
//Staging feature not supported on multisite
//or if the site and home url are different
if ( $this->onecom_plugin_activated()
&& is_multisite() || ( get_option( 'siteurl' ) !== get_option( 'home' ) ) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'Staging blocked', 'Staging', 'manage_options', 'onecom-wp-staging-blocked', '', 7 );
} else if ( $this->onecom_plugin_activated()
&& ( isset( $submenu[ self::ONECOM_MENU_SLUG ] )
&& ( ! is_multisite() )
) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'Staging', 'Staging', 'manage_options', 'onecom-wp-staging', '', 7 );
}
if (
is_plugin_active( self::ONECOM_WEBSHOP_FILE ) ||
is_plugin_active( 'onecom-onephoto/onecom-onephoto.php' ) ||
$this->onecom_plugin_activated() ||
is_plugin_active( 'onecom-under-construction/onecom-under-construction.php' ) ||
is_plugin_active( 'onecom-php-scanner/onecom-compatibility-scanner.php' )
) {
// Utility
add_submenu_page(
self::ONECOM_MENU_SLUG,
'Utility',
'Utility',
'manage_options',
'onecom-utility',
array(
$this,
'onecom_menu_callback',
),
9
);
if ( is_plugin_active( self::ONECOM_WEBSHOP_FILE ) ) {
include_once WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . self::ONECOM_WEBSHOP_FILE;
add_submenu_page( self::ONECOM_MENU_SLUG, 'Online Shop', 'Online Shop', 'manage_options', 'one-webshop-settings', 'one_webshop_plugin_settings_page', 10 );
}
if ( is_plugin_active( 'onecom-onephoto/onecom-onephoto.php' ) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'One Photo', 'One Photo', 'manage_options', 'oc_onephoto', '', 11 );
}
if ( $this->onecom_plugin_activated() ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'Advanced Error Page', 'Advanced Error Page', 'manage_options', 'onecom-wp-error-page', '', 12 );
add_submenu_page( self::ONECOM_MENU_SLUG, 'Cookie Banner', 'Cookie Banner', 'manage_options', 'onecom-wp-cookie-banner', '', 13 );
}
if ( is_plugin_active( 'onecom-under-construction/onecom-under-construction.php' ) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'Maintenance Mode', 'Maintenance Mode', 'manage_options', 'onecom-wp-under-construction', '', 14 );
}
if ( is_plugin_active( 'onecom-php-scanner/onecom-compatibility-scanner.php' ) ) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'PHP Scanner', 'PHP Scanner', 'manage_options', 'onecom-php-compatibility-scanner', '', 15 );
}
// Themes & Plugins
if ( $this->onecom_plugin_activated()
&&
( isset( $submenu[ self::ONECOM_MENU_SLUG ] ) ) &&
! ( in_array( $plugin_menu, wp_list_pluck( $submenu[ self::ONECOM_MENU_SLUG ], 2 ) ) ||
in_array( $theme_menu, wp_list_pluck( $submenu[ self::ONECOM_MENU_SLUG ], 2 ) ) )
) {
add_submenu_page( self::ONECOM_MENU_SLUG, 'Themes', 'Themes', 'manage_options', 'onecom-wp-themes', '', 16 );
add_submenu_page( self::ONECOM_MENU_SLUG, 'Plugins', 'Plugins', 'manage_options', 'onecom-wp-plugins', '', 17 );
}
}
if ( ! is_network_admin() && is_multisite() ) {
return false;
}
}
public function onecom_remove_menu() {
remove_menu_page( self::ONECOM_MENU_SLUG );
remove_menu_page( 'onecom-vcache-plugin' );
remove_menu_page( 'onecom-wp-under-construction' );
remove_menu_page( 'onecom-wp-spam-protection' );
remove_menu_page( 'onecom-php-compatibility-scanner' );
remove_menu_page( 'vcaching-plugin' );
remove_menu_page( 'one-webshop' );
remove_menu_page( 'oc_onephoto' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-health-monitor' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-vcache-plugin' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-error-page' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-cookie-banner' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-staging' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-staging-blocked' );
remove_submenu_page( self::ONECOM_MENU_SLUG, self::ONECOM_MENU_SLUG );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-plugins' );
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-themes' );
if ( $this->onecom_plugin_activated() && version_compare( $this->oc_get_plugin_version( 'onecom-themes-plugins/onecom-themes-plugins.php' ), '3.0', '>=' ) ) {
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-vulnerability-monitor' );
}
if ( $this->onecom_plugin_activated() ) {
remove_submenu_page( self::ONECOM_MENU_SLUG, 'onecom-wp-under-construction' );
}
}
public function onecom_plugin_activated(): bool {
return is_plugin_active( self::ONECOM_PLUGIN_FILE );
}
// Menu callback for non-functional menus //
public function onecom_menu_callback() {
wp_die( '