D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
homehopshortterm
/
www
/
wp-content
/
plugins
/
pixwell-core
/
includes
/
Filename :
actions.php
back
Copy
<?php /** Don't load directly */ defined( 'ABSPATH' ) || exit; add_action( 'init', 'pixwell_remove_plugin_hooks' ); add_action( 'init', 'pixwell_elementor_font_display', 20 ); add_action( 'admin_notices', 'pixwell_theme_settings_warn', 20 ); add_action( 'pre_get_posts', 'pixwell_blog_posts_per_page' ); add_action( 'pre_get_posts', 'pixwell_filter_search' ); add_action( 'save_post', 'pixwell_add_total_word', 100, 1 ); add_action( 'save_post_post', 'pixwell_init_avg_review', 999, 1 ); add_action( 'save_post_post', 'pixwell_video_save_featured', PHP_INT_MAX, 1 ); add_action( 'wp_head', 'pixwell_start_wp_head_buffer', 0 ); add_action( 'wp_head', 'pixwell_end_wp_head_buffer', PHP_INT_MAX ); add_action( 'wp_head', 'pixwell_bookmarklet_icon', 1 ); add_action( 'wp_head', 'pixwell_pingback_header', 5 ); add_action( 'wp_head', 'pixwell_preload_font_icon', 9 ); add_action( 'wp_head', 'pixwell_embed_dark_mode', 100 ); add_action( 'wp_enqueue_scripts', 'pixwell_remove_default_cooked', 999 ); add_action( 'wp_enqueue_scripts', 'pixwell_enqueue_optimized', 1000 ); add_action( 'wp_footer', 'pixwell_footer_inline_script', 1 ); add_action( 'wp_footer', 'rb_render_cookie_popup' ); add_action( 'wp_footer', 'pixwell_load_svg_icons', 99 ); add_filter( 'user_contactmethods', 'pixwell_additional_author_info' ); add_filter( 'wp_kses_allowed_html', 'pixwell_kses_allowed_html', 10, 2 ); add_filter( 'cooked_get_settings', 'pixwell_cooked_restore_content' ); add_filter( 'pvc_post_views_html', 'pixwell_post_views_remove', 999 ); add_filter( 'rbc_default_sidebar', 'pixwell_set_sidebar' ); add_filter( 'cooked_default_content', 'pixwell_cooked_default_content' ); add_filter( 'rb_deal_feat_medium', 'pixwell_deal_feat_medium' ); add_filter( 'bcn_pick_post_term', 'pixwell_pick_primary_cat', 10, 4 ); add_filter( 'post_class', 'pixwell_remove_hatom', 10, 1 ); add_filter( 'pvc_enqueue_styles', '__return_false' ); add_filter( 'wp_lazy_loading_enabled', 'pixwell_lazy_load' ); add_filter( 'wp_get_attachment_image_attributes', 'pixwell_optimize_featured_image', 10, 3 ); add_filter( 'get_the_archive_title_prefix', 'pixwell_archive_title_prefix', 10 ); add_filter( 'widget_text', 'do_shortcode' ); add_filter( 'upload_mimes', 'pixwell_svg_upload_supported', 10, 1 ); add_filter( 'wp_get_attachment_image_src', 'pixwell_support_gif', 10, 4 ); remove_filter( 'pre_term_description', 'wp_filter_kses' ); remove_filter( 'term_description', 'wp_kses_data' ); if ( ! function_exists( 'pixwell_pingback_header' ) ): function pixwell_pingback_header() { if ( is_singular() && pings_open() ) : ?> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"/> <?php endif; } endif; if ( ! function_exists( 'pixwell_bookmarklet_icon' ) ) { function pixwell_bookmarklet_icon() { $apple_icon = pixwell_get_option( 'icon_touch_apple' ); $metro_icon = pixwell_get_option( 'icon_touch_metro' ); if ( ! empty( $apple_icon['url'] ) ) : ?> <link rel="apple-touch-icon" href="<?php echo esc_url( $apple_icon['url'] ); ?>"/> <?php endif; if ( ! empty( $metro_icon['url'] ) ) : ?> <meta name="msapplication-TileColor" content="#ffffff"> <meta name="msapplication-TileImage" content="<?php echo esc_url( $metro_icon['url'] ); ?>"/> <?php endif; } } if ( ! function_exists( 'pixwell_post_views_remove' ) ) { function pixwell_post_views_remove( $html ) { if ( is_single() ) { return false; } else { return $html; } } } if ( ! function_exists( 'pixwell_blog_posts_per_page' ) ) { function pixwell_blog_posts_per_page( $query ) { if ( is_admin() ) { return false; } if ( $query->is_main_query() ) { if ( $query->is_search() || $query->is_category() || $query->is_tag() || $query->is_author() || $query->is_archive() ) { $query->set( 'post_status', 'publish' ); } if ( $query->is_home() ) { $blog_index_posts_per_page = pixwell_get_option( 'blog_posts_per_page_index' ); if ( ! empty( $blog_index_posts_per_page ) ) { $query->set( 'posts_per_page', intval( $blog_index_posts_per_page ) ); } } elseif ( $query->is_search() ) { $search_posts_per_page = pixwell_get_option( 'blog_posts_per_page_search' ); if ( ! empty( $search_posts_per_page ) ) { $query->set( 'posts_per_page', intval( $search_posts_per_page ) ); } } elseif ( $query->is_category() ) { $term_meta = rb_get_term_meta( 'pixwell_meta_categories', get_queried_object_id() ); if ( ! empty( $term_meta['posts_per_page'] ) ) { $posts_per_page = $term_meta['posts_per_page']; } else { $posts_per_page = pixwell_get_option( 'blog_posts_per_page_cat' ); } if ( ! empty( $posts_per_page ) ) { $query->set( 'posts_per_page', intval( $posts_per_page ) ); } } elseif ( $query->is_author() ) { $author_posts_per_page = pixwell_get_option( 'blog_posts_per_page_author' ); if ( ! empty( $author_posts_per_page ) ) { $query->set( 'posts_per_page', intval( $author_posts_per_page ) ); } } elseif ( $query->is_archive() ) { if ( $query->is_post_type_archive( 'rb-portfolio' ) || $query->is_tax( 'portfolio-category' ) ) { $portfolio_posts_per_page = pixwell_get_option( 'portfolio_posts_per_page' ); if ( ! empty( $portfolio_posts_per_page ) ) { $query->set( 'posts_per_page', intval( $portfolio_posts_per_page ) ); } } else { $archive_posts_per_page = pixwell_get_option( 'blog_posts_per_page_archive' ); if ( ! empty( $archive_posts_per_page ) ) { $query->set( 'posts_per_page', intval( $archive_posts_per_page ) ); } } } } return false; } } /** * @return string * set default sidebar name */ if ( ! function_exists( 'pixwell_set_sidebar' ) ) { function pixwell_set_sidebar() { return 'pixwell_sidebar_default'; } } /** * @return bool * remove search page */ if ( ! function_exists( 'pixwell_filter_search' ) ) { function pixwell_filter_search( $query ) { $search_page = pixwell_get_option( 'search_post' ); if ( ! empty( $search_page ) && ! is_admin() && $query->is_search() && $query->is_main_query() ) { $query->set( 'post_type', 'post' ); } return $query; } } /** * @return array * author info */ if ( ! function_exists( 'pixwell_additional_author_info' ) ) { function pixwell_additional_author_info( $user ) { if ( ! is_array( $user ) ) { $user = []; } $data = [ 'job' => esc_html__( 'Your Job Name', 'pixwell-core' ), 'feat' => esc_html__( 'Author Box Background', 'pixwell-core' ) . '<br/><small>' . esc_html__( '(Input attachment Image URL)', 'pixwell-core' ), 'facebook' => esc_html__( 'Facebook profile URL', 'pixwell-core' ), 'rb_twitter' => esc_html__( 'Twitter profile URL', 'pixwell-core' ), 'instagram' => esc_html__( 'Instagram profile URL', 'pixwell-core' ), 'pinterest' => esc_html__( 'Pinterest profile URL', 'pixwell-core' ), 'linkedin' => esc_html__( 'LinkedIn profile URL', 'pixwell-core' ), 'tumblr' => esc_html__( 'Tumblr profile URL', 'pixwell-core' ), 'flickr' => esc_html__( 'Flickr profile URL', 'pixwell-core' ), 'skype' => esc_html__( 'Skype profile URL', 'pixwell-core' ), 'snapchat' => esc_html__( 'Snapchat profile URL', 'pixwell-core' ), 'myspace' => esc_html__( 'Myspace profile URL', 'pixwell-core' ), 'youtube' => esc_html__( 'Youtube profile URL', 'pixwell-core' ), 'bloglovin' => esc_html__( 'Bloglovin profile URL', 'pixwell-core' ), 'digg' => esc_html__( 'Digg profile URL', 'pixwell-core' ), 'dribbble' => esc_html__( 'Dribbble profile URL', 'pixwell-core' ), 'soundcloud' => esc_html__( 'Soundcloud profile URL', 'pixwell-core' ), 'vimeo' => esc_html__( 'Vimeo profile URL', 'pixwell-core' ), 'reddit' => esc_html__( 'Reddit profile URL', 'pixwell-core' ), 'vkontakte' => esc_html__( 'Vkontakte profile URL', 'pixwell-core' ), 'telegram' => esc_html__( 'Telegram profile URL', 'pixwell-core' ), 'whatsapp' => esc_html__( 'Whatsapp profile URL', 'pixwell-core' ), 'rss' => esc_html__( 'Rss', 'pixwell-core' ), ]; $user = array_merge( $user, $data ); return $user; } } if ( ! function_exists( 'pixwell_add_avg_review' ) ) { function pixwell_add_avg_review( $post_id = '' ) { if ( empty( $post_id ) ) { $post_id = get_the_ID(); } $review = rb_get_meta( 'post_review', $post_id ); if ( empty( $review ) || $review != 1 ) { return false; } $total = 0; $count = 0; $data = [ [ 'review_label' => rb_get_meta( 'review_label_1', $post_id ), 'review_star' => rb_get_meta( 'review_star_1', $post_id ), ], [ 'review_label' => rb_get_meta( 'review_label_2', $post_id ), 'review_star' => rb_get_meta( 'review_star_2', $post_id ), ], [ 'review_label' => rb_get_meta( 'review_label_3', $post_id ), 'review_star' => rb_get_meta( 'review_star_3', $post_id ), ], [ 'review_label' => rb_get_meta( 'review_label_4', $post_id ), 'review_star' => rb_get_meta( 'review_star_4', $post_id ), ], [ 'review_label' => rb_get_meta( 'review_label_5', $post_id ), 'review_star' => rb_get_meta( 'review_star_5', $post_id ), ], [ 'review_label' => rb_get_meta( 'review_label_6', $post_id ), 'review_star' => rb_get_meta( 'review_star_6', $post_id ), ], [ 'review_label' => rb_get_meta( 'review_label_7', $post_id ), 'review_star' => rb_get_meta( 'review_star_7', $post_id ), ], ]; foreach ( $data as $element ) { if ( ! empty( $element['review_label'] ) && ! empty( $element['review_star'] ) ) { $element['review_star'] = absint( $element['review_star'] ); if ( $element['review_star'] > 5 ) { $element['review_star'] = 5; } elseif ( $element['review_star'] < 1 ) { $element['review_star'] = 1; } $total = $total + $element['review_star']; $count ++; } } if ( $count > 0 ) { $total = round( $total / $count, 1 ); update_post_meta( $post_id, 'pixwell_review_stars', $total ); } return $count; } } if ( ! function_exists( 'pixwell_init_avg_review' ) ) { function pixwell_init_avg_review( $post_id = '' ) { if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! empty( $_GET['rest_route'] ) ) { return false; } /** */ pixwell_add_avg_review( $post_id ); } } /** cooked plugin support */ if ( ! function_exists( 'pixwell_cooked_default_content' ) ) { function pixwell_cooked_default_content() { return '<p>[cooked-info left="author,taxonomies,difficulty" right="print,fullscreen"]</p><p>[cooked-excerpt]</p><p>[cooked-info left="servings" right="prep_time,cook_time,total_time"]</p><p>[cooked-ingredients]</p><p>[cooked-directions]</p><p>[cooked-gallery]</p>'; } } /** restore default if empty */ if ( ! function_exists( 'pixwell_cooked_restore_content' ) ) { function pixwell_cooked_restore_content( $settings ) { if ( empty( $settings['default_content'] ) ) { $settings['default_content'] = pixwell_cooked_default_content(); } return $settings; } } /** support cooked plugin with infinite load next */ if ( ! function_exists( 'pixwell_remove_default_cooked' ) ) { function pixwell_remove_default_cooked() { if ( is_plugin_active( 'cooked/cooked.php' ) ) { wp_deregister_script( 'cooked-functions-js' ); wp_register_script( 'cooked-functions-js', PIXWELL_CORE_URL . 'assets/cooked-reload.js', [ 'jquery' ], '1.0', true ); } } } /** default deal thumbnails */ if ( ! function_exists( 'pixwell_deal_feat_medium' ) ) { function pixwell_deal_feat_medium( $size ) { return 'pixwell_280x210'; } } /** render cookie popup */ if ( ! function_exists( 'rb_render_cookie_popup' ) ) : function rb_render_cookie_popup() { $popup = pixwell_get_option( 'cookie_popup' ); if ( empty( $popup ) || pixwell_is_amp() ) { return; } $content = pixwell_get_option( 'cookie_popup_content' ); $button = pixwell_get_option( 'cookie_popup_button' ); ?> <aside id="rb-cookie" class="rb-cookie"> <p class="cookie-content"><?php echo do_shortcode( $content ); ?></p> <div class="cookie-footer"> <a id="cookie-accept" class="cookie-accept" href="#"><?php echo esc_html( $button ) ?></a> </div> </aside> <?php } endif; /** primary category */ if ( ! function_exists( 'pixwell_pick_primary_cat' ) ) { function pixwell_pick_primary_cat( $terms, $id, $type, $taxonomy ) { if ( 'post' == $type ) { $primary_category = rb_get_meta( 'primary_cat', $id ); if ( empty( $primary_category ) ) { return $terms; }; return get_term_by( 'id', $primary_category, $taxonomy ); } return $terms; } } /** load reaction icons */ if ( ! function_exists( 'pixwell_load_svg_icons' ) ) { function pixwell_load_svg_icons() { if ( pixwell_is_amp() || ! is_singular( 'post' ) ) { return; } include_once PIXWELL_CORE_PATH . 'includes/icons.php'; } } if ( ! function_exists( 'pixwell_remove_hatom' ) ) { function pixwell_remove_hatom( $classes ) { foreach ( $classes as $key => $value ) { if ( $value == 'hentry' ) { unset( $classes[ $key ] ); } } return $classes; } } if ( ! function_exists( 'pixwell_preload_font_icon' ) ) { function pixwell_preload_font_icon() { if ( ! pixwell_get_option( 'preload_icon' ) ) { return; } echo sprintf( '<link rel="preload" href="%s" as="font" type="font/woff2" crossorigin="anonymous">', get_theme_file_uri( 'assets/fonts/ruby-icon.woff2?v=10.7' ) ); } } if ( ! function_exists( 'pixwell_lazy_load' ) ) { /** * @return bool */ function pixwell_lazy_load() { if ( empty( pixwell_get_option( 'lazy_load' ) ) ) { return false; } else { return true; } } } if ( ! function_exists( 'pixwell_remove_plugin_hooks' ) ) { /** * remove multiple authors */ function pixwell_remove_plugin_hooks() { global $multiple_authors_addon; if ( ! empty( $multiple_authors_addon ) ) { remove_filter( 'the_content', [ $multiple_authors_addon, 'filter_the_content' ] ); } } } if ( ! function_exists( 'pixwell_enqueue_optimized' ) ) { function pixwell_enqueue_optimized() { /** disable on elementor live editor */ if ( ! empty( $_GET['elementor-preview'] ) ) { return; } if ( pixwell_get_option( 'disable_dashicons' ) && ! is_user_logged_in() ) { wp_deregister_style( 'dashicons' ); } if ( pixwell_get_option( 'disable_block_style' ) && ( is_page_template( 'rbc-frontend.php' ) || pixwell_is_elementor() ) && ! is_admin() ) { wp_deregister_style( 'wp-block-library' ); } } } if ( ! function_exists( 'pixwell_is_elementor' ) ) { /** * @return bool */ function pixwell_is_elementor() { if ( ! is_page() ) { return false; } $document = false; if ( class_exists( 'Elementor\Plugin' ) ) { $document = Elementor\Plugin::$instance->documents->get( get_the_ID() ); } if ( $document && $document->is_built_with_elementor() ) { return true; } return false; } } if ( ! function_exists( 'pixwell_elementor_font_display' ) ) { function pixwell_elementor_font_display() { if ( empty( get_option( 'elementor_font_display' ) ) ) { update_option( 'elementor_font_display', 'swap' ); } } } if ( ! function_exists( 'pixwell_optimize_featured_image' ) ) { /** * @param $attr * @param $attachment * @param $size * * @return mixed */ function pixwell_optimize_featured_image( $attr, $attachment, $size ) { if ( pixwell_get_option( 'disable_srcset' ) ) { unset( $attr['srcset'] ); unset( $attr['sizes'] ); } return $attr; } } /** per load google font */ if ( ! function_exists( 'pixwell_start_wp_head_buffer' ) ) { function pixwell_start_wp_head_buffer() { if ( pixwell_is_amp() ) { return false; } ob_start(); } } if ( ! function_exists( 'pixwell_end_wp_head_buffer' ) ) { function pixwell_end_wp_head_buffer() { if ( pixwell_is_amp() ) { return false; } $in = ob_get_clean(); $preload_font = pixwell_get_option( 'preload_gfonts' ); $disable_google_fonts = pixwell_get_option( 'disable_google_font' ); if ( ! empty( $disable_google_fonts ) ) { $preload_font = true; } if ( ! $preload_font || pixwell_is_amp() || is_admin() || ! empty( $_GET['elementor-preview'] ) ) { echo $in; return false; } $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in ); preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches ); if ( ! $matches[2] ) { echo $in; return false; } $fonts_data = []; $index = 0; $fonts_string = ''; $subset_string = ''; $add_pos = '<link'; foreach ( $matches[2] as $font ) { if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $index ] ) ) { $font = str_replace( [ '%7C', '%7c' ], '|', $font ); if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) { $font = rawurldecode( $font ); $font = str_replace( [ 'css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family=', ], [ 'css?', '', '', '', '', 'italic', ':italic', ',', '%7C' ], $font ); } $font = explode( 'family=', $font ); $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : []; $this_font = array_values( array_filter( explode( '|', reset( $font ) ) ) ); if ( ! empty( $this_font ) ) { $fonts_data[ $index ]['fonts'] = $this_font; $subset = ( is_array( $font ) ) ? end( $font ) : ''; if ( false !== strpos( $subset, 'subset=' ) ) { $subset = str_replace( [ '%2C', '%2c' ], ',', $subset ); $subset = explode( 'subset=', $subset ); $fonts_data[ $index ]['subsets'] = explode( ',', $subset[1] ); } } $in = str_replace( $matches[0][ $index ], '', $in ); } $index ++; } foreach ( $fonts_data as $font ) { $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' ); if ( ! empty( $font['subsets'] ) ) { $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' ); } } if ( ! empty( $subset_string ) ) { $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) ); $fonts_string = $fonts_string . '&subset=' . $subset_string; } $fonts_string = str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ); $fonts_string .= '&display=swap'; $fonts_html = '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>'; $fonts_html .= '<link rel="preload" as="style" onload="this.onload=null;this.rel=\'stylesheet\'" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" crossorigin>'; $fonts_html .= '<noscript><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '"></noscript>'; /** remove all google fonts */ if ( $disable_google_fonts ) { $fonts_html = ''; } echo substr_replace( $in, $fonts_html . $add_pos, strpos( $in, $add_pos ), strlen( $add_pos ) ); return false; } } /** * @param $tags * @param $context * * @return array|mixed */ if ( ! function_exists( 'pixwell_kses_allowed_html' ) ) { function pixwell_kses_allowed_html( $tags, $context ) { switch ( $context ) { case 'pixwell': $tags = [ 'a' => [ 'href' => [], 'title' => [], 'target' => [], ], 'br' => [], 'em' => [], 'strong' => [], 'i' => [ 'class' => [], ], 'p' => [], 'span' => [], 'div' => [ 'class' => [], ], ]; return $tags; default: return $tags; } } } if ( ! function_exists( 'pixwell_embed_dark_mode' ) ) { function pixwell_embed_dark_mode() { if ( pixwell_is_amp() ) { return false; } $dark_mode = (string) pixwell_get_option( 'dark_mode' ); $optimize_load = (string) pixwell_get_option( 'dark_mode_cookie' ); if ( 'browser' === $dark_mode ) { add_action( 'wp_body_open', 'pixwell_dark_mode_prefers_scheme_script', 0 ); } if ( '2' === $optimize_load ) { add_action( 'wp_body_open', 'pixwell_dark_mode_inline_script', 0 ); } else { add_action( 'wp_footer', 'pixwell_dark_mode_inline_script', 0 ); } } } if ( ! function_exists( 'pixwell_dark_mode_prefers_scheme_script' ) ) { function pixwell_dark_mode_prefers_scheme_script() { $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'"; ?> <script<?php echo $type_attr; ?>> (function () { document.body.setAttribute('data-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default'); })(); </script> <?php } } if ( ! function_exists( 'pixwell_dark_mode_inline_script' ) ) { function pixwell_dark_mode_inline_script() { if ( '1' !== (string) pixwell_get_option( 'dark_mode' ) ) { return false; } $optimized_load = (string) pixwell_get_option( 'dark_mode_cookie' ); $cookie_mode = ( $optimized_load === '1' ); $first_visit_mode = pixwell_get_option( 'first_visit_mode' ); $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'"; ?> <script<?php echo $type_attr; ?>> (function () { let currentMode = null; const darkModeID = '<?php echo pixwell_get_dark_mode_id() ?>'; <?php if( $cookie_mode ) : ?> currentMode = document.body.getAttribute('data-theme'); if (currentMode === 'browser' && window.matchMedia) { currentMode = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default'; document.body.setAttribute('data-theme', currentMode); } <?php else: ?> currentMode = navigator.cookieEnabled ? localStorage.getItem(darkModeID) || null : 'default'; if (!currentMode) { <?php if( 'browser' === $first_visit_mode ) : ?> if (window.matchMedia && navigator.cookieEnabled) { currentMode = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default'; localStorage.setItem(darkModeID, currentMode); } <?php else : ?> currentMode = '<?php echo esc_attr( $first_visit_mode ); ?>'; localStorage.setItem(darkModeID, '<?php echo esc_attr( $first_visit_mode ); ?>'); <?php endif; ?> } document.body.setAttribute('data-theme', currentMode === 'dark' ? 'dark' : 'default'); <?php endif; ?> })(); </script> <?php } } if ( ! function_exists( 'pixwell_footer_inline_script' ) ) { function pixwell_footer_inline_script() { if ( pixwell_is_amp() ) { return false; } $optimized_load = (string) pixwell_get_option( 'dark_mode_cookie' ); $dark_mode = (string) pixwell_get_option( 'dark_mode' ); $cookie_mode = ( $optimized_load === '1' ); $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'"; ?> <script<?php echo $type_attr; ?>> (function () { <?php if ( '1' === $dark_mode ) : ?> const darkModeID = '<?php echo pixwell_get_dark_mode_id() ?>'; const currentMode = <?php echo ! empty( $cookie_mode ) ? "document.body.getAttribute('data-theme')" : "navigator.cookieEnabled ? (localStorage.getItem(darkModeID) || 'default') : 'default'" ?>; const selector = currentMode === 'dark' ? '.mode-icon-dark' : '.mode-icon-default'; const icons = document.querySelectorAll(selector); if (icons.length) { icons.forEach(icon => icon.classList.add('activated')); } <?php endif; ?> })(); </script> <?php } } if ( ! function_exists( 'pixwell_archive_title_prefix' ) ) { function pixwell_archive_title_prefix( $prefix ) { if ( pixwell_get_option( 'archive_no_prefix' ) ) { return false; } return $prefix; } } if ( ! function_exists( 'pixwell_svg_upload_supported' ) ) { /** * @param $mime_types * * @return mixed */ function pixwell_svg_upload_supported( $mime_types = [] ) { if ( pixwell_get_option( 'svg_support' ) ) { $mime_types['svg'] = 'image/svg+xml'; $mime_types['svgz'] = 'image/svg+xml'; } return $mime_types; } } if ( ! function_exists( 'pixwell_video_save_featured' ) ) { function pixwell_video_save_featured( $post_id ) { if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! empty( $_GET['rest_route'] ) ) { return; } if ( empty( $post_id ) || get_post_status( $post_id ) !== 'publish' || 'post' !== get_post_type( $post_id ) ) { return; } if ( ! empty( get_post_meta( $post_id, '_thumbnail_id', true ) ) ) { return; } $post_type = get_post_type( $post_id ); $video_url = rb_get_meta( 'video_url', $post_id ); if ( 'post' != $post_type || empty( $video_url ) ) { return; } $image_url = pixwell_video_get_feat( $video_url ); if ( ! empty( $image_url ) ) { if ( ! function_exists( 'media_sideload_image' ) ) { require_once( ABSPATH . 'wp-admin/includes/media.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' ); require_once( ABSPATH . 'wp-admin/includes/image.php' ); } $attr_id = media_sideload_image( $image_url, $post_id, null, 'id' ); set_post_thumbnail( $post_id, $attr_id ); } } } if ( ! function_exists( 'pixwell_video_get_feat' ) ) { function pixwell_video_get_feat( $video_url ) { if ( empty( $video_url ) ) { return false; } $host_name = pixwell_video_detect_url( $video_url ); switch ( $host_name ) { case 'youtube' : return pixwell_video_get_feat_youtube( $video_url ); case 'vimeo' : return pixwell_video_get_feat_vimeo( $video_url ); case 'dailymotion' : return pixwell_video_get_feat_dailymotion( $video_url ); default : return false; } } } if ( ! function_exists( 'pixwell_video_set_featured' ) ) { function pixwell_video_set_featured( $att_id ) { update_post_meta( get_the_ID(), '_thumbnail_id', $att_id ); } } if ( ! function_exists( 'pixwell_support_gif' ) ) { function pixwell_support_gif( $image, $attachment_id, $size, $icon ) { $gif_support = pixwell_get_option( 'gif_support' ); if ( ! empty( $gif_support ) && ! empty( $image[0] ) ) { $format = wp_check_filetype( $image[0] ); if ( ! empty( $format ) && 'gif' == $format['ext'] && 'full' != $size ) { return wp_get_attachment_image_src( $attachment_id, $size = 'full', $icon ); } } return $image; } } if ( ! function_exists( 'pixwell_video_detect_url' ) ) { function pixwell_video_detect_url( $video_url ) { $video_url = strtolower( $video_url ); if ( strpos( $video_url, 'youtube.com' ) !== false || strpos( $video_url, 'youtu.be' ) !== false ) { return 'youtube'; } if ( strpos( $video_url, 'dailymotion.com' ) !== false ) { return 'dailymotion'; } if ( strpos( $video_url, 'vimeo.com' ) !== false ) { return 'vimeo'; } return false; } } if ( ! function_exists( 'pixwell_video_id_youtube' ) ) { function pixwell_video_id_youtube( $video_url ) { $s = []; parse_str( parse_url( $video_url, PHP_URL_QUERY ), $s ); if ( empty( $s["v"] ) ) { $youtube_sl_explode = explode( '?', $video_url ); $youtube_sl = explode( '/', $youtube_sl_explode[0] ); if ( ! empty( $youtube_sl[3] ) ) { return $youtube_sl [3]; } return $youtube_sl [0]; } else { return $s["v"]; } } } if ( ! function_exists( 'pixwell_video_id_vimeo' ) ) { function pixwell_video_id_vimeo( $video_url ) { sscanf( parse_url( $video_url, PHP_URL_PATH ), '/%d', $video_id ); return $video_id; } } if ( ! function_exists( 'pixwell_video_id_dailymotion' ) ) { function pixwell_video_id_dailymotion( $video_url ) { $video_id = strtok( basename( $video_url ), '_' ); if ( strpos( $video_id, '#video=' ) !== false ) { $video_parts = explode( '#video=', $video_id ); if ( ! empty( $video_parts[1] ) ) { return $video_parts[1]; } }; return $video_id; } } if ( ! function_exists( 'pixwell_video_feat_response' ) ) { function pixwell_video_feat_response( $image_url ) { $headers = @get_headers( $image_url ); if ( ! empty( $headers[0] ) and strpos( $headers[0], '404' ) !== false ) { return true; } return false; } } if ( ! function_exists( 'pixwell_video_get_feat_youtube' ) ) { function pixwell_video_get_feat_youtube( $video_url ) { $protocol = pixwell_protocol(); $video_id = pixwell_video_id_youtube( $video_url ); $image_url_1920 = $protocol . '://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg'; $image_url_640 = $protocol . '://img.youtube.com/vi/' . $video_id . '/sddefault.jpg'; $image_url_480 = $protocol . '://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg'; if ( ! pixwell_video_feat_response( $image_url_1920 ) ) { return $image_url_1920; } elseif ( ! pixwell_video_feat_response( $image_url_640 ) ) { return $image_url_640; } elseif ( ! pixwell_video_feat_response( $image_url_480 ) ) { return $image_url_480; } else { return false; } } } if ( ! function_exists( 'pixwell_video_get_feat_vimeo' ) ) { function pixwell_video_get_feat_vimeo( $video_url ) { $protocol = pixwell_protocol(); $video_id = pixwell_video_id_vimeo( $video_url ); $api_url = $protocol . '://vimeo.com/api/oembed.json?url=https://vimeo.com/' . $video_id; $data_response = wp_remote_get( $api_url, [ 'timeout' => 60, 'sslverify' => false, 'user-agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0', ] ); if ( ! is_wp_error( $data_response ) ) { $data_response = wp_remote_retrieve_body( $data_response ); $data_response = json_decode( $data_response ); return $data_response->thumbnail_url; } else { return false; } } } if ( ! function_exists( 'pixwell_video_get_feat_dailymotion' ) ) { function pixwell_video_get_feat_dailymotion( $video_url ) { $video_id = pixwell_video_id_dailymotion( $video_url ); $protocol = pixwell_protocol(); $param = $protocol . '://api.dailymotion.com/video/' . $video_id . '?fields=thumbnail_url'; $data_response = wp_remote_get( $param ); if ( ! is_wp_error( $data_response ) ) { $data_response = json_decode( $data_response['body'] ); return $data_response->thumbnail_url; } else { return false; } } } if ( ! function_exists( 'pixwell_add_total_word' ) ) { function pixwell_add_total_word( $post_id = '' ) { if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! empty( $_GET['rest_route'] ) ) { return false; } if ( empty( $post_id ) ) { $post_id = get_the_ID(); } $content = get_post_field( 'post_content', $post_id ); $total_word = pixwell_total_word( $content ); update_post_meta( $post_id, 'pixwell_total_word', $total_word ); return $total_word; } }