| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- <?php
- namespace Elementor;
- use Elementor\Core\Base\Document;
- use Elementor\Core\Responsive\Files\Frontend as FrontendFile;
- use Elementor\Core\Files\CSS\Global_CSS;
- use Elementor\Core\Files\CSS\Post as Post_CSS;
- use Elementor\Core\Files\CSS\Post_Preview;
- use Elementor\Core\Responsive\Responsive;
- use Elementor\Core\Settings\Manager as SettingsManager;
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- /**
- * Elementor frontend.
- *
- * Elementor frontend handler class is responsible for initializing Elementor in
- * the frontend.
- *
- * @since 1.0.0
- */
- class Frontend {
- /**
- * The priority of the content filter.
- */
- const THE_CONTENT_FILTER_PRIORITY = 9;
- /**
- * Post ID.
- *
- * Holds the ID of the current post.
- *
- * @access private
- *
- * @var int Post ID.
- */
- private $post_id;
- /**
- * Fonts to enqueue
- *
- * Holds the list of fonts that are being used in the current page.
- *
- * @since 1.9.4
- * @access private
- *
- * @var array Used fonts. Default is an empty array.
- */
- private $fonts_to_enqueue = [];
- /**
- * Registered fonts.
- *
- * Holds the list of enqueued fonts in the current page.
- *
- * @since 1.0.0
- * @access private
- *
- * @var array Registered fonts. Default is an empty array.
- */
- private $registered_fonts = [];
- /**
- * Whether the page is using Elementor.
- *
- * Used to determine whether the current page is using Elementor.
- *
- * @since 1.0.0
- * @access private
- *
- * @var bool Whether Elementor is being used. Default is false.
- */
- private $_has_elementor_in_page = false;
- /**
- * Whether the excerpt is being called.
- *
- * Used to determine whether the call to `the_content()` came from `get_the_excerpt()`.
- *
- * @since 1.0.0
- * @access private
- *
- * @var bool Whether the excerpt is being used. Default is false.
- */
- private $_is_excerpt = false;
- /**
- * Filters removed from the content.
- *
- * Hold the list of filters removed from `the_content()`. Used to hold the filters that
- * conflicted with Elementor while Elementor process the content.
- *
- * @since 1.0.0
- * @access private
- *
- * @var array Filters removed from the content. Default is an empty array.
- */
- private $content_removed_filters = [];
- /**
- * @var Document[]
- */
- private $admin_bar_edit_documents = [];
- /**
- * @var string[]
- */
- private $body_classes = [
- 'elementor-default',
- ];
- /**
- * Init.
- *
- * Initialize Elementor front end. Hooks the needed actions to run Elementor
- * in the front end, including script and style registration.
- *
- * Fired by `template_redirect` action.
- *
- * @since 1.0.0
- * @access public
- */
- public function init() {
- if ( Plugin::$instance->editor->is_edit_mode() ) {
- return;
- }
- add_filter( 'body_class', [ $this, 'body_class' ] );
- if ( Plugin::$instance->preview->is_preview_mode() ) {
- return;
- }
- $this->post_id = get_the_ID();
- if ( is_singular() && Plugin::$instance->db->is_built_with_elementor( $this->post_id ) ) {
- add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] );
- }
- // Priority 7 to allow google fonts in header template to load in <head> tag
- add_action( 'wp_head', [ $this, 'print_fonts_links' ], 7 );
- add_action( 'wp_footer', [ $this, 'wp_footer' ] );
- // Add Edit with the Elementor in Admin Bar.
- add_action( 'admin_bar_menu', [ $this, 'add_menu_in_admin_bar' ], 200 );
- }
- /**
- * @param string|array $class
- */
- public function add_body_class( $class ) {
- if ( is_array( $class ) ) {
- $this->body_classes = array_merge( $this->body_classes, $class );
- } else {
- $this->body_classes[] = $class;
- }
- }
- /**
- * Body tag classes.
- *
- * Add new elementor classes to the body tag.
- *
- * Fired by `body_class` filter.
- *
- * @since 1.0.0
- * @access public
- *
- * @param array $classes Optional. One or more classes to add to the body tag class list.
- * Default is an empty array.
- *
- * @return array Body tag classes.
- */
- public function body_class( $classes = [] ) {
- $classes = array_merge( $classes, $this->body_classes );
- $id = get_the_ID();
- if ( is_singular() && Plugin::$instance->db->is_built_with_elementor( $id ) ) {
- $classes[] = 'elementor-page elementor-page-' . $id;
- }
- return $classes;
- }
- /**
- * Add content filter.
- *
- * Remove plain content and render the content generated by Elementor.
- *
- * @since 1.8.0
- * @access public
- */
- public function add_content_filter() {
- add_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
- }
- /**
- * Remove content filter.
- *
- * When the Elementor generated content rendered, we remove the filter to prevent multiple
- * accuracies. This way we make sure Elementor renders the content only once.
- *
- * @since 1.8.0
- * @access public
- */
- public function remove_content_filter() {
- remove_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
- }
- /**
- * Registers scripts.
- *
- * Registers all the frontend scripts.
- *
- * Fired by `wp_enqueue_scripts` action.
- *
- * @since 1.2.1
- * @access public
- */
- public function register_scripts() {
- /**
- * Before frontend register scripts.
- *
- * Fires before Elementor frontend scripts are registered.
- *
- * @since 1.2.1
- */
- do_action( 'elementor/frontend/before_register_scripts' );
- $suffix = Utils::is_script_debug() ? '' : '.min';
- wp_register_script(
- 'elementor-waypoints',
- ELEMENTOR_ASSETS_URL . 'lib/waypoints/waypoints' . $suffix . '.js',
- [
- 'jquery',
- ],
- '4.0.2',
- true
- );
- wp_register_script(
- 'flatpickr',
- ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.js',
- [
- 'jquery',
- ],
- '4.1.4',
- true
- );
- wp_register_script(
- 'imagesloaded',
- ELEMENTOR_ASSETS_URL . 'lib/imagesloaded/imagesloaded' . $suffix . '.js',
- [
- 'jquery',
- ],
- '4.1.0',
- true
- );
- wp_register_script(
- 'jquery-numerator',
- ELEMENTOR_ASSETS_URL . 'lib/jquery-numerator/jquery-numerator' . $suffix . '.js',
- [
- 'jquery',
- ],
- '0.2.1',
- true
- );
- wp_register_script(
- 'jquery-swiper',
- ELEMENTOR_ASSETS_URL . 'lib/swiper/swiper.jquery' . $suffix . '.js',
- [
- 'jquery',
- ],
- '4.4.3',
- true
- );
- wp_register_script(
- 'jquery-slick',
- ELEMENTOR_ASSETS_URL . 'lib/slick/slick' . $suffix . '.js',
- [
- 'jquery',
- ],
- '1.8.1',
- true
- );
- wp_register_script(
- 'elementor-dialog',
- ELEMENTOR_ASSETS_URL . 'lib/dialog/dialog' . $suffix . '.js',
- [
- 'jquery-ui-position',
- ],
- '4.5.0',
- true
- );
- wp_register_script(
- 'elementor-frontend',
- ELEMENTOR_ASSETS_URL . 'js/frontend' . $suffix . '.js',
- [
- 'elementor-dialog',
- 'elementor-waypoints',
- 'jquery-swiper',
- ],
- ELEMENTOR_VERSION,
- true
- );
- /**
- * After frontend register scripts.
- *
- * Fires after Elementor frontend scripts are registered.
- *
- * @since 1.2.1
- */
- do_action( 'elementor/frontend/after_register_scripts' );
- }
- /**
- * Registers styles.
- *
- * Registers all the frontend styles.
- *
- * Fired by `wp_enqueue_scripts` action.
- *
- * @since 1.2.0
- * @access public
- */
- public function register_styles() {
- /**
- * Before frontend register styles.
- *
- * Fires before Elementor frontend styles are registered.
- *
- * @since 1.2.0
- */
- do_action( 'elementor/frontend/before_register_styles' );
- $suffix = Utils::is_script_debug() ? '' : '.min';
- $direction_suffix = is_rtl() ? '-rtl' : '';
- wp_register_style(
- 'elementor-icons',
- ELEMENTOR_ASSETS_URL . 'lib/eicons/css/elementor-icons' . $suffix . '.css',
- [],
- '3.8.0'
- );
- wp_register_style(
- 'font-awesome',
- ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome' . $suffix . '.css',
- [],
- '4.7.0'
- );
- wp_register_style(
- 'elementor-animations',
- ELEMENTOR_ASSETS_URL . 'lib/animations/animations.min.css',
- [],
- ELEMENTOR_VERSION
- );
- wp_register_style(
- 'flatpickr',
- ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.css',
- [],
- '4.1.4'
- );
- $frontend_file_name = 'frontend' . $direction_suffix . $suffix . '.css';
- $has_custom_file = Responsive::has_custom_breakpoints();
- if ( $has_custom_file ) {
- $frontend_file = new FrontendFile( 'custom-' . $frontend_file_name, Responsive::get_stylesheet_templates_path() . $frontend_file_name );
- $time = $frontend_file->get_meta( 'time' );
- if ( ! $time ) {
- $frontend_file->update();
- }
- $frontend_file_url = $frontend_file->get_url();
- } else {
- $frontend_file_url = ELEMENTOR_ASSETS_URL . 'css/' . $frontend_file_name;
- }
- wp_register_style(
- 'elementor-frontend',
- $frontend_file_url,
- [],
- $has_custom_file ? null : ELEMENTOR_VERSION
- );
- /**
- * After frontend register styles.
- *
- * Fires after Elementor frontend styles are registered.
- *
- * @since 1.2.0
- */
- do_action( 'elementor/frontend/after_register_styles' );
- }
- /**
- * Enqueue scripts.
- *
- * Enqueue all the frontend scripts.
- *
- * @since 1.0.0
- * @access public
- */
- public function enqueue_scripts() {
- /**
- * Before frontend enqueue scripts.
- *
- * Fires before Elementor frontend scripts are enqueued.
- *
- * @since 1.0.0
- */
- do_action( 'elementor/frontend/before_enqueue_scripts' );
- wp_enqueue_script( 'elementor-frontend' );
- $is_preview_mode = Plugin::$instance->preview->is_preview_mode( Plugin::$instance->preview->get_post_id() );
- $elementor_frontend_config = [
- 'isEditMode' => $is_preview_mode,
- 'is_rtl' => is_rtl(),
- 'breakpoints' => Responsive::get_breakpoints(),
- 'version' => ELEMENTOR_VERSION,
- 'urls' => [
- 'assets' => ELEMENTOR_ASSETS_URL,
- ],
- ];
- $elementor_frontend_config['settings'] = SettingsManager::get_settings_frontend_config();
- if ( is_singular() ) {
- $post = get_post();
- $elementor_frontend_config['post'] = [
- 'id' => $post->ID,
- 'title' => $post->post_title,
- 'excerpt' => $post->post_excerpt,
- ];
- } else {
- $elementor_frontend_config['post'] = [
- 'id' => 0,
- 'title' => wp_get_document_title(),
- 'excerpt' => '',
- ];
- }
- if ( $is_preview_mode ) {
- $elements_manager = Plugin::$instance->elements_manager;
- $elements_frontend_keys = [
- 'section' => $elements_manager->get_element_types( 'section' )->get_frontend_settings_keys(),
- 'column' => $elements_manager->get_element_types( 'column' )->get_frontend_settings_keys(),
- ];
- $elements_frontend_keys += Plugin::$instance->widgets_manager->get_widgets_frontend_settings_keys();
- $elementor_frontend_config['elements'] = [
- 'data' => (object) [],
- 'editSettings' => (object) [],
- 'keys' => $elements_frontend_keys,
- ];
- }
- wp_localize_script( 'elementor-frontend', 'elementorFrontendConfig', $elementor_frontend_config );
- /**
- * After frontend enqueue scripts.
- *
- * Fires after Elementor frontend scripts are enqueued.
- *
- * @since 1.0.0
- */
- do_action( 'elementor/frontend/after_enqueue_scripts' );
- }
- /**
- * Enqueue styles.
- *
- * Enqueue all the frontend styles.
- *
- * Fired by `wp_enqueue_scripts` action.
- *
- * @since 1.0.0
- * @access public
- */
- public function enqueue_styles() {
- /**
- * Before frontend styles enqueued.
- *
- * Fires before Elementor frontend styles are enqueued.
- *
- * @since 1.0.0
- */
- do_action( 'elementor/frontend/before_enqueue_styles' );
- wp_enqueue_style( 'elementor-icons' );
- wp_enqueue_style( 'font-awesome' );
- wp_enqueue_style( 'elementor-animations' );
- wp_enqueue_style( 'elementor-frontend' );
- /**
- * After frontend styles enqueued.
- *
- * Fires after Elementor frontend styles are enqueued.
- *
- * @since 1.0.0
- */
- do_action( 'elementor/frontend/after_enqueue_styles' );
- if ( ! Plugin::$instance->preview->is_preview_mode() ) {
- $this->parse_global_css_code();
- $css_file = new Post_CSS( get_the_ID() );
- $css_file->enqueue();
- }
- }
- /**
- * Elementor footer scripts and styles.
- *
- * Handle styles and scripts that are not printed in the header.
- *
- * Fired by `wp_footer` action.
- *
- * @since 1.0.11
- * @access public
- */
- public function wp_footer() {
- if ( ! $this->_has_elementor_in_page ) {
- return;
- }
- $this->enqueue_styles();
- $this->enqueue_scripts();
- $this->print_fonts_links();
- }
- /**
- * Print fonts links.
- *
- * Enqueue all the frontend fonts by url.
- *
- * Fired by `wp_head` action.
- *
- * @since 1.9.4
- * @access public
- */
- public function print_fonts_links() {
- $google_fonts = [
- 'google' => [],
- 'early' => [],
- ];
- foreach ( $this->fonts_to_enqueue as $key => $font ) {
- $font_type = Fonts::get_font_type( $font );
- switch ( $font_type ) {
- case Fonts::GOOGLE:
- $google_fonts['google'][] = $font;
- break;
- case Fonts::EARLYACCESS:
- $google_fonts['early'][] = $font;
- break;
- default:
- /**
- * Print font links.
- *
- * Fires when Elementor frontend fonts are printed on the HEAD tag.
- *
- * The dynamic portion of the hook name, `$font_type`, refers to the font type.
- *
- * @since 2.0.0
- *
- * @param string $font Font name.
- */
- do_action( "elementor/fonts/print_font_links/{$font_type}", $font );
- }
- }
- $this->fonts_to_enqueue = [];
- $this->enqueue_google_fonts( $google_fonts );
- }
- /**
- * Print Google fonts.
- *
- * Enqueue all the frontend Google fonts.
- *
- * Fired by `wp_head` action.
- *
- * @since 1.0.0
- * @access private
- *
- * @param array $google_fonts Optional. Google fonts to print in the frontend.
- * Default is an empty array.
- */
- private function enqueue_google_fonts( $google_fonts = [] ) {
- static $google_fonts_index = 0;
- $print_google_fonts = true;
- /**
- * Print frontend google fonts.
- *
- * Filters whether to enqueue Google fonts in the frontend.
- *
- * @since 1.0.0
- *
- * @param bool $print_google_fonts Whether to enqueue Google fonts. Default is true.
- */
- $print_google_fonts = apply_filters( 'elementor/frontend/print_google_fonts', $print_google_fonts );
- if ( ! $print_google_fonts ) {
- return;
- }
- // Print used fonts
- if ( ! empty( $google_fonts['google'] ) ) {
- $google_fonts_index++;
- foreach ( $google_fonts['google'] as &$font ) {
- $font = str_replace( ' ', '+', $font ) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic';
- }
- $fonts_url = sprintf( 'https://fonts.googleapis.com/css?family=%s', implode( rawurlencode( '|' ), $google_fonts['google'] ) );
- $subsets = [
- 'ru_RU' => 'cyrillic',
- 'bg_BG' => 'cyrillic',
- 'he_IL' => 'hebrew',
- 'el' => 'greek',
- 'vi' => 'vietnamese',
- 'uk' => 'cyrillic',
- 'cs_CZ' => 'latin-ext',
- 'ro_RO' => 'latin-ext',
- 'pl_PL' => 'latin-ext',
- ];
- $locale = get_locale();
- if ( isset( $subsets[ $locale ] ) ) {
- $fonts_url .= '&subset=' . $subsets[ $locale ];
- }
- wp_enqueue_style( 'google-fonts-' . $google_fonts_index, $fonts_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
- }
- if ( ! empty( $google_fonts['early'] ) ) {
- foreach ( $google_fonts['early'] as $current_font ) {
- $google_fonts_index++;
- //printf( '<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/earlyaccess/%s.css">', strtolower( str_replace( ' ', '', $current_font ) ) );
- $font_url = sprintf( 'https://fonts.googleapis.com/earlyaccess/%s.css', strtolower( str_replace( ' ', '', $current_font ) ) );
- wp_enqueue_style( 'google-earlyaccess-' . $google_fonts_index, $font_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
- }
- }
- }
- /**
- * Enqueue fonts.
- *
- * Enqueue all the frontend fonts.
- *
- * @since 1.2.0
- * @access public
- *
- * @param array $font Fonts to enqueue in the frontend.
- */
- public function enqueue_font( $font ) {
- if ( in_array( $font, $this->registered_fonts ) ) {
- return;
- }
- $this->fonts_to_enqueue[] = $font;
- $this->registered_fonts[] = $font;
- }
- /**
- * Parse global CSS.
- *
- * Enqueue the global CSS file.
- *
- * @since 1.2.0
- * @access protected
- */
- protected function parse_global_css_code() {
- $scheme_css_file = new Global_CSS( 'global.css' );
- $scheme_css_file->enqueue();
- }
- /**
- * Apply builder in content.
- *
- * Used to apply the Elementor page editor on the post content.
- *
- * @since 1.0.0
- * @access public
- *
- * @param string $content The post content.
- *
- * @return string The post content.
- */
- public function apply_builder_in_content( $content ) {
- $this->restore_content_filters();
- if ( Plugin::$instance->preview->is_preview_mode() || $this->_is_excerpt ) {
- return $content;
- }
- // Remove the filter itself in order to allow other `the_content` in the elements
- $this->remove_content_filter();
- $post_id = get_the_ID();
- $builder_content = $this->get_builder_content( $post_id );
- if ( ! empty( $builder_content ) ) {
- $content = $builder_content;
- $this->remove_content_filters();
- }
- // Add the filter again for other `the_content` calls
- $this->add_content_filter();
- return $content;
- }
- /**
- * Retrieve builder content.
- *
- * Used to render and return the post content with all the Elementor elements.
- *
- * Note that this method is an internal method, please use `get_builder_content_for_display()`.
- *
- * @since 1.0.0
- * @access public
- *
- * @param int $post_id The post ID.
- * @param bool $with_css Optional. Whether to retrieve the content with CSS
- * or not. Default is false.
- *
- * @return string The post content.
- */
- public function get_builder_content( $post_id, $with_css = false ) {
- if ( post_password_required( $post_id ) ) {
- return '';
- }
- if ( ! Plugin::$instance->db->is_built_with_elementor( $post_id ) ) {
- return '';
- }
- $document = Plugin::$instance->documents->get_doc_for_frontend( $post_id );
- // Change the current post, so widgets can use `documents->get_current`.
- Plugin::$instance->documents->switch_to_document( $document );
- if ( $document->is_editable_by_current_user() ) {
- $this->admin_bar_edit_documents[ $document->get_main_id() ] = $document;
- }
- $data = $document->get_elements_data();
- /**
- * Frontend builder content data.
- *
- * Filters the builder content in the frontend.
- *
- * @since 1.0.0
- *
- * @param array $data The builder content.
- * @param int $post_id The post ID.
- */
- $data = apply_filters( 'elementor/frontend/builder_content_data', $data, $post_id );
- if ( empty( $data ) ) {
- return '';
- }
- if ( ! $this->_is_excerpt ) {
- if ( $document->is_autosave() ) {
- $css_file = new Post_Preview( $document->get_post()->ID );
- } else {
- $css_file = new Post_CSS( $post_id );
- }
- $css_file->enqueue();
- }
- ob_start();
- // Handle JS and Customizer requests, with CSS inline.
- if ( is_customize_preview() || Utils::is_ajax() ) {
- $with_css = true;
- }
- if ( ! empty( $css_file ) && $with_css ) {
- $css_file->print_css();
- }
- $document->print_elements_with_wrapper( $data );
- $content = ob_get_clean();
- /**
- * Frontend content.
- *
- * Filters the content in the frontend.
- *
- * @since 1.0.0
- *
- * @param string $content The content.
- */
- $content = apply_filters( 'elementor/frontend/the_content', $content );
- if ( ! empty( $content ) ) {
- $this->_has_elementor_in_page = true;
- }
- Plugin::$instance->documents->restore_document();
- return $content;
- }
- /**
- * Add Elementor menu to admin bar.
- *
- * Add new admin bar item only on singular pages, to display a link that
- * allows the user to edit with Elementor.
- *
- * Fired by `admin_bar_menu` action.
- *
- * @since 1.3.4
- * @access public
- *
- * @param \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference.
- */
- public function add_menu_in_admin_bar( \WP_Admin_Bar $wp_admin_bar ) {
- if ( empty( $this->admin_bar_edit_documents ) ) {
- return;
- }
- $queried_object_id = get_queried_object_id();
- $menu_args = [
- 'id' => 'elementor_edit_page',
- 'title' => __( 'Edit with Elementor', 'elementor' ),
- ];
- if ( is_singular() && isset( $this->admin_bar_edit_documents[ $queried_object_id ] ) ) {
- $menu_args['href'] = $this->admin_bar_edit_documents[ $queried_object_id ]->get_edit_url();
- unset( $this->admin_bar_edit_documents[ $queried_object_id ] );
- }
- $wp_admin_bar->add_node( $menu_args );
- foreach ( $this->admin_bar_edit_documents as $document ) {
- $wp_admin_bar->add_menu( [
- 'id' => 'elementor_edit_doc_' . $document->get_main_id(),
- 'parent' => 'elementor_edit_page',
- 'title' => sprintf( '<span class="elementor-edit-link-title">%s</span><span class="elementor-edit-link-type">%s</span>', $document->get_post()->post_title, $document::get_title() ),
- 'href' => $document->get_edit_url(),
- ] );
- }
- }
- /**
- * Retrieve builder content for display.
- *
- * Used to render and return the post content with all the Elementor elements.
- *
- * @since 1.0.0
- * @access public
- *
- * @param int $post_id The post ID.
- *
- * @param bool $with_css Optional. Whether to retrieve the content with CSS
- * or not. Default is false.
- *
- * @return string The post content.
- */
- public function get_builder_content_for_display( $post_id, $with_css = false ) {
- if ( ! get_post( $post_id ) ) {
- return '';
- }
- $editor = Plugin::$instance->editor;
- // Avoid recursion
- if ( get_the_ID() === (int) $post_id ) {
- $content = '';
- if ( $editor->is_edit_mode() ) {
- $content = '<div class="elementor-alert elementor-alert-danger">' . __( 'Invalid Data: The Template ID cannot be the same as the currently edited template. Please choose a different one.', 'elementor' ) . '</div>';
- }
- return $content;
- }
- // Set edit mode as false, so don't render settings and etc. use the $is_edit_mode to indicate if we need the CSS inline
- $is_edit_mode = $editor->is_edit_mode();
- $editor->set_edit_mode( false );
- $with_css = $with_css ? true : $is_edit_mode;
- $content = $this->get_builder_content( $post_id, $with_css );
- // Restore edit mode state
- Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
- return $content;
- }
- /**
- * Start excerpt flag.
- *
- * Flags when `the_excerpt` is called. Used to avoid enqueueing CSS in the excerpt.
- *
- * @since 1.4.3
- * @access public
- *
- * @param string $excerpt The post excerpt.
- *
- * @return string The post excerpt.
- */
- public function start_excerpt_flag( $excerpt ) {
- $this->_is_excerpt = true;
- return $excerpt;
- }
- /**
- * End excerpt flag.
- *
- * Flags when `the_excerpt` call ended.
- *
- * @since 1.4.3
- * @access public
- *
- * @param string $excerpt The post excerpt.
- *
- * @return string The post excerpt.
- */
- public function end_excerpt_flag( $excerpt ) {
- $this->_is_excerpt = false;
- return $excerpt;
- }
- /**
- * Remove content filters.
- *
- * Remove WordPress default filters that conflicted with Elementor.
- *
- * @since 1.5.0
- * @access public
- */
- public function remove_content_filters() {
- $filters = [
- 'wpautop',
- 'shortcode_unautop',
- 'wptexturize',
- ];
- foreach ( $filters as $filter ) {
- // Check if another plugin/theme do not already removed the filter.
- if ( has_filter( 'the_content', $filter ) ) {
- remove_filter( 'the_content', $filter );
- $this->content_removed_filters[] = $filter;
- }
- }
- }
- /**
- * Restore content filters.
- *
- * Restore removed WordPress filters that conflicted with Elementor.
- *
- * @since 1.5.0
- * @access private
- */
- private function restore_content_filters() {
- foreach ( $this->content_removed_filters as $filter ) {
- add_filter( 'the_content', $filter );
- }
- $this->content_removed_filters = [];
- }
- public function has_elementor_in_page() {
- return $this->_has_elementor_in_page;
- }
- /**
- * Front End constructor.
- *
- * Initializing Elementor front end. Make sure we are not in admin, not and
- * redirect from old URL structure of Elementor editor.
- *
- * @since 1.0.0
- * @access public
- */
- public function __construct() {
- // We don't need this class in admin side, but in AJAX requests.
- if ( is_admin() && ! Utils::is_ajax() ) {
- return;
- }
- add_action( 'template_redirect', [ $this, 'init' ] );
- add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ], 5 );
- add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ], 5 );
- $this->add_content_filter();
- // Hack to avoid enqueue post CSS while it's a `the_excerpt` call.
- add_filter( 'get_the_excerpt', [ $this, 'start_excerpt_flag' ], 1 );
- add_filter( 'get_the_excerpt', [ $this, 'end_excerpt_flag' ], 20 );
- }
- }
|