getMessage(); } set_transient( 'sxanl_geoip_notice', $result, 60 ); self::redirect_back( 'geoip' ); } /** * Settings-page action: re-poll the Sentrixa update channel now. */ public static function handle_check_update() { if ( ! current_user_can( 'manage_options' ) || ! check_admin_referer( 'sxanl_check_update' ) ) { wp_die( esc_html__( 'Not allowed.', 'sentrixa-analytics' ) ); } if ( ! class_exists( 'SXANL_Updater' ) ) { wp_die( esc_html__( 'Updates for this edition come from WordPress.org.', 'sentrixa-analytics' ) ); } $m = SXANL_Updater::force_check(); $latest = ! empty( $m['version'] ) ? (string) $m['version'] : SXANL_VERSION; set_transient( 'sxanl_update_notice', $latest, 60 ); self::redirect_back( 'update' ); } private static function redirect_back( $done ) { wp_safe_redirect( add_query_arg( array( 'page' => self::MENU_SLUG . '-settings', 'sxa-done' => $done ), admin_url( 'admin.php' ) ) ); exit; } public static function menu() { $cap = 'view_sentrixa_analytics'; add_menu_page( __( 'Analytics', 'sentrixa-analytics' ), __( 'Analytics', 'sentrixa-analytics' ), $cap, self::MENU_SLUG, array( __CLASS__, 'render_dashboard' ), 'dashicons-chart-area', 80 ); add_submenu_page( self::MENU_SLUG, __( 'Dashboard', 'sentrixa-analytics' ), __( 'Dashboard', 'sentrixa-analytics' ), $cap, self::MENU_SLUG, array( __CLASS__, 'render_dashboard' ) ); add_submenu_page( self::MENU_SLUG, __( 'Settings', 'sentrixa-analytics' ), __( 'Settings', 'sentrixa-analytics' ), 'manage_options', self::MENU_SLUG . '-settings', array( __CLASS__, 'render_settings' ) ); } public static function action_links( $links ) { $links[] = '' . esc_html__( 'Dashboard', 'sentrixa-analytics' ) . ''; return $links; } public static function assets( $hook ) { if ( false === strpos( (string) $hook, self::MENU_SLUG ) ) { return; } wp_enqueue_style( 'sentrixa-analytics-admin', SXANL_URL . 'assets/css/admin.css', array(), SXANL_VERSION ); wp_enqueue_script( 'sentrixa-analytics-admin', SXANL_URL . 'assets/js/admin.js', array(), SXANL_VERSION, true ); wp_localize_script( 'sentrixa-analytics-admin', 'SXANL_ADMIN', array( 'root' => esc_url_raw( rest_url( SXANL_REST_NS ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'geojson' => esc_url_raw( rest_url( SXANL_REST_NS . '/geojson' ) ), 'siteName' => get_bloginfo( 'name' ), 'lastRollup' => get_option( 'sxanl_last_rollup', '' ), 'canManage' => current_user_can( 'manage_options' ), 'pro' => SXANL_Edition::is_pro(), 'countryNames' => sxanl_country_names(), ) ); } public static function render_dashboard() { echo '
'; echo '

' . esc_html__( 'Analytics', 'sentrixa-analytics' ) . ' Sentrixa

'; echo '

' . esc_html__( 'Loading…', 'sentrixa-analytics' ) . '

'; echo '
'; } public static function render_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $s = SXANL_Settings::all(); ?>


' ); echo esc_html( SXANL_VERSION ); if ( $sxanl_new ) { /* translators: %s: plugin version number */ printf( ' — %s', esc_html( sprintf( __( 'version %s available', 'sentrixa-analytics' ), $sxanl_m['version'] ) ) ); } else { echo ' — ' . esc_html__( 'up to date', 'sentrixa-analytics' ); } ?>

%s

', esc_html__( 'Summaries rebuilt. The dashboard is up to date.', 'sentrixa-analytics' ) ); } elseif ( 'update' === $done ) { $latest = get_transient( 'sxanl_update_notice' ); delete_transient( 'sxanl_update_notice' ); if ( is_string( $latest ) && version_compare( $latest, SXANL_VERSION, '>' ) ) { printf( '

%s

', sprintf( /* translators: 1: new version, 2: Plugins page URL */ wp_kses_post( __( 'Sentrixa Analytics %1$s is available. Update now.', 'sentrixa-analytics' ) ), esc_html( $latest ), esc_url( self_admin_url( 'plugins.php' ) ) ) ); } else { printf( '

%s

', esc_html__( 'You are running the latest version of Sentrixa Analytics.', 'sentrixa-analytics' ) ); } } elseif ( 'geoip' === $done ) { $msg = get_transient( 'sxanl_geoip_notice' ); delete_transient( 'sxanl_geoip_notice' ); $ok = is_string( $msg ) && 0 === strpos( $msg, 'updated' ); printf( '

%s

', $ok ? 'success' : 'warning', /* translators: %s: result of the country database update */ esc_html( sprintf( __( 'Country database: %s', 'sentrixa-analytics' ), is_string( $msg ) ? $msg : 'no result' ) ) ); } } private static function cron_when( $hook ) { $ts = wp_next_scheduled( $hook ); return $ts ? wp_date( 'Y-m-d H:i', $ts ) : __( 'not scheduled', 'sentrixa-analytics' ); } }