hash ) && $domainInfo->hash ) {
$hash = $domainInfo->hash;
}
$mySecret = trim( Base32::encodeUpper( $hash ) );
$otp = TOTP::create( $mySecret, $valid_for, 'sha1', $length );
return $otp->now();
}
}
//TODO: Currently not using
if ( ! function_exists( 'oc_generate_totp_for_cluster' ) ) {
function oc_generate_totp_for_cluster( $valid_for = 30, $length = 6 ) {
$fileString = '{}';
if ( file_exists( '/run/mail.conf' ) ) {
$fileString = trim( file_get_contents( '/run/mail.conf' ) );
} else {
error_log( 'mail.conf file does\'nt exist on cluster' );
return 'mail.conf file does\'nt exist on cluster';
}
$domainInfo = json_decode( $fileString );
$hash = 'oc';
if ( isset( $domainInfo->wp->hash ) && $domainInfo->wp->hash ) {
$hash = $domainInfo->wp->hash;
}
global $webconfig_name;
$webconfig_name = $domainInfo->wp->webconfig;
$mySecret = trim( Base32::encodeUpper( $hash ) );
$otp = TOTP::create( $mySecret, $valid_for, 'sha1', $length );
return $otp->now();
}
}
if ( ! function_exists( 'oc_validate_domain' ) ) {
function oc_validate_domain( $force = false, $domain = null ) {
// check transient
$oc_validate_domain = get_site_transient( 'oc_validate_domain' );
if ( ! empty( $oc_validate_domain ) && ! $force ) {
return $oc_validate_domain;
}
if ( ! $domain ) {
$domain = isset( $_SERVER['ONECOM_DOMAIN_NAME'] ) ? $_SERVER['ONECOM_DOMAIN_NAME'] : false;
}
//TODO: uncomment later
if ( ! $domain /*&& !is_cluster_domain()*/ ) {
return array(
'data' => null,
'error' => 'Empty domain',
'success' => false,
);
}
global $webconfig_name;
$totp = oc_generate_totp();
//change curl url
if ( is_cluster_domain() ) {
//create header for cluster model
$curl_url = MIDDLEWARE_URL . '/features/cluster';
$http_header = array(
'Cache-Control: no-cache',
'X-Onecom-Client-Domain: ' . $domain, //need to use from wp-config if available otherwise use domain parse
'X-TOTP: ' . $totp,
'cache-control: no-cache',
);
$http_header[] = 'X-ONECOM-CLUSTER-ID: ' . OC_CLUSTER_ID;
$http_header[] = 'X-ONECOM-WEBCONFIG-NAME: ' . $_SERVER['HTTP_X_GROUPONE_WEBCONFIG_NAME'];
} else {
//prepare headers for domain model
$curl_url = MIDDLEWARE_URL . '/features';
$http_header = array(
'Cache-Control: no-cache',
'X-Onecom-Client-Domain: ' . $domain, //need to use from wp-config if available otherwise use domain parse
'X-TOTP: ' . $totp,
'cache-control: no-cache',
);
}
$curl = curl_init();
curl_setopt_array(
$curl,
array(
CURLOPT_URL => $curl_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $http_header,
)
);
$response = curl_exec( $curl );
$response = json_decode( $response, true );
$err = curl_error( $curl );
curl_close( $curl );
if ( $err ) {
return array(
'data' => null,
'error' => __( 'Some error occurred, please reload the page and try again.', 'validator' ),
'success' => false,
);
} else {
// save transient for next calls
if ( is_blog_installed() ) {
set_site_transient( 'oc_validate_domain', $response, 12 * HOUR_IN_SECONDS );
}
// return latest response
return $response;
}
}
}
add_action( 'admin_init', 'oc_set_premi_flag' );
if ( ! function_exists( 'oc_set_premi_flag' ) ) {
function oc_set_premi_flag( $force = false ) {
$oc_premi_flag = get_site_transient( 'oc_premi_flag' );
if ( ( ! $oc_premi_flag ) || $force ) {
$oc_premi_flag = oc_validate_domain( $force );
if ( isset( $oc_premi_flag['data'] ) && $oc_premi_flag['data'] ) {
if ( is_blog_installed() ) {
set_site_transient( 'oc_premi_flag', $oc_premi_flag['data'], 12 * HOUR_IN_SECONDS );
}
}
}
if ( ! isset( $oc_premi_flag['data'] ) ) {
$oc_premi_flag['data'] = $oc_premi_flag;
}
return $oc_premi_flag;
}
}
// hook onto WP CRON to check transients
add_action( 'wp_version_check', 'oc_set_premi_flag_cron' );
if ( ! function_exists( 'oc_set_premi_flag_cron' ) ) {
function oc_set_premi_flag_cron() {
oc_set_premi_flag( true );
}
}
/**
* Feature mapping
*/
if ( ! function_exists( 'oc_pm_features' ) ) {
function oc_pm_features( $key, $val ) {
$operations = array(
'ins' => OC_ID_OCI,
'stg' => 'STAGING_ENV',
'stheme' => OC_ID_STD_THMS,
'ptheme' => OC_ID_PRM_THMS,
'pcache' => 'PERFORMANCE_CACHE',
'mwp' => 'MWP_ADDON',
);
if ( ! array_key_exists( $key, $operations ) ) {
return false;
}
return in_array( $operations[ $key ], (array) $val );
}
}
/**
* Function oc_get_logline()
* Function to prepare log data to be sent to WPAPI
*
* @param array $post_data An array of varialbles intercepted from $_POST.
*
* @return string
* @since v0.1.3
*/
if ( ! function_exists( 'oc_get_logline' ) ) {
function oc_get_logline( $post_data ) {
$is_premium = strip_tags( $post_data['isPremium'] );
$message = "isPremium:$is_premium";
$state = 'state';
$feature_condition = ( isset( $post_data[ OC_FTR_STR ] ) && ( $post_data[ OC_FTR_STR ] != '' ) );
$theme_condition = ( isset( $post_data[ OC_THM_STR ] ) && ( $post_data[ OC_THM_STR ] != '' ) );
if ( ! ( $feature_condition || $theme_condition ) ) {
return false;
}
if ( isset( $post_data[ OC_FTR_STR ] ) && $post_data[ OC_FTR_STR ] != '' ) {
$feature = strip_tags( $post_data[ OC_FTR_STR ] );
$message .= ";feature:$feature";
}
if ( isset( $post_data[ $state ] ) && $post_data[ $state ] != '' ) {
$state = filter_var( $post_data[ $state ], FILTER_SANITIZE_NUMBER_INT );
$message .= ";state:$state";
}
if ( isset( $post_data['featureAction'] ) && $post_data['featureAction'] != '' ) {
$feature_action = strip_tags( $post_data['featureAction'] );
$message .= ";featureAction:$feature_action";
}
if ( isset( $post_data[ OC_THM_STR ] ) && ( $post_data[ OC_THM_STR ] != '' ) ) {
$theme = strip_tags( $post_data[ OC_THM_STR ] );
$message .= ";theme:$theme";
}
//append the available features at the end
$feature_array = oc_set_premi_flag( true );
$feature_string = implode( '|', $feature_array['data'] );
$feature_string = rtrim( $feature_string, '|' );
return $message . ";features_available:$feature_string";
}
}
/**
* Function to handle validation by ajax
*/
add_action( 'wp_ajax_oc_validate_action', 'oc_validate_action_cb' );
if ( ! function_exists( 'oc_validate_action_cb' ) ) {
function oc_validate_action_cb() {
$data = isset( $_POST['operation'] ) ? strip_tags( $_POST['operation'] ) : '';
$action_type = isset( $_POST['actionType'] ) ? strip_tags( $_POST['actionType'] ) : '';
$result = oc_set_premi_flag( true );
$status = 'status';
$data_str = 'data';
$referrer = '';
if ( isset( $_POST['referrer'] ) ) {
$referrer = strpos( $_POST['referrer'], 'step=theme' ) ? 'install_wizard' : 'themes_page';
}
if ( $result[ $data_str ] == null && $result[ OC_SUCCESS_STR ] != 1 ) {
$response = array(
$status => '',
'msg' => OC_GENERIC_ERR_MSG . ' [' . $result[ OC_ERR_STR ] . ']',
);
} elseif ( oc_pm_features( $data, $result[ $data_str ] ) || in_array( 'MWP_ADDON', $result[ $data_str ] ) ) {
$response = array(
$status => OC_SUCCESS_STR,
);
} else {
$response = array(
$status => 'failed',
);
}
// push stats
if ( $action_type != '' && class_exists( OC_PUSH_STATS ) ) {
$premium = ( empty( $_POST['isPremium'] ) || $_POST['isPremium'] !== 'true' ) ? 0 : 1;
$slug = isset( $_POST['theme'] ) ? $_POST['theme'] : '';
if ( $action_type === 'wppremium_install_theme' && isset( $_POST['theme'] ) ) {
( class_exists( OC_PUSH_STATS ) ? \OCPushStats::push_stats_event_themes_and_plugins( 'install', 'theme', "$slug", $referrer, array( PREMIUM => "$premium" ) ) : '' );
} elseif ( $action_type === 'wppremium_preview_theme' && isset( $_POST['theme'] ) ) {
( class_exists( OC_PUSH_STATS ) ? \OCPushStats::push_stats_event_themes_and_plugins( 'preview', 'theme', "$slug", $referrer, array( PREMIUM => "$premium" ) ) : '' );
} elseif ( $action_type === 'wppremium_click_upgrade' && $_POST['feature'] === 'theme' ) {
( class_exists( OC_PUSH_STATS ) ? \OCPushStats::push_stats_event_themes_and_plugins( 'click_upgrade', 'theme', $_POST['theme'], $referrer, array( PREMIUM => "$premium" ) ) : '' );
} elseif ( $action_type === 'wppremium_close_upgrade' && $_POST['feature'] === 'theme' ) {
( class_exists( OC_PUSH_STATS ) ? \OCPushStats::push_stats_event_themes_and_plugins( 'close_upgrade', 'theme', $_POST['theme'], $referrer, array( PREMIUM => "$premium" ) ) : '' );
}
}
echo wp_send_json( $response );
wp_die();
}
}
/* validator scripts */
add_action(
'admin_print_scripts',
function () {
?>
base, $thm_screens ) ) {
$type = OC_THMS_STR;
}
if ( isset( $_POST['action'] ) && $_POST['action'] === 'show_plugin_dependent_popup' ) {
$dependent_plugin = prepare_dependent_plugin_popup( $_POST['popupContent'] );
wp_send_json(
array(
'success' => true,
'data' => $dependent_plugin,
)
);
} else {
?>
' . '
' . __( 'Quick fix or ignore recommendations', OC_VALIDATOR_DOMAIN ) . '';
echo '' . __( 'Get better performance with Performance Cache and CDN', OC_VALIDATOR_DOMAIN ) . '';
echo '' . __( 'Get notified about security with Vulnerability Monitoring', OC_VALIDATOR_DOMAIN ) . '';
echo '' . __( 'Get helpful tips with Advanced Error Page', OC_VALIDATOR_DOMAIN ) . '';
echo '' . __( 'Get access to our Premium themes', OC_VALIDATOR_DOMAIN ) . '';
echo '' . __( 'Increase your authentication security', OC_VALIDATOR_DOMAIN ) . '';
echo '' . __( 'Host on our WordPress servers built for speed', OC_VALIDATOR_DOMAIN ) . '';
echo '';
?>
';
foreach ( $data['bodylist'] as $key => $liVal ) {
echo '
' . nl2br( stripslashes( __( $liVal, OC_VALIDATOR_DOMAIN ) ) ) . '';
}
echo '';
echo '';
echo nl2br( stripslashes( __( $data['footer-desc'], OC_VALIDATOR_DOMAIN ) ) );
?>
' . __( 'Premium', OC_VALIDATOR_DOMAIN ) . '';
}
}
/**
* Function to show inline premium badge
*/
$oc_inline_badge_fn = 'oc_inline_badge';
add_filter( 'onecom_premium_inline_badge', $oc_inline_badge_fn, 10, 4 ); // attach with MM
add_filter( 'oc_preview_install', $oc_inline_badge_fn, 10, 4 ); // attach with preview install
add_filter( 'oc_staging_button_create', $oc_inline_badge_fn, 10, 4 ); // attach with staging create
add_filter( 'oc_staging_button_delete', $oc_inline_badge_fn, 10, 4 ); // attach with staging delete
if ( ! function_exists( $oc_inline_badge_fn ) ) {
function oc_inline_badge( $html, $type = '', $feature = '', $cuEventTrackId = '' ) {
$features = (array) oc_set_premi_flag();
// Check if Premium features
if ( isset( $features['data'] ) ) {
$features = $features['data'];
}
if ( oc_pm_features( $feature, $features ) || in_array( 'MWP_ADDON', $features ) ) {
$badge = ' Premium';
} else {
if ( $type == '' ) {
$type = __( 'This is a Premium Theme', OC_VALIDATOR_DOMAIN );
}
$badge = '' . $type . ' ' . __( 'Learn more', OC_VALIDATOR_DOMAIN ) . '';
}
return $html . $badge;
}
}
/**
* Function oc_val_exclude_themes
* Remove ILO app theme from Theme listing in plugin section
*
* @param array $themes , an array of onecom themes
* @param bool $exclude_themes , weather or not to exclude ilo theme?
*
* @return array
*/
if ( ! function_exists( 'oc_val_exclude_themes' ) ) {
function oc_val_exclude_themes( $themes, $exclude_themes ) {
if ( ! $exclude_themes || ! is_array( $themes ) ) {
return $themes;
}
foreach ( $themes as $theme_item ) {
if ( isset( $theme_item->collection ) ) {
foreach ( $theme_item->collection as $key => $theme ) {
if ( isset( $theme->slug ) && ( $theme->slug === 'onecom-ilotheme' ) ) {
unset( $theme_item->collection[ $key ] );
}
}
}
}
return $themes;
}
}
/**
* Function to query update
**/
if ( ! function_exists( 'onecom_query_check' ) ) {
function onecom_query_check( $url, $page = null ) {
if ( $page != null || $page != 1 || $page != '1' ) {
$url = add_query_arg(
array(
'page' => $page,
),
$url
);
}
return add_query_arg(
array(
'wp' => ONECOM_WP_CORE_VERSION,
'php' => ONECOM_PHP_VERSION,
OC_ITM_COUNT_STR => 1000,
),
$url
);
}
}
/**
* Fetch one.com themes
*/
if ( ! function_exists( 'onecom_fetch_themes' ) ) {
function onecom_fetch_themes( $page = 1, $exclude_ilotheme = false ) {
$themes = array();
$transientName = 'onecom_themes';
$themes = (array) get_site_transient( $transientName );
/* Note- simple switch over from previous data to new data structure */
if ( ! isset( $themes['total'] ) && ! empty( $themes ) ) {
delete_site_transient( $transientName );
$themes = (array) get_site_transient( $transientName );
}
// If requested page already exists in transient, return
if ( ! empty( $themes ) && isset( $themes[ OC_ITM_COUNT_STR ] ) && $themes[ OC_ITM_COUNT_STR ] >= 1000 ) {
if ( array_key_exists( $page, $themes ) ) { // page exists in current themes
$themes = oc_val_exclude_themes( $themes, $exclude_ilotheme );
return $themes[ $page ];
}
}
$fetch_themes_url = MIDDLEWARE_URL . '/themes';
$fetch_themes_url = onecom_query_check( $fetch_themes_url, $page );
global $wp_version;
$args = array(
'timeout' => 5,
'httpversion' => '1.0',
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url(),
'body' => null,
'compress' => false,
'decompress' => true,
'sslverify' => true,
'stream' => false,
);
$response = wp_remote_get( $fetch_themes_url, $args );
if ( is_wp_error( $response ) ) {
if ( isset( $response->errors['http_request_failed'] ) ) {
$errorMessage = __( 'Connection timed out', OC_VALIDATOR_DOMAIN );
} else {
$errorMessage = $response->get_error_message();
}
} else {
if ( wp_remote_retrieve_response_code( $response ) != 200 ) {
$errorMessage = '(' . wp_remote_retrieve_response_code( $response ) . ') ' . wp_remote_retrieve_response_message( $response );
} else {
$body = wp_remote_retrieve_body( $response );
$body = json_decode( $body );
if ( ! empty( $body ) && $body->success ) {
$themes[ OC_ITM_COUNT_STR ] = $body->data->item_count;
$themes['total'] = $body->data->total;
$themes[ $body->data->current_page ] = (object) array();
$themes[ $body->data->current_page ]->collection = $body->data->collection;
$themes[ $body->data->current_page ]->page_number = $body->data->current_page;
} elseif ( ! $body->success ) {
if ( $body->error == 'RESOURCE NOT FOUND' ) {
$try_again_url = add_query_arg(
array(
'request' => OC_THMS_STR,
),
''
);
$try_again_url = wp_nonce_url( $try_again_url, '_wpnonce' );
$errorMessage = __( 'Sorry, no compatible themes found for your version of WordPress and PHP.', OC_VALIDATOR_DOMAIN ) . ' ' . __( 'Try again', OC_VALIDATOR_DOMAIN ) . '';
} else {
$errorMessage = $body->error;
}
}
}
$themes = oc_val_exclude_themes( $themes, $exclude_ilotheme );
if ( is_blog_installed() ) {
set_site_transient( $transientName, $themes, 24 * HOUR_IN_SECONDS );
}
}
if ( empty( $themes ) || ! isset( $themes[ $page ] ) ) {
return new WP_Error( 'message', $errorMessage );
} else {
return $themes[ $page ];
}
}
}
/**
* Get premium themes names
*/
if ( ! function_exists( 'onecom_is_premium_theme' ) ) {
function onecom_is_premium_theme( $name = null ) {
$themes = onecom_fetch_themes();
$themes = ( isset( $themes->collection ) && ! empty( $themes->collection ) ) ? $themes->collection : array();
$themes = array_reverse( array_reverse( $themes ) );
$premium_themes = array();
foreach ( $themes as $theme ) {
if ( in_array( PREMIUM, (array) $theme->tags ) ) {
$premium_themes[] = $theme->name;
}
}
if ( $name == null ) {
return $premium_themes;
}
if ( in_array( $name, $premium_themes ) ) {
return true;
}
return false;
}
}
/**
* Check if theme is to be activated
*/
if ( ! function_exists( 'oc_check_theme_eligibility' ) ) {
function oc_check_theme_eligibility( $features, $stylesheet = '' ) {
// exit if it is not a one.com theme
$theme = wp_get_theme( $stylesheet );
if ( 'one.com' !== strtolower( $theme->display( OC_AUTHOR_STR, false ) ) ) {
return true;
}
// exit if premium package
if ( in_array( OC_ID_PRM_THMS, $features ) ) {
return true;
}
// check if non-premium WP package & trying to use STANDARD THEME
if (
( in_array( OC_ID_OCI, $features ) || in_array( OC_ID_STD_THMS, $features ) )
&& ! onecom_is_premium_theme( $theme->display( OC_AUTHOR_STR, false ) )
) {
return true;
}
return false;
}
}
// Show notice for a non-premium WP package
if ( ! function_exists( 'onecom_premium_theme_admin_notice' ) ) {
function onecom_premium_theme_admin_notice( $html = '' ) {
global $current_screen;
// only show banner on the onecom plugins allowed screens
$allowed_screens = array(
'one-com_page_onecom-wp-plugins',
'admin_page_onecom-wp-recommended-plugins',
'admin_page_onecom-wp-discouraged-plugins',
);
if ( isset( $current_screen->id ) && ! in_array( $current_screen->id, $allowed_screens ) ) {
return false;
}
$badge = '' . sprintf( __( 'Make your website even more powerful with %sManaged WordPress%s', OC_VALIDATOR_DOMAIN ), '', '' ) . '
';
if ( $html != '' ) {
return $html . $badge;
}
echo $badge;
}
}
// Admin one.com notice css
if ( ! function_exists( 'onecom_premium_error_activation_style' ) ) {
function onecom_premium_error_activation_style() {
echo '';
}
}
/**
* Validate premium theme activation
*/
add_action( 'after_switch_theme', 'onecom_premium_theme_check', 10, 2 );
if ( ! function_exists( 'onecom_premium_theme_check' ) ) {
function onecom_premium_theme_check( $oldtheme_name, $oldtheme ) {
// just using the variable to reduce sonar warning
$oldtheme_name;
// exit if it is not a one.com theme
$theme = wp_get_theme();
if ( 'one.com' !== strtolower( $theme->display( OC_AUTHOR_STR, false ) ) ) {
return true;
}
// exit if premium package
$features = (array) oc_set_premi_flag( true )['data'];
if ( in_array( OC_ID_PRM_THMS, $features ) || in_array( 'MWP_ADDON', $features ) ) {
return true;
}
// check if non-premium WP package & trying to use STANDARD THEME
if (
( in_array( OC_ID_OCI, $features ) || in_array( OC_ID_STD_THMS, $features ) ) &&
! onecom_is_premium_theme( $theme->display( OC_NAME_STR, false ) )
) {
return true;
}
// Show notice for a non-WP package
add_action( 'admin_notices', 'onecom_premium_theme_admin_notice', 2 );
// Custom styling for default admin notice.
add_action( 'admin_head', 'onecom_premium_error_activation_style' );
// Switch back to previous theme.
switch_theme( $oldtheme->stylesheet );
onecom_show_modal( true );
return true;
}
}
add_action( 'admin_footer', 'onecom_show_modal' );
/**
* @param $show
* function to show upgrade modal on theme switch
* @return void
*/
if ( ! function_exists( 'onecom_show_modal' ) ) {
function onecom_show_modal( $show = false ) {
if ( $show === true) {
?>
base;
// exit if not on themes page
if ( ! ( isset( $_GET ) && ! empty( $_GET ) && ( $current_page == OC_THMS_STR || $current_page == 'themes-network' ) ) ) {
return;
}
// check if oc_error
if ( isset( $_GET[ OC_ERR_STR ] ) && 'oc_error' == $_GET[ OC_ERR_STR ] ) {
$network = is_multisite() ? 'network_' : '';
add_action( $network . 'admin_notices', 'onecom_premium_theme_admin_notice', 2 );
}
// exit if theme action is not for activating/enabling
if ( ! ( $_GET['action'] == 'enable' || $_GET['action'] == 'activate' ) ) {
return;
}
// exit if theme stylesheet not available
if ( ! ( isset( $_GET[ OC_THM_STR ] ) || isset( $_GET['stylesheet'] ) ) ) {
return;
}
// get stylesheet name for single/network site
$stylesheet = isset( $_GET[ OC_THM_STR ] ) ? $_GET[ OC_THM_STR ] : $_GET['stylesheet'];
// check if this theme is available for the current package; exit if available
$features = (array) oc_set_premi_flag( true );
if ( oc_check_theme_eligibility( $features, $stylesheet ) ) {
return true;
}
// if theme not available, prepare for redirecting back on the themes page
$temp_args = array( 'enabled', OC_ERR_STR );
$_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
$referer = remove_query_arg( $temp_args, wp_get_referer() );
if ( false === strpos( $referer, '/network/themes.php' ) ) {
wp_redirect( network_admin_url( 'themes.php?error=oc_error' ) );
} else {
wp_safe_redirect( add_query_arg( OC_ERR_STR, 'oc_error', $referer ) );
}
exit;
}
}
add_action( 'admin_print_footer_scripts', 'oc_pm_badge_injection', 999 );
if ( ! function_exists( 'oc_pm_badge_injection' ) ) {
function oc_pm_badge_injection( $hook_suffix ) {
$installed_themes = wp_get_themes();
$themes_to_mark_array = array();
foreach ( $installed_themes as $theme ) {
if ( 'one.com' === strtolower( $theme->display( OC_AUTHOR_STR, false ) )
&& onecom_is_premium_theme( $theme->display( OC_AUTHOR_STR, false ) )
) {
$themes_to_mark_array[] = str_replace( ' ', '-', strtolower( $theme->display( OC_AUTHOR_STR, false ) ) );
$themes_to_mark = json_encode( $themes_to_mark_array );
}
}
?>
display( OC_AUTHOR_STR, false ) )
&& onecom_is_premium_theme( $theme->display( OC_AUTHOR_STR, false ) )
) {
$themes_to_mark_arr[] = strtolower( $theme->display( OC_AUTHOR_STR, false ) );
$themes_to_mark = json_encode( $themes_to_mark_arr );
}
}
wp_add_inline_script(
'customize-controls',
'(function ( api ) {
api.bind( "ready", function () {
var _query = api.previewer.query;
api.previewer.query = function () {
var theme_ = ' . $themes_to_mark . ';
var query = _query.call( this );
// console.log($themes_to_mark);
// console.log(query.customize_theme)
if(-1 !== theme_.indexOf(query.customize_theme)){
//alert("halt!!");
}
query.foo = "bar";
return query;
};
});
})( wp.customize );'
);
}
);
/**
* Function to get the client ip address
**/
if ( ! function_exists( 'onecom_get_client_ip_env' ) ) {
function onecom_get_client_ip_env() {
if ( getenv( 'HTTP_CLIENT_IP' ) ) {
$clientIP = @getenv( 'HTTP_CLIENT_IP' );
} elseif ( getenv( 'REMOTE_ADDR' ) ) {
$clientIP = @getenv( 'REMOTE_ADDR' );
} else {
$clientIP = $_SERVER['ONECOM_CLIENT_IP'] = '0.0.0.0';
}
return $clientIP;
}
}
/**
* Function to buil URLs as per locale
*/
global $onecom_global_links;
$onecom_global_links = array();
$onecom_global_links['en'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/en-us/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/en-us/articles/115005586029-Discouraged-WordPress-plugins',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/en-us/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/en-us/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/en/wordpress-hosting',
);
$onecom_global_links['cs_CZ'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/cs/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/cs/articles/115005586029-Nedoporu%C4%8Dovan%C3%A9-moduly-plug-in-ve-WordPressu',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/cs/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/cs/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/cs/wordpress',
);
$onecom_global_links['da_DK'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/da/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/da/articles/115005586029-Frar%C3%A5dede-WordPress-plugins',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/da/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/da/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/da/wordpress',
);
$onecom_global_links['de_DE'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/de/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/de/articles/115005586029-Nicht-empfohlene-Plugins',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/de/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/de/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/de/wordpress',
);
$onecom_global_links['es_ES'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/es/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/es/articles/115005586029-Plugins-de-WordPress-no-recomendados',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/es/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/es/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/es/wordpress',
);
$onecom_global_links['fr_FR'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/fr/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/fr/articles/115005586029-Les-plugins-WordPress-d%C3%A9conseill%C3%A9s',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/fr/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/fr/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/fr/wordpress',
);
$onecom_global_links['it_IT'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/it/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/it/articles/115005586029-Plugin-per-WordPress-sconsigliati',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/it/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/it/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/it/wordpress',
);
$onecom_global_links['nb_NO'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/no/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/no/articles/115005586029-Ikke-anbefalte-WordPress-plugins',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/no/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/no/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/no/wordpress',
);
$onecom_global_links['nl_NL'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/nl/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/nl/articles/115005586029-Niet-aanbevolen-WordPress-plugins',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/nl/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/nl/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/nl/wordpress-hosting',
);
$onecom_global_links['pl_PL'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/pl/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/pl/articles/115005586029-Niezalecane-wtyczki-WordPress',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/pl/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/pl/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/pl/wordpress',
);
$onecom_global_links['pt_PT'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/pt/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/pt/articles/115005586029-Plugins-para-o-WordPress-desaconselh%C3%A1veis',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/pt/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/pt/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/pt/wordpress',
);
$onecom_global_links['fi'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/fi/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/fi/articles/115005586029-WordPress-lis%C3%A4osat-joiden-k%C3%A4ytt%C3%B6%C3%A4-ei-suositella',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/fi/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/fi/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/fi/wordpress',
);
$onecom_global_links['sv_SE'] = array(
OC_MAIN_GUIDE_STR => 'https://help.one.com/hc/sv/categories/360002171377-WordPress',
OC_DISC_GUIDE_STR => 'https://help.one.com/hc/sv/articles/115005586029-WordPress-till%C3%A4gg-som-vi-avr%C3%A5der-fr%C3%A5n',
OC_STG_GUIDE_STR => 'https://help.one.com/hc/sv/articles/360000020617',
OC_COOKIE_GUIDE_STR => 'https://help.one.com/hc/sv/articles/360001472758',
OC_PRM_PAGE_STR => 'https://www.one.com/sv/wordpress-hosting',
);
if ( ! function_exists( 'onecom_generic_locale_link' ) ) {
function onecom_generic_locale_link( $request, $locale, $lang_only = 0 ) {
global $onecom_global_links;
if ( ! empty( $onecom_global_links ) && array_key_exists( $locale, $onecom_global_links ) ) {
if ( $lang_only != 0 ) {
return strstr( $locale, '_', true );
}
if ( ! empty( $onecom_global_links[ $locale ][ $request ] ) ) {
return $onecom_global_links[ $locale ][ $request ];
}
}
if ( $lang_only != 0 ) {
return 'en';
}
return $onecom_global_links['en'][ $request ];
}
}
/**
* Hide one.com plugins from WordPress plugin listing
*/
if ( ! function_exists( 'onecom_hide_plugins' ) ) {
function onecom_hide_plugins( $plugins ) {
global $wp_list_table;
$url_condition = ( empty( $_GET['premium'] ) || intval( $_GET['premium'] ) !== 1 );
foreach ( $wp_list_table->items as $key => $plugin ) {
if ( $url_condition && in_array( $plugin['Author'], array( 'onecom', 'one.com' ) ) ) {
unset( $wp_list_table->items[ $key ] );
}
}
}
}
/* Deactivated hiding the plugins until we ensure a reliable auto-updates solution */
//add_action( 'pre_current_active_plugins', 'onecom_hide_plugins' );
/*
* Force enable automatic updates for one.com plugins
* Disable email notification if one.com plugin update
* */
function onecom_autoupdates( $update, $item ) {
if (
is_object( $item )
&& property_exists( $item, 'Author' )
&& in_array( $item->Author, array( 'one.com', 'onecom' ) )
) {
add_filter( 'auto_plugin_update_send_email', '__return_false' );
return true;
}
return $update;
}
add_filter( 'auto_update_plugin', 'onecom_autoupdates', 10, 2 );
// one.com actions (stats) after automatic update completed
function onecom_automatic_updates_complete( $update_results ) {
// return if it is not a plugin update
if ( empty( $update_results ) || ! isset( $update_results['plugin'] ) ) {
return;
}
// fetch each one.com plugin update
foreach ( $update_results['plugin'] as $result ) {
if ( property_exists( $result, 'item' )
&& property_exists( $result->item, 'Author' )
&& in_array( $result->item->Author, array( 'one.com', 'onecom' ) )
) {
// prepare data to push into stats
$plugin_slug = $result->item->slug;
$additional_info = array(
'additional_info' => json_encode(
array(
'current_version' => $result->item->current_version,
'new_version' => $result->item->new_version,
)
),
);
if ( strpos( 'onecom-vcache', __DIR__ ) ) {
$referrer = basename( dirname( __DIR__, 3 ) );
} else {
$referrer = basename( dirname( __DIR__, 2 ) );
}
// Push auto update stats
( class_exists( OC_PUSH_STATS ) ? \OCPushStats::push_stats_event_themes_and_plugins( 'auto_update', 'plugin', $plugin_slug, $referrer, $additional_info ) : '' );
}
}
}
add_action( 'automatic_updates_complete', 'onecom_automatic_updates_complete' );
if ( ! function_exists( 'oc_upgrade_link' ) ) {
function oc_upgrade_link( $type = '' ) {
$first_part = 'https://www.one.com/admin/select-admin-domain.do?domain=';
$middle_part = ! empty( OC_DOMAIN_NAME ) ? OC_DOMAIN_NAME : '';
$last_part = '&targetUrl=/admin/managedwp/upgrade.do';
return $first_part . $middle_part . $last_part;
}
}
if ( ! defined( 'OC_INLINE_LOGO' ) ) {
define( 'OC_INLINE_LOGO', sprintf( '
', plugin_dir_url( __FILE__ ) . '/assets/images/one.com.black.svg', __( 'One.com', OC_VALIDATOR_DOMAIN ) ) );
}
// function moved from generic plugin to validator //
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;
}
}
// ------------ redesign notice --------------- //
//ajax handle for set trasient forever
add_action( 'wp_ajax_oc_set_redesign_notice_forever', 'oc_set_redesign_notice_forever_callback' );
function oc_set_redesign_notice_forever_callback() {
$status = false;
$message = __( 'Some error occurred, please reload the page and try again.', OC_VALIDATOR_DOMAIN );
if ( isset( $_POST['action'] ) && $_POST['action'] === 'oc_set_redesign_notice_forever' && $_POST['setTransient'] === 'forever' ) {
$plugin_forever_key = 'redesign_notices_forever_dismiss_' . get_current_user_id();
set_site_transient( $plugin_forever_key, 1, 0 );//WITH NO EXPIRATION
$status = true;
$message = __( 'Updated', OC_VALIDATOR_DOMAIN );
}
wp_send_json(
array(
'status' => $status,
'message' => $message,
)
);
wp_die();
}
//To add admin notices on dashboard about plugin redesign
if ( ! function_exists( 'oc_plugin_redesign_notices' ) ) {
function oc_plugin_redesign_notices() {
$user = wp_get_current_user();
//return if not administrator user role
if ( ( ! isset( $user->roles ) ) || ( ! in_array( 'administrator', (array) $user->roles ) ) ) {
return;
}
//Prepare redesign transient keys
$plugin_30days_key = 'redesign_notices_show_for_30_days_' . get_current_user_id();
$plugin_forever_key = 'redesign_notices_forever_dismiss_' . get_current_user_id();
$isExecuted = 'redesign_notices_for_executed_' . get_current_user_id();
$get_30days_transient = get_site_transient( $plugin_30days_key );
$get_forever_dismiss_transient = get_site_transient( $plugin_forever_key );
$isSetExecuted = get_site_transient( $isExecuted );
//return if dismiss for forever
if ( $get_forever_dismiss_transient || ! empty( $get_forever_dismiss_transient ) ) {
return;
}
if ( ( ! $get_30days_transient || empty( $get_30days_transient ) ) && ( ! $isSetExecuted || empty( $isSetExecuted ) ) ) {
set_site_transient( $plugin_30days_key, 1, 30 * DAY_IN_SECONDS );//for 30 days
//set_site_transient($plugin_30days_key, 1, 2 * MINUTE_IN_SECONDS);//for 2 minute
set_site_transient( $isExecuted, 1, 0 );
}
$get_30days_transient = get_site_transient( $plugin_30days_key );
//if 30 days transient expire then simply return
if ( ! $get_30days_transient || empty( $get_30days_transient ) ) {
return;
}
$img_url = plugin_dir_url( __FILE__ ) . 'assets/images/one.com-pl.svg';
$plugin_redesign_img = plugin_dir_url( __FILE__ ) . 'assets/images/plugin-redesign.svg';
$crossIcon = plugin_dir_url( __FILE__ ) . 'assets/images/notice-cross-icon.svg';
?>
tag in website page source based on one.com plugins
require_once plugin_dir_path( __FILE__ ) . 'oc-js-vars.php';