ID, $pages, true ) || has_shortcode( (string) $post->post_content, 'returnkit_portal' ) || has_shortcode( (string) $post->post_content, 'returnkit_withdrawal' ) ); } /** * The forms carry nonces and signed tokens: keep these pages out of page * caches, with headers sent before any output. * * @return void */ public static function maybe_no_cache() { if ( self::is_form_page() ) { Access::no_cache(); } } /** * Load early (in the head) on pages known to need the assets, so they * don't arrive late from inside a shortcode. * * @return void */ public static function maybe_enqueue() { if ( // My Account only on the tabs that show ReturnKit (not the login form). ( function_exists( 'is_account_page' ) && is_account_page() && is_user_logged_in() && self::on_account_tab() ) || ( function_exists( 'is_order_received_page' ) && is_order_received_page() ) || self::is_form_page() ) { self::enqueue(); } } /** * Is the current My Account tab one where ReturnKit shows something? * * @return bool */ private static function on_account_tab() { foreach ( array( Account::endpoint_key(), 'orders', 'view-order' ) as $tab ) { if ( is_wc_endpoint_url( $tab ) ) { return true; } } return false; } /** * Enqueue (safe to call several times, also from inside a shortcode). * * @return void */ public static function enqueue() { if ( wp_style_is( 'rtkt-portal', 'enqueued' ) ) { return; } $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; $css = 'assets/css/portal' . $min . '.css'; $js = 'assets/js/portal' . $min . '.js'; wp_enqueue_style( 'rtkt-portal', RTKT_URL . $css, array(), rtkt_asset_version( $css ) ); // A few KB: WordPress prints it inline in instead of as a // render-blocking request (wp_maybe_inline_styles, 20 KB budget). wp_style_add_data( 'rtkt-portal', 'path', RTKT_DIR . $css ); wp_enqueue_script( 'rtkt-portal', RTKT_URL . $js, array(), rtkt_asset_version( $js ), array( 'in_footer' => true, 'strategy' => 'defer' ) ); // One line in the head: mark the page as having JavaScript before it // paints, so fields that start collapsed never shift the layout. wp_register_script( 'rtkt-portal-head', false, array(), RTKT_VERSION, false ); wp_enqueue_script( 'rtkt-portal-head' ); wp_add_inline_script( 'rtkt-portal-head', "document.documentElement.classList.add('rtkt-js');" ); /** * Fires when the portal assets load (Pro adds its exchange picker). */ do_action( 'rtkt_portal_assets' ); } }