is_bot() ) { return; } $options = new \AjaxPress\Options(); $settings = $options->get_settings( true ); // Skip SPA for logged-in admins if setting is enabled. if ( ! empty( $settings['disable_for_admins'] ) && current_user_can( 'manage_options' ) ) { return; } // Enqueue CSS. wp_enqueue_style( 'ajaxpress', AJAXPRESS_URL . 'public/css/ajaxpress.min.css', array(), AJAXPRESS_VERSION ); // Inline CSS. $inline_css = $this->get_inline_css(); wp_add_inline_style( 'ajaxpress', $inline_css ); // Enqueue JS in footer. wp_enqueue_script( 'ajaxpress', AJAXPRESS_URL . 'public/js/ajaxpress.min.js', array(), AJAXPRESS_VERSION, true ); // Inline script. $inline_script = $this->get_inline_script(); wp_localize_script( 'ajaxpress', 'ajaxpress_vars', $inline_script ); } /** * Get Inline Script. * * @return array */ public function get_inline_script() { $options = new \AjaxPress\Options(); $license = get_option( 'ajaxpress_license', [] ); $settings = $options->get_settings( true ); // The frontend only ever needs a validity flag. The full license // record (key, plan, activation counts) stays admin-side: anyone // can read frontend page source, and a leaked key can consume the // customer's activation seats. $is_license_active = ! empty( $license['key'] ) && 'active' === ( isset( $license['status'] ) ? $license['status'] : '' ); $script = array( 'rest' => array( 'url' => rest_url('ajaxpress'), 'nonce' => wp_create_nonce('wp_rest'), ), 'site' => array( 'url' => get_site_url(), 'name' => get_bloginfo('name'), 'language' => get_bloginfo('language'), ), 'plugin' => array( 'url' => plugin_dir_url(AJAXPRESS), 'version' => AJAXPRESS_VERSION, ), 'settings' => $settings, 'navigation' => apply_filters( 'ajaxpress_navigation', true ), 'user_logged_in' => is_user_logged_in(), 'license' => array( 'valid' => $is_license_active, ), 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, ); return $script; } /** * Get Inline CSS. * * @return string */ public function get_inline_css() { $settings = Options::get_instance()->get_settings( true ); $cursor_mode = isset( $settings['cursor_mode'] ) ? $settings['cursor_mode'] : 'auto'; $animation_duration = floatval( isset( $settings['content_animation_duration'] ) ? $settings['content_animation_duration'] : 0.3 ); $css = wp_sprintf( ' :root { --ajaxpress-cursor-mode: %s; --ajaxpress-animation-duration: %ss; }', $cursor_mode, $animation_duration ); // Content animations. $css .= ' .ajaxpress-animate-fade { animation: ajaxpress-fade var(--ajaxpress-animation-duration) ease-in; } .ajaxpress-animate-slide-up { animation: ajaxpress-slide-up var(--ajaxpress-animation-duration) ease-out; } .ajaxpress-animate-slide-down { animation: ajaxpress-slide-down var(--ajaxpress-animation-duration) ease-out; } @keyframes ajaxpress-fade { from { opacity: 0; } to { opacity: 1; } } @keyframes ajaxpress-slide-up { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } @keyframes ajaxpress-slide-down { from { transform: translateY(-30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } .ajaxpress-animate-cursor { cursor: var(--ajaxpress-cursor-mode) !important; } .ajaxpress-animate-cursor * { cursor: var(--ajaxpress-cursor-mode) !important; } '; return apply_filters( 'ajaxpress_inline_css', $css ); } /** * Check if current request is from a bot/crawler. * * @return bool */ private function is_bot() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ); $bots = array( 'googlebot', 'bingbot', 'slurp', 'duckduckbot', 'baiduspider', 'yandexbot', 'facebookexternalhit', 'linkedinbot', 'twitterbot', 'applebot', 'semrushbot', 'ahrefsbot', 'mj12bot', 'dotbot', 'petalbot', 'bytespider', ); foreach ( $bots as $bot ) { if ( strpos( $ua, $bot ) !== false ) { return true; } } return false; } } // Start. Enqueues::start(); }