Stable google fonts ($google_fonts['google']).
* @return string
*/
public function get_stable_google_fonts_url( array $fonts ): string {
foreach ( $fonts as &$font ) {
$font = str_replace( ' ', '+', $font ) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic';
}
// Defining a font-display type to google fonts.
$font_display_url_str = '&display=' . Fonts::get_font_display_setting();
$fonts_url = sprintf( 'https://fonts.googleapis.com/css?family=%1$s%2$s', implode( rawurlencode( '|' ), $fonts ), $font_display_url_str );
$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',
'hr_HR' => 'latin-ext',
'hu_HU' => 'latin-ext',
'sk_SK' => 'latin-ext',
'tr_TR' => 'latin-ext',
'lt_LT' => 'latin-ext',
];
/**
* Google font subsets.
*
* Filters the list of Google font subsets from which locale will be enqueued in frontend.
*
* @since 1.0.0
*
* @param array $subsets A list of font subsets.
*/
$subsets = apply_filters( 'elementor/frontend/google_font_subsets', $subsets );
$locale = get_locale();
if ( isset( $subsets[ $locale ] ) ) {
$fonts_url .= '&subset=' . $subsets[ $locale ];
}
return $fonts_url;
}
/**
* @param array $fonts Early Access google fonts ($google_fonts['early']).
* @return array
*/
public function get_early_access_google_font_urls( array $fonts ): array {
$font_urls = [];
foreach ( $fonts as $font ) {
$font_urls[] = sprintf( 'https://fonts.googleapis.com/earlyaccess/%s.css', strtolower( str_replace( ' ', '', $font ) ) );
}
return $font_urls;
}
/**
* 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 = [] ) {
$print_google_fonts = Fonts::is_google_fonts_enabled();
/**
* 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'] ) ) {
$this->google_fonts_index++;
$fonts_url = $this->get_stable_google_fonts_url( $google_fonts['google'] );
wp_enqueue_style( 'google-fonts-' . $this->google_fonts_index, $fonts_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
}
if ( ! empty( $google_fonts['early'] ) ) {
$early_access_font_urls = $this->get_early_access_google_font_urls( $google_fonts['early'] );
foreach ( $early_access_font_urls as $ea_font_url ) {
$this->google_fonts_index++;
//printf( '', strtolower( str_replace( ' ', '', $current_font ) ) );
wp_enqueue_style( 'google-earlyaccess-' . $this->google_fonts_index, $ea_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 = Global_CSS::create( '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 '';
}
$document = Plugin::$instance->documents->get_doc_for_frontend( $post_id );
if ( ! $document || ! $document->is_built_with_elementor() ) {
return '';
}
// Change the current post, so widgets can use `documents->get_current`.
Plugin::$instance->documents->switch_to_document( $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 );
do_action( 'elementor/frontend/before_get_builder_content', $document, $this->_is_excerpt );
if ( empty( $data ) ) {
Plugin::$instance->documents->restore_document();
return '';
}
if ( ! $this->_is_excerpt ) {
if ( $document->is_autosave() ) {
$css_file = Post_Preview::create( $document->get_post()->ID );
} else {
$css_file = Post_CSS::create( $post_id );
}
/**
* Builder Content - Before Enqueue CSS File
*
* Allows intervening with a document's CSS file before it is enqueued.
*
* @param $css_file Post_CSS|Post_Preview
*/
$css_file = apply_filters( 'elementor/frontend/builder_content/before_enqueue_css_file', $css_file );
$css_file->enqueue();
}
ob_start();
// Handle JS and Customizer requests, with CSS inline.
if ( is_customize_preview() || wp_doing_ajax() ) {
$with_css = true;
}
/**
* Builder Content - With CSS
*
* Allows overriding the `$with_css` parameter which is a factor in determining whether to print the document's
* CSS and font links inline in a `style` tag above the document's markup.
*
* @param $with_css boolean
*/
$with_css = apply_filters( 'elementor/frontend/builder_content/before_print_css', $with_css );
if ( ! empty( $css_file ) && $with_css ) {
$css_file->print_css();
}
$document->print_elements_with_wrapper( $data );
$content = ob_get_clean();
$content = $this->process_more_tag( $content );
/**
* 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();
// BC
// TODO: use Deprecation::do_deprecated_action() in 3.1.0
do_action( 'elementor/frontend/get_builder_content', $document, $this->_is_excerpt, $with_css );
return $content;
}
/**
* 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 = '
' . esc_html__( 'Invalid Data: The Template ID cannot be the same as the currently edited template. Please choose a different one.', 'elementor' ) . '
';
}
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;
}
}
}
/**
* Has Elementor In Page
*
* Determine whether the current page is using Elementor.
*
* @since 2.0.9
*
* @access public
* @return bool
*/
public function has_elementor_in_page() {
return $this->_has_elementor_in_page;
}
public function create_action_hash( $action, array $settings = [] ) {
return '#' . rawurlencode( sprintf( 'elementor-action:action=%1$s&settings=%2$s', $action, base64_encode( wp_json_encode( $settings ) ) ) );
}
/**
* Is the current render mode is static.
*
* @return bool
*/
public function is_static_render_mode() {
// The render mode manager is exists only in frontend,
// so by default if it is not exist the method will return false.
if ( ! $this->render_mode_manager ) {
return false;
}
return $this->render_mode_manager->get_current()->is_static();
}
/**
* Get Init Settings
*
* Used to define the default/initial settings of the object. Inheriting classes may implement this method to define
* their own default/initial settings.
*
* @since 2.3.0
*
* @access protected
* @return array
*/
protected function get_init_settings() {
$is_preview_mode = Plugin::$instance->preview->is_preview_mode( Plugin::$instance->preview->get_post_id() );
$active_experimental_features = Plugin::$instance->experiments->get_active_features();
$active_experimental_features = array_fill_keys( array_keys( $active_experimental_features ), true );
$assets_url = ELEMENTOR_ASSETS_URL;
/**
* Frontend assets URL
*
* Filters Elementor frontend assets URL.
*
* @since 2.3.0
*
* @param string $assets_url The frontend assets URL. Default is ELEMENTOR_ASSETS_URL.
*/
$assets_url = apply_filters( 'elementor/frontend/assets_url', $assets_url );
$settings = [
'environmentMode' => [
'edit' => $is_preview_mode,
'wpPreview' => is_preview(),
'isScriptDebug' => Utils::is_script_debug(),
],
'i18n' => [
'shareOnFacebook' => esc_html__( 'Share on Facebook', 'elementor' ),
'shareOnTwitter' => esc_html__( 'Share on Twitter', 'elementor' ),
'pinIt' => esc_html__( 'Pin it', 'elementor' ),
'download' => esc_html__( 'Download', 'elementor' ),
'downloadImage' => esc_html__( 'Download image', 'elementor' ),
'fullscreen' => esc_html__( 'Fullscreen', 'elementor' ),
'zoom' => esc_html__( 'Zoom', 'elementor' ),
'share' => esc_html__( 'Share', 'elementor' ),
'playVideo' => esc_html__( 'Play Video', 'elementor' ),
'previous' => esc_html__( 'Previous', 'elementor' ),
'next' => esc_html__( 'Next', 'elementor' ),
'close' => esc_html__( 'Close', 'elementor' ),
'a11yCarouselWrapperAriaLabel' => __( 'Carousel | Horizontal scrolling: Arrow Left & Right', 'elementor' ),
'a11yCarouselPrevSlideMessage' => __( 'Previous slide', 'elementor' ),
'a11yCarouselNextSlideMessage' => __( 'Next slide', 'elementor' ),
'a11yCarouselFirstSlideMessage' => __( 'This is the first slide', 'elementor' ),
'a11yCarouselLastSlideMessage' => __( 'This is the last slide', 'elementor' ),
'a11yCarouselPaginationBulletMessage' => __( 'Go to slide', 'elementor' ),
],
'is_rtl' => is_rtl(),
// 'breakpoints' object is kept for BC.
'breakpoints' => Responsive::get_breakpoints(),
// 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0
'responsive' => [
'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
],
'version' => ELEMENTOR_VERSION,
'is_static' => $this->is_static_render_mode(),
'experimentalFeatures' => $active_experimental_features,
'urls' => [
'assets' => $assets_url,
],
'swiperClass' => Plugin::$instance->experiments->is_feature_active( 'e_swiper_latest' ) ? 'swiper' : 'swiper-container',
];
$settings['settings'] = SettingsManager::get_settings_frontend_config();
$kit = Plugin::$instance->kits_manager->get_active_kit_for_frontend();
$settings['kit'] = $kit->get_frontend_settings();
if ( is_singular() ) {
$post = get_post();
$title = Utils::urlencode_html_entities( wp_get_document_title() );
// Try to use the 'large' WP image size because the Pinterest share API
// has problems accepting shares with large images sometimes, and the WP 'large' thumbnail is
// the largest default WP image size that will probably not be changed in most sites
$featured_image_url = get_the_post_thumbnail_url( null, 'large' );
// If the large size was nullified, use the full size which cannot be nullified/deleted
if ( ! $featured_image_url ) {
$featured_image_url = get_the_post_thumbnail_url( null, 'full' );
}
$settings['post'] = [
'id' => $post->ID,
'title' => $title,
'excerpt' => $post->post_excerpt,
'featuredImage' => $featured_image_url,
];
} else {
$settings['post'] = [
'id' => 0,
'title' => wp_get_document_title(),
'excerpt' => get_the_archive_description(),
];
}
$empty_object = (object) [];
if ( $is_preview_mode ) {
$settings['elements'] = [
'data' => $empty_object,
'editSettings' => $empty_object,
'keys' => $empty_object,
];
}
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
if ( ! empty( $user->roles ) ) {
$settings['user'] = [
'roles' => $user->roles,
];
}
}
return $settings;
}
/**
* Restore content filters.
*
* Restore removed WordPress filters that conflicted with Elementor.
*
* @since 1.5.0
* @access public
*/
public function restore_content_filters() {
foreach ( $this->content_removed_filters as $filter ) {
add_filter( 'the_content', $filter );
}
$this->content_removed_filters = [];
}
/**
* Process More Tag
*
* Respect the native WP () tag
*
* @access private
* @since 2.0.4
*
* @param $content
*
* @return string
*/
private function process_more_tag( $content ) {
$post = get_post();
$content = str_replace( '<!--more-->', '', $content );
$parts = get_extended( $content );
if ( empty( $parts['extended'] ) ) {
return $content;
}
if ( is_singular() ) {
return $parts['main'] . '' . $parts['extended'];
}
if ( empty( $parts['more_text'] ) ) {
$parts['more_text'] = esc_html__( '(more…)', 'elementor' );
}
$more_link_text = sprintf(
'%2$s',
sprintf(
/* translators: %s: Current post name. */
__( 'Continue reading %s', 'elementor' ),
the_title_attribute( [
'echo' => false,
] )
),
$parts['more_text']
);
$more_link = sprintf( ' %s', get_permalink(), $post->ID, $more_link_text );
/**
* The content "more" link.
*
* Filters the "more" link displayed after the content.
*
* This hook can be used either to change the link syntax or to change the
* text inside the link.
*
* @since 2.0.4
*
* @param string $more_link The more link.
* @param string $more_link_text The text inside the more link.
*/
$more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
return force_balance_tags( $parts['main'] ) . $more_link;
}
private function is_optimized_css_mode() {
$is_optimized_css_loading = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
return ! Utils::is_script_debug() && $is_optimized_css_loading && ! Plugin::$instance->preview->is_preview_mode();
}
}