url = menu_page_url( 'onecom-wp-health-monitor', false ); $this->staging_url = (empty(menu_page_url( 'onecom-wp-staging', false ))) ? menu_page_url( 'onecom-wp-staging-blocked', false ) : menu_page_url( 'onecom-wp-staging', false ); $this->theme_url = menu_page_url( 'onecom-wp-themes', false ); $this->cookie_banner_url = menu_page_url( 'onecom-wp-cookie-banner', false ); //plugin page one.com Plugins menu $this->plugin_url = ( is_multisite() && is_network_admin() ) ? network_admin_url( 'admin.php?page='.MARKETPLACE_PAGE_SLUG ) : admin_url( 'admin.php?page='.MARKETPLACE_PAGE_SLUG ); $this->health_tooltip = addslashes( __( 'Health Monitor scans your website for potential security issues and checks the overall state of your site.', 'onecom-wp' ) ); $this->theme_tooltip = addslashes( __( 'Exclusive themes specially crafted for one.com customers.', 'onecom-wp' ) ); $this->plugin_tooltip = addslashes( __( 'Plugins that bring the one.com experience and services to WordPress.', 'onecom-wp' ) ); $this->cookie_banner_tooltip = addslashes( __( 'Show a banner on your website to inform visitors about cookies and get their consent.', 'onecom-wp' ) ); add_action( 'wp_dashboard_setup', array( $this, 'osch_widget_cb' ) ); //removed themes shortcut link from the welcome panel// add_action( 'admin_head-themes.php', array( $this, 'oc_themes_button' ) ); add_action( 'admin_head-plugins.php', array( $this, 'oc_plugins_button' ) ); add_action( 'admin_head-plugin-install.php', array( $this, 'oc_plugins_button' ) ); add_action( 'admin_head-widgets.php', array( $this, 'oc_cookie_banner_button' ) ); add_action( 'admin_head-options-privacy.php', array( $this, 'oc_cookie_banner_box' ) ); add_action( 'admin_head-options-general.php', array( $this, 'oc_staging_button' ) ); add_action( 'admin_head-site-health.php', array( $this, 'oc_site_health_info' ) ); add_action( 'tool_box', array( $this, 'tools_page_staging_box' ) ); add_action( 'tool_box', array( $this, 'tools_page_health_monitor_box' ) ); add_action( 'admin_head', array( $this, 'oc_button_css' ) ); } /** * adds widget to the wp admin dashboard */ public function osch_widget_cb() { $user = wp_get_current_user(); if ( ( ! isset( $user->roles ) ) || ( ! in_array( 'administrator', (array) $user->roles ) ) ) { return; } wp_add_dashboard_widget( self::WID, '
' . __( 'Go to control panel', 'onecom-wp' ) . 'onecom-logo
', array( $this, 'ocsh_widget_cb' ) ); global $wp_meta_boxes; if ( isset( $wp_meta_boxes[ self::DASHBOARD ] ) ) { $normal_dashboard = $wp_meta_boxes[ self::DASHBOARD ]['normal']['core']; $example_widget_backup = array( self::WID => $normal_dashboard[ self::WID ] ); unset( $normal_dashboard[ self::WID ] ); $sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard ); $wp_meta_boxes[ self::DASHBOARD ]['normal']['core'] = $sorted_dashboard; } } /** * checks for health monitor scan in db and returns value based on the result */ public function ocsh_widget_cb() { $site_scan_transient = get_site_transient( 'ocsh_site_scan_result' ); $site_scan_result = oc_sh_calculate_score( $site_scan_transient ); $colors = array( 'poor' => '#D20019', 'ok' => '#FF755A', 'good' => '#76B82A', ); $color = $colors['good']; $score = ''; if ( isset( $site_scan_result[ self::SCORE ] ) ) { if ( $site_scan_result[ self::SCORE ] < 75 && $site_scan_result[ self::SCORE ] >= 50 ) { $color = $colors['ok']; } elseif ( $site_scan_result[ self::SCORE ] < 50 ) { $color = $colors['poor']; } $score = '' . round( $site_scan_result[ self::SCORE ] ) . '%'; } echo '

' . __( self::HEALTH_MONITOR, 'onecom-wp' ) . '

' . __( 'More insights', 'onecom-wp' ) . '
'; if ( $site_scan_result && isset( $site_scan_result['todo'] ) ) { $todo = $site_scan_result['todo']; echo '
' . __( 'Score', 'onecom-wp' ) . ':' . $score . '
' . __( 'To do', 'onecom-wp' ) . ': ' . $todo . ' ' . __( 'items', 'onecom-wp' ) . '
'; } else { echo '
' . __( 'Health Monitor lets you monitor the essential security and performance checkpoints and fix them if needed.', 'onecom-wp' ) . '
' . __( self::SCAN_NOW, 'onecom-wp' ) . '
'; } echo $this->render_html( false ); } /** * generates html for the dashboard widget * @param bool $scan */ public function render_html( $scan = false ) { ?>

oc_dashboard_mwp_links(); } else { $this->oc_dashboard_non_mwp_links(); } ?>
theme_tooltip; $this->oc_append_buttons( $this->theme_url, $label, '', $title ); } /** * adds the one.com plugins button to the plugins screen */ public function oc_plugins_button() { $label = self::ONECOM . __( 'Plugins', 'onecom-wp' ); $this->oc_append_buttons( $this->plugin_url, $label, '', $this->plugin_tooltip ); } /** * adds the cookie banner button to the widget screen */ public function oc_cookie_banner_button() { $label = __( 'Cookie banner', 'onecom-wp' ); $this->oc_append_buttons( $this->cookie_banner_url, $label, '', $this->cookie_banner_tooltip ); } /** * generates and appends the buttons through jquery * @param $url url link to be plaved on the button * @param $label string label of button * @param string $desc description for general screen under settings * @param string $title tooltip for buttons * @param bool $new if the button is for add new media screen */ public function oc_append_buttons( $url, $label, $desc = '', $title = '', $new = false ) { if ( $desc === '' ) { ?> oc_append_buttons( $this->staging_url, $label, $desc ); } /** * adds the staging box to the tools screen */ public function tools_page_staging_box() { $title = __( 'Staging', 'onecom-wp' ); $desc = __( 'Create a staging version of your site to try out new plugins, themes and customizations', 'onecom-wp' ); $label = __( self::CREATE_STAGING_SITE, 'onecom-wp' ); $this->tools_page_content_render_html( $title, $desc, $label, $this->staging_url ); } /** * adds the health monitor box to the tools screen */ public function tools_page_health_monitor_box() { $title = __( self::HEALTH_MONITOR, 'onecom-wp' ); $desc = __( 'Health Monitor scans your website for potential security issues and checks the overall state of your site.', 'onecom-wp' ); $label = __( self::SCAN_NOW, 'onecom-wp' ); $this->tools_page_content_render_html( $title, $desc, $label, $this->url ); } /** * returns html for the boxes on tools screen */ public function tools_page_content_render_html( $title, $desc, $label, $url ) { echo '

' . $title . '

' . $desc . '

' . $label . '

'; } /** * css for the shortcuts to be added */ public function oc_button_css() { echo ""; } /** * adds the cookie banner box to the privacy screen */ public function oc_cookie_banner_box() { $title = __( 'one.com Cookie Banner', 'onecom-wp' ); $description = addslashes( __( 'Show a banner on your website to inform visitors about cookies and get their consent.', 'onecom-wp' ) ); $label = __( 'Cookie banner', 'onecom-wp' ); ?>