*/ namespace RankMath\Frontend; use RankMath\Post; use RankMath\Helper; use RankMath\Paper\Paper; use RankMath\Traits\Hooker; use RankMath\OpenGraph\Twitter; use RankMath\OpenGraph\Facebook; use RankMath\OpenGraph\Slack; use RankMath\Frontend\Shortcodes; defined( 'ABSPATH' ) || exit; /** * Frontend class. * * @copyright Copyright (C) 2008-2019, Yoast BV * The following code is a derivative work of the code from the Yoast(https://github.com/Yoast/wordpress-seo/), which is licensed under GPL v3. */ class Frontend { use Hooker; /** * The Constructor. */ public function __construct() { if ( \RankMath\Helpers\Param::get( 'et_fb' ) ) { return; } $this->includes(); $this->hooks(); /** * Fires when frontend is included/loaded. */ $this->do_action( 'frontend/loaded' ); } /** * Include required files. */ private function includes() { rank_math()->shortcodes = new Shortcodes(); if ( Helper::is_breadcrumbs_enabled() ) { /** * If RM's breadcrumbs are enabled then we can remove the bbPress breadcrumbs. */ add_filter( 'bbp_get_breadcrumb', '__return_false' ); } new Redirection(); rank_math()->link_attributes = new Link_Attributes(); rank_math()->comments = new Comments(); } /** * Hook into actions and filters. */ private function hooks() { $this->action( 'wp_enqueue_scripts', 'enqueue' ); $this->action( 'wp', 'integrations' ); $this->filter( 'the_content_feed', 'embed_rssfooter' ); $this->filter( 'the_excerpt_rss', 'embed_rssfooter_excerpt' ); // Add support for shortcode in the Category/Term description. add_filter( 'category_description', 'do_shortcode' ); add_filter( 'term_description', 'do_shortcode' ); } /** * Initialize integrations. */ public function integrations() { $type = get_query_var( 'sitemap' ); if ( $this->do_filter( 'frontend/disable_integration', ! empty( $type ) || is_customize_preview() ) ) { return; } Paper::get(); new Facebook(); new Twitter(); new Slack(); // Leave this for backwards compatibility as AMP plugin uses head function. We can remove this in the future update. rank_math()->head = new Head(); if ( function_exists( 'amp_is_dev_mode' ) && amp_is_dev_mode() ) { $this->filter( 'script_loader_tag', 'add_amp_dev_mode_attributes', 10, 2 ); $this->filter( 'amp_dev_mode_element_xpaths', 'add_amp_dev_mode_xpaths' ); } } /** * Enqueue Styles and Scripts */ public function enqueue() { if ( ! is_admin_bar_showing() || ! Helper::has_cap( 'admin_bar' ) ) { return; } wp_enqueue_style( 'rank-math', rank_math()->assets() . 'css/rank-math.css', null, rank_math()->version ); wp_enqueue_script( 'rank-math', rank_math()->assets() . 'js/rank-math.js', [ 'jquery' ], rank_math()->version, true ); if ( is_singular() ) { Helper::add_json( 'objectID', Post::get_page_id() ); Helper::add_json( 'objectType', 'post' ); } elseif ( is_category() || is_tag() || is_tax() ) { Helper::add_json( 'objectID', get_queried_object_id() ); Helper::add_json( 'objectType', 'term' ); } elseif ( is_author() ) { Helper::add_json( 'objectID', get_queried_object_id() ); Helper::add_json( 'objectType', 'user' ); } } /** * Adds the RSS header and footer messages to the RSS feed item content. * * @param string $content Feed item content. * * @return string */ public function embed_rssfooter( $content ) { return $this->embed_rss( $content, 'full' ); } /** * Adds the RSS header and footer messages to the RSS feed item excerpt. * * @param string $content Feed item excerpt. * * @return string */ public function embed_rssfooter_excerpt( $content ) { return $this->embed_rss( $content, 'excerpt' ); } /** * Add data-ampdevmode attribute to enqueued scripts. * * @since 1.0.45 * * @param string $tag The script tag. * @param string $handle The script handle. * * @return string Modified script tag. */ public function add_amp_dev_mode_attributes( $tag, $handle ) { if ( ! in_array( $handle, [ 'rank-math', 'jquery-core', 'jquery-migrate' ], true ) ) { return $tag; } return preg_replace( '/(?<=