$frontpage_id, 'post_content' => wp_kses_post( $content ), ); wp_update_post( $post ); } } $thumbnail = get_theme_mod( 'hestia_feature_thumbnail', get_template_directory_uri() . '/assets/img/contact.jpg' ); $thumbnail_id = attachment_url_to_postid( $thumbnail ); update_post_meta( $frontpage_id, '_thumbnail_id', $thumbnail_id ); break; } update_option( 'hestia_sync_needed', false ); } add_action( 'after_setup_theme', 'hestia_sync_controls' ); /** * This function updates controls from customizer (about content and featured background) when you change your frontpage. */ function hestia_ajax_call() { $pid = $_POST['pid']; $return_value = array(); $content = get_post_field( 'post_content', $pid ); set_theme_mod( 'hestia_page_editor', $content ); $hestia_frontpage_featured = ''; if ( has_post_thumbnail( $pid ) ) { $hestia_frontpage_featured = get_the_post_thumbnail_url( $pid ); } else { $thumbnail = get_theme_mod( 'hestia_feature_thumbnail', get_template_directory_uri() . '/assets/img/contact.jpg' ); if ( $thumbnail === get_template_directory_uri() . '/assets/img/contact.jpg' ) { $hestia_frontpage_featured = get_template_directory_uri() . '/assets/img/contact.jpg'; } } set_theme_mod( 'hestia_feature_thumbnail', $hestia_frontpage_featured ); $return_value['post_content'] = $content; $return_value['post_thumbnail'] = $hestia_frontpage_featured; echo json_encode( $return_value ); die(); } add_action( 'wp_ajax_hestia_ajax_call', 'hestia_ajax_call' ); /** * Hestia allow all HTML tags in TinyMce editor. * * @param array $init_array TinyMce settings. * * @return array */ function hestia_override_mce_options( $init_array ) { $opts = '*[*]'; $init_array['valid_elements'] = $opts; $init_array['extended_valid_elements'] = $opts; return $init_array; } add_filter( 'tiny_mce_before_init', 'hestia_override_mce_options' ); /** * Sync frontpage content with customizer control * * @param string $value New value. * * @return mixed */ function hestia_sync_content_from_control( $value, $old_value = '' ) { if ( ! is_customize_preview() ) { return ''; } $frontpage_id = get_option( 'page_on_front' ); if ( ! empty( $frontpage_id ) && ! empty( $value ) ) { if ( ! wp_is_post_revision( $frontpage_id ) ) { // update the post, which calls save_post again $post = array( 'ID' => $frontpage_id, 'post_content' => wp_kses_post( $value ), ); wp_update_post( $post ); } } return $value; } /** * Change the default mode of the editor to html when using the tinyMce editor in customizer. * * @param string $editor_mode The current mode of the default editor. * * @return string The new mode (visual or html) of the editor, if we are in the customizer page. */ function hestia_change_editor_mode_to_html( $editor_mode ) { if ( is_customize_preview() && function_exists( 'get_current_screen' ) ) { $screen = get_current_screen(); if ( isset( $screen->id ) ) { if ( $screen->id === 'customize' ) { return 'tmce'; } } } return $editor_mode; } add_filter( 'wp_default_editor', 'hestia_change_editor_mode_to_html' ); /** * This filter is used to filter the content of the post after it is retrieved from the database and before it is * printed to the screen. * Initial we've applied 'the_content' filter but that was wrong because it relies on the global $post being set. * Otherwise, it can break plugins. See https://github.com/Codeinwp/hestia-pro/issues/309 for the issue. * For more explanations check this link https://themehybrid.com/weblog/how-to-apply-content-filters */ add_filter( 'hestia_text', 'wptexturize' ); add_filter( 'hestia_text', 'convert_smilies' ); add_filter( 'hestia_text', 'convert_chars' ); add_filter( 'hestia_text', 'wpautop' ); add_filter( 'hestia_text', 'shortcode_unautop' ); add_filter( 'hestia_text', 'do_shortcode' );