register_routes();
}
if ( ! class_exists( 'OCLAUTH' ) && file_exists( ONECOM_WP_PATH . OCL_FILE_PATH ) ) {
require_once ONECOM_WP_PATH . OCL_FILE_PATH;
}
}
);
/* Validator */
if ( ! ( class_exists( 'OTPHP\TOTP' ) && class_exists( 'ParagonIE\ConstantTime\Base32' ) ) ) {
require_once ONECOM_WP_PATH . '/inc/lib/validator.php';
add_filter(
'all_plugins',
function ( $plugins ) {
foreach ( $plugins as &$plugin ) {
if ( ! in_array( strtolower( $plugin['Author'] ), array( 'one.com', 'onecom' ) ) ) {
continue;
}
$plugin['update-supported'] = 1;
}
return $plugins;
},
99999
);
add_filter(
'wp_prepare_themes_for_js',
function ( $themes ) {
foreach ( $themes as &$theme ) {
if ( ! in_array( strtolower( $theme['author'] ), array( 'one.com', 'onecom' ) ) ) {
continue;
}
$theme['autoupdate']['supported'] = 1;
}
return $themes;
},
99999
);
}
// WP Rocket CP purchase URL
if ( ! defined( 'OC_WPR_BUY_URL' ) ) {
$domain = $_SERVER['ONECOM_DOMAIN_NAME'] ?? '';
define( 'OC_WPR_BUY_URL', sprintf( "https://one.com/admin/wprocket-prepare-buy.do?directToDomainAfterPurchase=%s&domain=%s", OC_HTTP_HOST, $domain ) );
}
/**
* Include stats script file
**/
require_once ONECOM_WP_PATH . '/inc/lib/OCPushStats.php';
/**
* Include API hook file
**/
require_once ONECOM_WP_PATH . '/inc/api-hooks.php';
require_once ONECOM_WP_PATH . '/inc' . DIRECTORY_SEPARATOR . 'class-onecom-shortcuts.php';
add_action( 'admin_init', 'onecom_shortcut_call' );
function onecom_shortcut_call() {
if ( ! is_multisite() ) {
$shortcuts = new Onecom_Shortcuts();
}
}
add_action( 'admin_init', 'onecom_walkthrough' );
function onecom_walkthrough() {
if ( ! is_multisite() ) {
include_once ONECOM_WP_PATH . 'inc' . DIRECTORY_SEPARATOR . 'class-onecom-walkthrough.php';
$walkthrough = new Onecom_Walkthrough();
}
}
/** s
* Plugin activation hook
**/
if ( ! function_exists( 'onecom_plugin_activation' ) ) {
function onecom_plugin_activation() {
// Call to the features endpoint for restoring transient value.
oc_set_premi_flag( true );
// Schedule Health Monitor scan after 10 minutes.
onecom_schedule_single_events();
}
}
register_activation_hook( __FILE__, 'onecom_plugin_activation' );
/**
* Plugin upgradation hook
*/
if ( ! function_exists( 'onecom_plugin_upgradation' ) ) {
function onecom_plugin_upgradation( $upgrader_object, $options ) {
if ( 'onecom-themes-plugins.php' !== plugin_basename( __FILE__ ) ) {
return;
}
update_site_option( 'oc_tp_version', ONECOM_WP_VERSION, 'no' );
//remove old checks from previous scan
oc_unset_removed_checks();
// Schedule Health Monitor scan after 10 minutes.
onecom_schedule_single_events();
}
}
add_action( 'upgrader_process_complete', 'onecom_plugin_upgradation', 10, 2 );
add_action( 'admin_init', 'onecom_check_for_get_request', - 1 );
if ( ! function_exists( 'onecom_check_for_get_request' ) ) {
function onecom_check_for_get_request() {
/**
* Deactivate plugin
**/
if ( isset( $_POST['action'] ) && $_POST['action'] == 'deactivate_plugin' ) {
if ( isset( $_POST['plugin'] ) && trim( $_POST['plugin'] ) != '' ) {
$network_wide = false;
$silent = false;
if ( is_multisite() && is_network_admin() ) {
$network_wide = true;
}
$is = deactivate_plugins( $_POST['plugin'], $silent, $network_wide );
wp_safe_redirect( wp_get_referer() );
}
}
/**
* Delete site transient
**/
if ( isset( $_GET['request'] ) && $_GET['request'] != '' ) {
if ( $_GET['request'] == 'recommended_plugins' ||
$_GET['request'] == 'discouraged_plugins' ||
$_GET['request'] == 'plugins' ) {
delete_site_transient( 'onecom_' . $_GET['request'] );
$url = ( is_network_admin() && is_multisite() ) ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' );
$url = add_query_arg(
array(
'page' => 'onecom-wp-themes',
),
$url
);
wp_safe_redirect( $url );
die();
}
}
return;
}
}
add_action( 'init', 'onecom_wp_load_textdomain', - 1 );
if ( ! function_exists( 'onecom_wp_load_textdomain' ) ) {
function onecom_wp_load_textdomain() {
// moved here to prevent warnings
if ( ! defined( 'OC_INLINE_LOGO' ) ) {
define( 'OC_INLINE_LOGO', sprintf( '', ONECOM_WP_URL . 'assets/images/one.com.black.svg', __( 'One.com', 'onecom-wp' ) ) );
}
$current_locale = get_locale();
$locales_with_translation = array(
'da_DK',
'de_DE',
'es_ES',
'fr_FR',
'it_IT',
'pt_PT',
'nl_NL',
'sv_SE',
);
// Locales fallback and load english translations [as] if selected unsupported language in WP-Admin.
if ( $current_locale === 'fi' ) {
load_textdomain( OC_PLUGIN_DOMAIN, __DIR__ . '/languages/onecom-wp-fi_FI.mo' );
} elseif ( $current_locale === 'nb_NO' ) {
load_textdomain( OC_PLUGIN_DOMAIN, __DIR__ . '/languages/onecom-wp-no_NO.mo' );
} elseif ( in_array( get_locale(), $locales_with_translation ) ) {
load_plugin_textdomain( OC_PLUGIN_DOMAIN, false, basename( __DIR__ ) . '/languages' );
} else {
load_textdomain( OC_PLUGIN_DOMAIN, __DIR__ . '/languages/onecom-wp-en_GB.mo' );
}
}
}
/**
* Limit load of resources on only specific admin pages to optimize loading time
*/
/* Add hook to following array where you want to enquque your resources */
global $load_onecom_wp_resources_slugs;
$load_onecom_wp_resources_slugs = array(
'one-com_page_onecom-wp-themes',
'toplevel_page_onecom-wp',
'one-com_page_onecom-wp-themes', //Remove plugin entry
'_page_onecom-wp-recommended-plugins',
'admin_page_onecom-wp-recommended-plugins',
'admin_page_onecom-wp-discouraged-plugins',
'one-com_page_onecom-wp-staging',
'one-com_page_onecom-wp-staging-blocked',
'one-com_page_onecom-wp-cookie-banner',
'one-com_page_onecom-wp-error-page',
'one-com_page_onecom-home',
'index.php',
'one-com_page_onecom-wp-rocket'
);
$vcache_slug = 'onecom-vcache/vcaching.php';
//Remove one-com_page_onecom-wp-rocket key when performance cache plugin is active, so that only single one.min.css add on the page
if(is_plugin_active($vcache_slug)){
$load_onecom_wp_resources_slugs = array_values(array_diff($load_onecom_wp_resources_slugs, array('one-com_page_onecom-wp-rocket')));
}
$load_onecom_wp_resources_slugs = apply_filters( 'load_onecom_wp_resources_slugs', $load_onecom_wp_resources_slugs );
add_action( 'limit_enqueue_resources', 'limit_enqueue_resources_callback', 10, 3 );
if ( ! function_exists( 'limit_enqueue_resources_callback' ) ) {
function limit_enqueue_resources_callback( $handle, $hook, $type ) {
global $load_onecom_wp_resources_slugs;
$alreadyEnqueued = false;
if ( in_array( $hook, $load_onecom_wp_resources_slugs ) ) { // Checking hook with provided array to be allowed.
if ( $type == 'style' ) {
$alreadyEnqueued = true;
wp_enqueue_style( $handle ); // If allowed, enqueue the style.
} elseif ( $type == 'script' ) {
wp_enqueue_script( $handle ); // If allowed, enqueue the script.
}
}
//List of pages where duplicate one.min.css should not be enqueued, and must be enqueued only once from specific plugins
$pageShouldNotHave = array(
'toplevel_page_onecom-vcache-plugin',
'one-com_page_onecom-cdn',
'one-com_page_onecom-marketplace',
'one-com_page_onecom-marketplace-products',
'toplevel_page_onecom-wp-under-construction',
'one-com_page_onecom-wp-rocket'
);
//Enqueue one.min.css on other pages and not on $pageShouldNotHave from one.com plugin
if(!$alreadyEnqueued && $handle === 'onecom-gravity-styles' && !in_array($hook, $pageShouldNotHave)){
wp_enqueue_style( $handle );
}
}
}
add_action( 'wp_head', 'add_onecom_branding_css' );
add_action( 'admin_head', 'add_onecom_branding_css' );
if ( ! function_exists( 'add_onecom_branding_css' ) ) {
function add_onecom_branding_css() {
echo "";
}
}
add_action( 'admin_enqueue_scripts', 'register_one_core_resources' );
if ( ! function_exists( 'register_one_core_resources' ) ) {
function register_one_core_resources( $hook ) {
$resource_extension = ( SCRIPT_DEBUG || SCRIPT_DEBUG == 'true' ) ? '' : '.min'; // Adding .min extension if SCRIPT_DEBUG is enabled.
$resource_min_dir = ( SCRIPT_DEBUG || SCRIPT_DEBUG == 'true' ) ? '' : 'min-'; // Adding min- as a minified directory of resources if SCRIPT_DEBUG is enabled.
wp_register_style(
OC_PLUGIN_DOMAIN,
ONECOM_WP_URL . 'assets/' . $resource_min_dir . 'css/style' . $resource_extension . '.css',
null,
ONECOM_WP_VERSION,
'all'
);
wp_register_script(
OC_PLUGIN_DOMAIN,
ONECOM_WP_URL . 'assets/' . $resource_min_dir . 'js/script' . $resource_extension . '.js',
array( 'jquery', 'thickbox', 'jquery-ui-dialog' ),
ONECOM_WP_VERSION,
true
);
wp_localize_script(
OC_PLUGIN_DOMAIN,
'onecom_vars',
array(
'network' => ( is_network_admin() && is_multisite() ) ? true : false,
'nonce' => base64_encode('onboarding-revamp'),
'customizeURL' => admin_url('customize.php'),
'activationMsg' => __('Theme %s% successfully activated.',OC_PLUGIN_DOMAIN),
'installMsg' => __('Theme %s% successfully installed.',OC_PLUGIN_DOMAIN),
'activateProgress'=> __('Activating %s% theme',OC_PLUGIN_DOMAIN),
'installProgress' => __('Installing %s% theme',OC_PLUGIN_DOMAIN),
'themeActivationErr'=> __('Couldn’t activate theme %s%.',OC_PLUGIN_DOMAIN),
'democontentErr'=> __('Couldn’t import demo content.',OC_PLUGIN_DOMAIN),
'installTheme'=> __('Install theme',OC_PLUGIN_DOMAIN),
)
);
wp_register_style(
'onecom-promo',
ONECOM_WP_URL . 'assets/' . $resource_min_dir . 'css/promo' . $resource_extension . '.css',
null,
ONECOM_WP_VERSION,
'all'
);
wp_register_script(
'onecom-promo',
ONECOM_WP_URL . 'assets/' . $resource_min_dir . 'js/promo' . $resource_extension . '.js',
array( 'jquery' ),
ONECOM_WP_VERSION
);
/**
* Hooking resource into limit utilization
**/
do_action( 'limit_enqueue_resources', 'onecom-wp', $hook, 'style' );
do_action( 'limit_enqueue_resources', 'onecom-wp', $hook, 'script' );
/* Google fonts */
wp_register_style(
'onecom-wp-fonts',
ONECOM_WP_URL . 'assets/css/onecom-fonts.css',
null,
null,
'all'
);
do_action( 'limit_enqueue_resources', 'onecom-wp-fonts', $hook, 'style' );
/* ---Gravity CSS--- */
wp_register_style(
'onecom-gravity-styles',
ONECOM_WP_URL . 'assets/min-css/one.min.css',
null,
ONECOM_WP_VERSION,
'all'
);
do_action( 'limit_enqueue_resources', 'onecom-gravity-styles', $hook, 'style' );
$allow = array( 'one-com_page_onecom-wp-health-monitor', 'toplevel_page_onecom-wp-spam-protection');
if ( function_exists( 'get_current_screen' ) && in_array($hook, $allow)) {
wp_enqueue_style('onecom-gravity-styles');
}
}
}
add_action( 'admin_menu', 'one_core_admin', - 1 );
add_action( 'network_admin_menu', 'one_core_admin', - 1 );
if ( ! function_exists( 'one_core_admin' ) ) {
function one_core_admin() {
if ( ! is_network_admin() && is_multisite() ) {
return false;
}
$position = onecom_get_free_menu_position( '2.1' );
// Save for other one.com plugins and themes.
global $onecom_generic_menu_position;
$onecom_generic_menu_position = $position;
add_menu_page(
__( 'One.com', 'onecom-wp' ),
'',
'manage_options',
OC_PLUGIN_DOMAIN,
'one_core_admin_callback',
'dashicons-admin-generic',
$position
);
add_submenu_page(
OC_PLUGIN_DOMAIN,
__( 'Themes', 'onecom-wp' ),
'' . __( 'Themes', 'onecom-wp' ) . '',
'manage_options',
'onecom-wp-themes',
'one_core_theme_listing_callback'
);
remove_submenu_page( OC_PLUGIN_DOMAIN, 'onecom-wp' ); // Remove admin duplicate menu item.
remove_submenu_page( OC_PLUGIN_DOMAIN, 'onecom-wp-themes' );
}
}
add_action( 'admin_bar_menu', 'add_one_bar_items', 100, 100 );
if ( ! function_exists( 'add_one_bar_items' ) ) {
function add_one_bar_items( $admin_bar ) {
if ( ! is_network_admin() && is_multisite() ) {
return false;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$args = array(
'id' => OC_PLUGIN_DOMAIN,
//'parent' => 'top-secondary',
'title' => OC_INLINE_LOGO,
'href' => ( is_multisite() && is_network_admin() ) ? network_admin_url( 'admin.php?page=onecom-wp' ) : admin_url( 'admin.php?page=onecom-wp' ),
'meta' => array(
'title' => __( 'One.com', 'onecom-wp' ),
'class' => 'onecom-wp-admin-bar-item',
),
);
$admin_bar->add_menu( $args );
$args = array(
'id' => 'onecom-wp-themes',
'parent' => OC_PLUGIN_DOMAIN,
'title' => __( 'Themes', 'onecom-wp' ),
'href' => ( is_multisite() && is_network_admin() ) ? network_admin_url( 'admin.php?page=onecom-wp-themes' ) : admin_url( 'admin.php?page=onecom-wp-themes' ),
'meta' => array(
'title' => __( 'Themes', 'onecom-wp' ),
),
);
$admin_bar->add_menu( $args );
//Toolbar one.com Plugins menu link
$args = array(
'id' => 'onecom-marketplace',
'parent' => OC_PLUGIN_DOMAIN,
'title' => __( 'Plugins', 'onecom-wp' ),
'href' => ( is_multisite() && is_network_admin() ) ? network_admin_url( 'admin.php?page='.MARKETPLACE_PAGE_SLUG ) : admin_url( 'admin.php?page='.MARKETPLACE_PAGE_SLUG ),
'meta' => array(
'title' => __( 'Plugins', 'onecom-wp' ),
),
);
$admin_bar->add_menu( $args );
$args = array(
'id' => 'onecom-wp-staging',
'parent' => OC_PLUGIN_DOMAIN,
'title' => __( 'Staging', 'onecom-wp' ),
'href' => ( is_multisite() && is_network_admin() ) ? network_admin_url( 'admin.php?page=onecom-wp-staging' ) : admin_url( 'admin.php?page=onecom-wp-staging' ),
'meta' => array(
'title' => __( 'Plugins', 'onecom-wp' ),
),
);
$admin_bar->add_menu( $args );
/*
* Account link to Control Panel
*/
$args = array(
'id' => 'one-cp',
'parent' => OC_PLUGIN_DOMAIN,
'title' => __( 'One.com Control Panel', 'onecom-wp' ),
'href' => OC_CP_LOGIN_URL,
'meta' => array(
'title' => __( 'Go to Control Panel at One.com', 'onecom-wp' ),
'target' => '_blank',
),
);
$admin_bar->add_menu( $args );
/*
* WordPress support
*/
$locale = get_locale();
$args = array(
'id' => 'one-wp-support',
'parent' => OC_PLUGIN_DOMAIN,
'title' => __( 'One.com Guides & FAQ', 'onecom-wp' ),
'href' => onecom_generic_locale_link( $request = 'main_guide', $locale ),
'meta' => array(
'title' => __( 'Go to Guides & FAQ at One.com', 'onecom-wp' ),
'target' => '_blank',
),
);
$admin_bar->add_menu( $args );
}
}
if ( ! function_exists( 'one_core_admin_callback' ) ) {
function one_core_admin_callback() {
$network = ( is_network_admin() && is_multisite() ) ? 'network/' : '';
include_once 'templates/' . $network . 'theme-listing.php';
}
}
if ( ! function_exists( 'one_core_theme_listing_callback' ) ) {
function one_core_theme_listing_callback() {
$network = ( is_network_admin() && is_multisite() ) ? 'network/' : '';
include_once 'templates/' . $network . 'theme-listing.php';
}
}
//Removed plugin listing
/**
* Function to get free position for menu
**/
if ( ! function_exists( 'onecom_get_free_menu_position' ) ) {
function onecom_get_free_menu_position( $start, $increment = 0.3 ) {
foreach ( $GLOBALS['menu'] as $key => $menu ) {
$menus_positions[] = $key;
}
if ( ! in_array( $start, $menus_positions ) ) {
return $start;
}
/* the position is already reserved find the closet one */
while ( in_array( $start, $menus_positions ) ) {
$start += $increment;
}
return (string) $start;
}
}
/**
* one.com updater
**/
if ( ! class_exists( 'ONECOMUPDATER' ) ) {
require_once ONECOM_WP_PATH . '/inc/update.php';
}
// Clean onboarding files if exists
add_action( 'admin_init', 'onecom_admin_init_callback' );
if ( ! function_exists( 'onecom_admin_init_callback' ) ) {
function onecom_admin_init_callback() {
require_once ONECOM_WP_PATH . '/inc/functions.php';
onecom_cleanup_onboarding_files();
}
}
/**
* one.com staging
**/
if ( ! class_exists( 'OneStaging\\OneStaging' ) && is_admin() ) {
include_once 'staging/one_staging.php';
\OneStaging\OneStaging::getInstance()->run();
}
/**
* oci entry point
**/
// Get POST or PUT request body to check if it is a POST call or GET call.
$entityBody = file_get_contents( 'php://input' );
// If POST content length is 0, then it is most probably a GET call.
if ( ! strlen( trim( $entityBody ) ) ) {
// Handle authentication request.
add_action(
'init',
function () {
if ( ! class_exists( 'OCLAUTH' ) &&
isset( $_GET['onecom-auth'] ) &&
! empty( $_GET['onecom-auth'] ) &&
file_exists( ONECOM_WP_PATH . OCL_FILE_PATH ) ) {
require_once ONECOM_WP_PATH . OCL_FILE_PATH;
$oclObj = OCLAUTH::getInstance();
$oclObj = null; // Destruct object.
}
}
);
}
/**
* oci show message on login page
* THIS FUNCTION IS CAUSING ISSUES ON LOGIN PAGE
**/
/*add_filter( 'login_message', function ( $message ) {
if ( ! is_user_logged_in() && ! class_exists( 'OCLAUTH' ) &&
isset( $_GET['redirect_to'] ) &&
file_exists( ONECOM_WP_PATH . OCL_FILE_PATH ) ) {
require_once ONECOM_WP_PATH . OCL_FILE_PATH;
$oclObj = OCLAUTH::getInstance();
$redirectto = $_GET['redirect_to'];
$query = parse_url( $redirectto, PHP_URL_QUERY );
$queries = array();
parse_str( $query, $queries );
if ( isset( $queries[ $oclObj::TOKENKEY ] ) && ! empty( $queries[ $oclObj::TOKENKEY ] ) ) {
$jwtPassVal = $queries[ $oclObj::TOKENKEY ];
$oclObj->checkToken( $jwtPassVal );
if ( ! $oclObj->tokenStatus ) {
$message = $oclObj->tokenMessage;
$oclObj = null;//destruct object
return '