' . $located . '' ), '1.0' ); return; } // Allow 3rd party plugin filter template file from their plugin. $located = apply_filters( 'rttpg_get_template', $located, $template_name, $args ); do_action( 'rttpg_before_template_part', $template_name, $located, $args ); include $located; do_action( 'rttpg_after_template_part', $template_name, $located, $args ); } /** * Get template content and return * * @param string $template_name Template name. * @param array $args Arguments. (default: array). * @param string $template_path Template path. (default: ''). * @param string $default_path Default path. (default: ''). * * @return string */ public static function get_template_html( $template_name, $args = [], $template_path = '', $default_path = '' ) { ob_start(); self::get_template( $template_name, $args, $template_path, $default_path ); return ob_get_clean(); } /** * Locate template. * * @param string $template_name Template. * @param string $template_path Path. * @param string $default_path Default path. * * @return mixed|void */ public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { $template_name = $template_name . '.php'; if ( ! $template_path ) { $template_path = rtTPG()->get_template_path(); } if ( ! $default_path ) { $default_path = rtTPG()->default_template_path() . '/templates/'; } // Look within passed path within the theme - this is priority. $template_files = []; $template_files[] = trailingslashit( $template_path ) . $template_name; $template = locate_template( apply_filters( 'rttpg_locate_template_files', $template_files, $template_name, $template_path, $default_path ) ); // Get default template/. if ( ! $template ) { $template = trailingslashit( $default_path ) . $template_name; } return apply_filters( 'rttpg_locate_template', $template, $template_name ); } /** * Mark something as being incorrectly called. * * @param string $function — The function that was called. * @param string $message — A message explaining what has been done incorrectly. * @param string $version — The version of WordPress where the message was added. * * @return void */ public static function doing_it_wrong( $function, $message, $version ) { // phpcs:disable $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); _doing_it_wrong( $function, $message, $version ); // phpcs:enable } /** * Verify nonce. * * @return bool */ public static function verifyNonce() { $nonce = isset( $_REQUEST[ rtTPG()->nonceId() ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ rtTPG()->nonceId() ] ) ) : null; $nonceText = rtTPG()->nonceText(); if ( ! wp_verify_nonce( $nonce, $nonceText ) ) { return false; } return true; } /** * @param $data * @param $temp_path * * @return void */ public static function tpg_template( $data, $temp_path = 'elementor' ) { $layout = str_replace( '-2', '', $data['layout'] ); $template_name = '/the-post-grid/' . $temp_path . '/' . $layout . '.php'; if ( file_exists( STYLESHEETPATH . $template_name ) ) { $file = STYLESHEETPATH . $template_name; } else if ( file_exists( TEMPLATEPATH . $template_name ) ) { $file = TEMPLATEPATH . $template_name; } else { $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php'; if ( ! file_exists( $file ) ) { if ( rtTPG()->hasPro() ) { $file = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php'; } else { $layout = substr( $layout, 0, - 1 ); $layout = strpos( $layout, '1' ) ? str_replace( '1', '', $layout ) : $layout; $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '1.php'; } } } ob_start(); include $file; echo ob_get_clean(); } /** * @param $data * * @return string */ public static function tpg_template_path( $data, $temp_path = 'elementor' ) { $layout = str_replace( '-2', '', $data['layout'] ); $template_name = '/the-post-grid/' . $temp_path . '/' . $layout . '.php'; $path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/'; if ( file_exists( STYLESHEETPATH . $template_name ) ) { $path = STYLESHEETPATH . '/the-post-grid/' . $temp_path . '/'; } else if ( file_exists( TEMPLATEPATH . $template_name ) ) { $path = TEMPLATEPATH . '/the-post-grid/' . $temp_path . '/'; } else { $template_path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/' . $temp_path . '/' . $layout . '.php'; if ( ! file_exists( $template_path ) && rtTPG()->hasPro() ) { $path = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/' . $temp_path . '/'; } } return $path; } /** * Get Post Pagination, Load more & Scroll markup * * @param $query * @param $data * * @return false|string|void */ public static function get_pagination_markup( $query, $data ) { if ( 'show' !== $data['show_pagination'] ) { return; } $htmlUtility = null; $posts_loading_type = $data['pagination_type']; $posts_per_page = ( isset( $data['display_per_page'] ) && $data['display_per_page'] ) ? $data['display_per_page'] : ( $data['post_limit'] ? $data['post_limit'] : get_option( 'posts_per_page' ) ); $hide = ( $query->max_num_pages < 2 ? " rt-hidden-elm" : null ); if ( $posts_loading_type == "pagination" ) { $htmlUtility .= Fns::rt_pagination( $query, $posts_per_page ); } else if ( rtTPG()->hasPro() && $posts_loading_type == "pagination_ajax" ) { //&& ! $isIsotope $htmlUtility .= "
"; } else if ( rtTPG()->hasPro() && $posts_loading_type == "load_more" ) { $load_more_button_text = $data['load_more_button_text'] ? $data['load_more_button_text'] : __( "Load More", 'the-post-grid' ); $htmlUtility .= "
" . $load_more_button_text . "
"; } else if ( rtTPG()->hasPro() && $posts_loading_type == "load_on_scroll" ) { $htmlUtility .= "
"; } if ( $htmlUtility ) { $html = "
" . $htmlUtility . "
"; return $html; } return false; } /** * @param $data * @param $total_pages * @param $posts_per_page * @param $_prefix * @param $is_gutenberg * * @return array */ public static function get_render_data_set( $data, $total_pages, $posts_per_page, $_prefix, $is_gutenberg = '' ) { $data_set = [ 'block_type' => 'elementor', 'is_gutenberg' => $is_gutenberg, 'prefix' => $_prefix, 'grid_column' => $data[ $_prefix . '_column' ] ?? '0', 'grid_column_tablet' => $data[ $_prefix . '_column_tablet' ] ?? '0', 'grid_column_mobile' => $data[ $_prefix . '_column_mobile' ] ?? '0', 'layout' => $data[ $_prefix . '_layout' ], 'pagination_type' => 'slider' === $_prefix ? 'slider' : $data['pagination_type'], 'total_pages' => $total_pages, 'posts_per_page' => $posts_per_page, 'layout_style' => $data[ $_prefix . '_layout_style' ] ?? '', 'show_title' => $data['show_title'], 'excerpt_type' => $data['excerpt_type'], 'excerpt_limit' => $data['excerpt_limit'], 'excerpt_more_text' => $data['excerpt_more_text'], 'title_limit' => $data['title_limit'], 'title_limit_type' => $data['title_limit_type'], 'title_visibility_style' => $data['title_visibility_style'], 'post_link_type' => $data['post_link_type'], 'link_target' => $data['link_target'], 'hover_animation' => $data['hover_animation'] ?? '', 'show_thumb' => $data['show_thumb'], 'show_meta' => $data['show_meta'], 'show_author' => $data['show_author'], 'show_author_image' => $data['show_author_image'], 'author_icon_visibility' => $data['author_icon_visibility'], 'show_meta_icon' => $data['show_meta_icon'], 'show_category' => $data['show_category'], 'show_date' => $data['show_date'], 'show_tags' => $data['show_tags'], 'show_comment_count' => $data['show_comment_count'], 'show_comment_count_label' => $data['show_comment_count_label'] ?? '', 'comment_count_label_singular' => $data['comment_count_label_singular'] ?? '', 'comment_count_label_plural' => $data['comment_count_label_plural'] ?? '', 'show_post_count' => $data['show_post_count'], 'post_count_icon' => $data['post_count_icon'] ?? '', 'show_excerpt' => $data['show_excerpt'], 'show_read_more' => $data['show_read_more'], 'show_btn_icon' => $data['show_btn_icon'], 'show_social_share' => $data['show_social_share'], 'show_cat_icon' => $data['show_cat_icon'] ?? '', 'is_thumb_linked' => $data['is_thumb_linked'], 'media_source' => $data['media_source'], 'no_posts_found_text' => isset( $data['no_posts_found_text'] ) ? esc_html( $data['no_posts_found_text'] ) : '', 'image_size' => $data['image_size'], 'image_offset' => $data['image_offset_size'], 'is_default_img' => $data['is_default_img'], 'default_image' => $data['default_image'], 'thumb_overlay_visibility' => $data['thumb_overlay_visibility'] ?? '', 'overlay_type' => $data['overlay_type'] ?? '', 'title_tag' => $data['title_tag'], 'post_type' => $data['post_type'], 'meta_separator' => $data['meta_separator'], 'readmore_icon_position' => $data['readmore_icon_position'], 'read_more_label' => $data['read_more_label'], 'readmore_btn_icon' => $data['readmore_btn_icon'], 'category_position' => $data['category_position'], 'title_position' => $data['title_position'] ?? 'default', 'category_style' => $data['category_style'] ?? '', 'is_thumb_lightbox' => $data['is_thumb_lightbox'], 'author_prefix' => $data['author_prefix'], 'cat_icon' => $data['cat_icon'] ?? '', 'tag_icon' => $data['tag_icon'] ?? '', 'date_icon' => $data['date_icon'] ?? '', 'user_icon' => $data['user_icon'] ?? '', 'meta_ordering' => $data['meta_ordering'], 'comment_icon' => $data['comment_icon'] ?? '', 'image_custom_dimension' => ( $data['image_size'] == 'custom' && isset( $data['image_custom_dimension'] ) ) ? $data['image_custom_dimension'] : [], 'img_crop_style' => ( $data['image_size'] == 'custom' && isset( $data['img_crop_style'] ) ) ? $data['img_crop_style'] : '', 'show_acf' => $data['show_acf'] ?? '', 'search_by' => $data['search_by'] ?? '', ]; $cf = Fns::is_acf(); if ( $cf && rtTPG()->hasPro() ) { $post_type = $data['post_type']; if ( $is_gutenberg && isset( $data['acf_data_lists'][ $post_type . '_cf_group' ] ) ) { $cf_group = $data['acf_data_lists'][ $post_type . '_cf_group' ]['options']; $data_set['cf_group'] = wp_list_pluck( $cf_group, 'value' ); } else { $data_set['cf_group'] = $data[ $post_type . '_cf_group' ]; } $data_set['cf_hide_empty_value'] = $data['cf_hide_empty_value']; $data_set['cf_show_only_value'] = $data['cf_show_only_value']; $data_set['cf_hide_group_title'] = $data['cf_hide_group_title']; } if ( $is_gutenberg ) { unset( $data_set['grid_column'] ); unset( $data_set['grid_column_mobile'] ); unset( $data_set['grid_column_mobile'] ); unset( $data_set['layout_style'] ); $data_set['c_image_width'] = $data['c_image_width'] ?? ''; $data_set['c_image_height'] = $data['c_image_height'] ?? ''; $data_set['grid_column'] = (array) $data['grid_column']; $data_set['layout_style'] = $data['grid_layout_style']; } return $data_set; } /** * Get Filter markup * * @param $data * * @return string */ public static function get_frontend_filter_markup( $data, $is_guten = false ) { if ( ! rtTPG()->hasPro() || ! ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show' || $data['show_sort_order'] == 'show' || $data['show_search'] == 'show' ) ) { return; } $html = null; $wrapperContainer = $wrapperClass = $itemClass = $filter_btn_item_per_page = ''; if ( 'carousel' === $data['filter_btn_style'] ) { $wrapperContainer = 'swiper'; $wrapperClass = 'swiper-wrapper'; $itemClass = 'swiper-slide'; $filter_btn_mobile = isset( $data['filter_btn_item_per_page_mobile'] ) ? $data['filter_btn_item_per_page_mobile'] : 'auto'; $filter_btn_tablet = isset( $data['filter_btn_item_per_page_tablet'] ) ? $data['filter_btn_item_per_page_tablet'] : 'auto'; $filter_btn_item_per_page = "data-per-page = '{$data['filter_btn_item_per_page']}' data-per-page-mobile = '{$filter_btn_mobile}' data-per-tablet = '{$filter_btn_tablet}'"; } $html .= "
"; if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) { $html .= "
"; } // if($data['filter_btn_style'] == 'carousel') { // $html .= "
"; // } $selectedSubTermsForButton = null; $filterType = $data['filter_type']; $post_count = ( 'yes' == $data['filter_post_count'] ) ? true : false; if ( 'show' == $data['show_taxonomy_filter'] ) { $postCountClass = ( $post_count ? " has-post-count" : null ); $allSelect = " selected"; $isTermSelected = false; $taxFilterOperator = $data['relation']; $taxonomy_label = $default_term = ''; if ( $is_guten ) { $taxFilter = $data['filter_taxonomy']; } else { $section_term_key = $data['post_type'] . '_filter_taxonomy'; $taxFilter = $data[ $section_term_key ]; } if ( $taxFilter ) { $taxonomy_details = get_taxonomy( $taxFilter ); $taxonomy_label = $taxonomy_details->label; $default_term_key = $taxFilter . '_default_terms'; $default_term = isset( $data[ $default_term_key ] ) ? $data[ $default_term_key ] : ''; } $allText = $data['tax_filter_all_text'] ? $data['tax_filter_all_text'] : __( "All ", "the-post-grid" ) . $taxonomy_label; $_taxonomies = get_object_taxonomies( $data['post_type'], 'objects' ); $terms = []; foreach ( $_taxonomies as $index => $object ) { if ( $object->name != $taxFilter ) { continue; } $setting_key = $object->name . '_ids'; if ( $is_guten && ! empty( $data['taxonomy_lists'][ $object->name ]['options'] ) ) { //This block execute if gutenberg editor has taxonomy query $terms = wp_list_pluck( $data['taxonomy_lists'][ $object->name ]['options'], 'value' ); } else if ( ! empty( $data[ $setting_key ] ) ) { //This block execute for Elementor editor has taxonomy query $terms = $data[ $setting_key ]; } else { //Execute if there is no taxonomy query $terms = get_terms( [ 'taxonomy' => $taxFilter, 'fields' => 'ids', ] ); } } $taxFilterTerms = $terms; if ( $default_term && $taxFilter ) { $isTermSelected = true; $allSelect = null; } if ( $filterType == 'dropdown' ) { $html .= "
"; $termDefaultText = $allText; $dataTerm = 'all'; $htmlButton = ""; $selectedSubTerms = null; $pCount = 0; if ( ! empty( $terms ) ) { $i = 0; foreach ( $terms as $term_id ) { $term = get_term( $term_id, $taxFilter, ARRAY_A ); $id = $term['term_id']; $pCount = $pCount + $term['count']; $sT = null; if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' ) { $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); if ( ! empty( $subTerms ) ) { $count = 0; $item = $allCount = null; foreach ( $subTerms as $stId => $t ) { $count = $count + absint( $t['count'] ); $sTPostCount = ( $post_count ? " ({$t['count']})" : null ); $item .= "{$t['name']}{$sTPostCount}"; } if ( $post_count ) { $allCount = " ({$count})"; } $sT .= ""; } if ( $default_term === $id ) { $selectedSubTerms = $sT; } } $postCount = ( $post_count ? " ({$term['count']})" : null ); if ( $default_term && $default_term == $id ) { $termDefaultText = $term['name'] . $postCount; $dataTerm = $id; } if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { if ( in_array( $id, $taxFilterTerms ) ) { $htmlButton .= "{$term['name']}{$postCount}{$sT}"; } } else { $htmlButton .= "{$term['name']}{$postCount}{$sT}"; } $i ++; } } $pAllCount = null; if ( $post_count ) { $pAllCount = " ({$pCount})"; if ( ! $default_term ) { $termDefaultText = $termDefaultText; } } if ( 'yes' == $data['tpg_hide_all_button'] ) { $htmlButton = "" . $allText . "" . $htmlButton; } $htmlButton = sprintf( '%s', $htmlButton ); $showAllhtml = ' ' . $termDefaultText . ' '; $html .= $showAllhtml . $htmlButton; $html .= '
' . $selectedSubTerms; } else { //if Button the execute //$termDefaultText = $allText; $bCount = 0; $bItems = null; if ( ! empty( $terms ) ) { foreach ( $terms as $term_id ) { $term = get_term( $term_id, $taxFilter, ARRAY_A ); if ( ! isset( $term['term_id'] ) ) { continue; } $id = $term['term_id']; $bCount = $bCount + absint( $term['count'] ); $sT = null; if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' && $data['filter_btn_style'] === 'default' && $data['filter_type'] == 'button' ) { $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); if ( ! empty( $subTerms ) ) { $sT .= "
"; foreach ( $subTerms as $stId => $t ) { $sTPostCount = ( $post_count ? " ({$t['count']})" : null ); $sT .= "{$t['name']}{$sTPostCount}"; } $sT .= "
"; if ( $default_term === $id ) { $selectedSubTermsForButton = $sT; } } } $postCount = ( $post_count ? " ({$term['count']})" : null ); $termSelected = null; if ( $isTermSelected && $id == $default_term ) { $termSelected = " selected"; } if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { if ( in_array( $id, $taxFilterTerms ) ) { $bItems .= "{$term['name']}{$postCount}{$sT}"; } } else { $bItems .= "{$term['name']}{$postCount}{$sT}"; } } } $html .= "
"; //$pCountH = ( $post_count ? " ({$bCount})" : null ); if ( 'yes' == $data['tpg_hide_all_button'] ) { $html .= "" . $allText . ""; } $html .= $bItems; $html .= "
"; if ( 'carousel' === $data['filter_btn_style'] ) { $html .= '
'; } } } // TODO: Author filter if ( 'show' == $data['show_author_filter'] ) { $user_el = $data['author']; $filterAuthors = $user_el; if ( ! empty( $user_el ) ) { $users = get_users( apply_filters( 'tpg_author_arg', [ 'include' => $user_el ] ) ); } else { $users = get_users( apply_filters( 'tpg_author_arg', [] ) ); } $allText = $allText = $data['author_filter_all_text'] ? $data['author_filter_all_text'] : __( "All Users", "the-post-grid" ); $allSelect = " selected"; //$isTermSelected = false; // if ( $default_term && $taxFilter ) { $isTermSelected = true; // $allSelect = null; // } if ( $filterType == 'dropdown' ) { $html .= "
"; $termDefaultText = $allText; $dataAuthor = 'all'; $htmlButton = ""; $htmlButton .= ''; $htmlButton .= "" . $allText . ""; if ( ! empty( $users ) ) { foreach ( $users as $user ) { $user_post_count = false; $post_count ? "(" . count_user_posts( $user->ID, $data['post_type'] ) . ")" : null; if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { if ( in_array( $user->ID, $filterAuthors ) ) { if ( $default_term == $user->ID ) { $termDefaultText = $user->display_name; $dataTerm = $user->ID; } else { $htmlButton .= "{$user->display_name} {$user_post_count}"; } } } else { if ( $default_term == $user->ID ) { $termDefaultText = $user->display_name; $dataTerm = $user->ID; } else { $htmlButton .= "{$user->display_name} {$user_post_count}"; } } } } $htmlButton .= ''; $showAllhtml = ' ' . $termDefaultText . ' '; $html .= $showAllhtml . $htmlButton; $html .= '
'; } else { $bCount = 0; $bItems = null; if ( ! empty( $users ) ) { foreach ( $users as $user ) { if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { if ( in_array( $user->ID, $filterAuthors ) ) { $bItems .= "{$user->display_name}"; } } else { $bItems .= "{$user->display_name}"; } } } $html .= "
"; // if ( 'yes' == $data['tax_filter_all_text'] ) { //$pCountH = ( $post_count ? " ({$bCount})" : null ); $html .= "" . $allText . ""; // } $html .= $bItems; $html .= "
"; } } if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) { $html .= "
"; } if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) { $html .= "
"; } // TODO: Order Filter if ( 'show' == $data['show_sort_order'] ) { $action_order = ( $data['order'] ? strtoupper( $data['order'] ) : "DESC" ); $html .= '
'; $html .= " "; $html .= '
'; } //TODO: Orderby Filter if ( 'show' == $data['show_order_by'] ) { $wooFeature = ( $data['post_type'] == "product" ? true : false ); $orders = Options::rtPostOrderBy( $wooFeature ); $action_orderby = ( ! empty( $data['orderby'] ) ? $data['orderby'] : "none" ); if ( $action_orderby == 'none' ) { $action_orderby_label = __( "Sort By", "the-post-grid" ); } else if ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) { $action_orderby_label = __( "Meta value", "the-post-grid" ); } else { $action_orderby_label = __( "By ", "the-post-grid" ) . $action_orderby; } if ( $action_orderby !== 'none' ) { $orders['none'] = __( "Sort By", "the-post-grid" ); } $html .= '
'; $html .= " {$action_orderby_label} "; $html .= ''; foreach ( $orders as $orderKey => $order ) { $html .= '' . $order . ''; } $html .= ''; $html .= '
'; } //TODO: Search Filter if ( 'show' == $data['show_search'] ) { $html .= '
'; $html .= sprintf( '', esc_html__( "Search...", 'the-post-grid' ) ); $html .= "🔍"; $html .= ""; $html .= '
'; } if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) { $html .= "
"; } $html .= "
$selectedSubTermsForButton
"; return $html; } /** * Get Excluded Taxonomy * * @return string[] */ public static function get_excluded_taxonomy() { return [ 'post_format', 'nav_menu', 'link_category', 'wp_theme', 'elementor_library_type', 'elementor_library_type', 'elementor_library_category', 'product_visibility', 'product_shipping_class', ]; } /** * Get Popup Modal Markup */ public static function get_modal_markup() { $html = null; $html .= '
'; $html .= "
"; echo $html; } /** * Get Archive page title */ public static function get_archive_title() { $queried_obj = get_queried_object(); if ( is_tag() || is_category() ) { echo esc_html( $queried_obj->name ); } else if ( is_author() ) { echo esc_html( $queried_obj->display_name ); } else if ( is_date() ) { $year = get_query_var( 'year' ); $monthnum = get_query_var( 'monthnum' ); $day = get_query_var( 'day' ); $time_string = $year . '/' . $monthnum . '/' . $day; $time_stamp = strtotime( $time_string ); echo date( get_option( 'date_format' ), $time_stamp ); } } /** * Get Last Category ID * * @return mixed */ public static function get_last_category_id() { if ( is_archive() ) { return; } $categories = get_terms( [ 'taxonomy' => 'category', 'hide_empty' => false, 'number' => 1, ] ); if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) { return $categories[0]->term_id; } } /** * @param $data * * @return string */ public static function get_dynamic_class_gutenberg( $data ) { $uniqueId = isset( $data['uniqueId'] ) ? $data['uniqueId'] : null; $uniqueClass = 'rttpg-block-postgrid rttpg-block-wrapper rttpg-block-' . $uniqueId; $dynamicClass = $uniqueClass; $dynamicClass .= ! empty( $data['align'] ) ? ' align' . $data['align'] : null; $dynamicClass .= ! empty( $data['className'] ) ? ' ' . $data['className'] : null; $dynamicClass .= ! empty( $data['full_wrapper_align']['lg'] ) ? " tpg-wrapper-align-{$data['full_wrapper_align']['lg']}" : null; $dynamicClass .= ! empty( $data['filter_type'] ) ? " tpg-filter-type-{$data['filter_type']}" : null; $dynamicClass .= ! empty( $data['show_pagination'] ) ? " pagination-visibility-{$data['show_pagination']}" : null; $dynamicClass .= ! empty( $data['ajax_pagination_type'] ) ? " ajax-pagination-type-next-prev-{$data['ajax_pagination_type']}" : null; $dynamicClass .= ! empty( $data['show_meta'] ) ? " meta-visibility-{$data['show_meta']}" : null; $dynamicClass .= ! empty( $data['section_title_style'] ) ? " section-title-style-{$data['section_title_style']}" : null; $dynamicClass .= ! empty( $data['section_title_alignment'] ) ? " section-title-align-{$data['section_title_alignment']}" : null; $dynamicClass .= ! empty( $data['hover_animation'] ) ? " img_hover_animation_{$data['hover_animation']}" : null; $dynamicClass .= ! empty( $data['title_visibility_style'] ) ? " title-{$data['title_visibility_style']}" : null; $dynamicClass .= ! empty( $data['title_position'] ) ? " title_position_{$data['title_position']}" : null; $dynamicClass .= ! empty( $data['title_hover_underline'] ) ? " title_hover_border_{$data['title_hover_underline']}" : null; $dynamicClass .= ! empty( $data['meta_position'] ) ? " meta_position_{$data['meta_position']}" : null; $dynamicClass .= ! empty( $data['author_icon_visibility'] ) ? " tpg-is-author-icon-{$data['author_icon_visibility']}" : null; $dynamicClass .= ! empty( $data['show_author_image'] ) ? " author-image-visibility-{$data['show_author_image']}" : null; $dynamicClass .= ! empty( $data['category_position'] ) ? " tpg-category-position-{$data['category_position']}" : null; $dynamicClass .= ! empty( $data['readmore_btn_style'] ) ? " readmore-btn-{$data['readmore_btn_style']}" : null; $dynamicClass .= ! empty( $data['grid_hover_overlay_type'] ) ? " grid-hover-overlay-type-{$data['grid_hover_overlay_type']}" : null; $dynamicClass .= ! empty( $data['grid_hover_overlay_height'] ) ? " grid-hover-overlay-height-{$data['grid_hover_overlay_height']}" : null; $dynamicClass .= ! empty( $data['on_hover_overlay'] ) ? " hover-overlay-height-{$data['on_hover_overlay']}" : null; $dynamicClass .= ! empty( $data['title_border_visibility'] ) ? " tpg-title-border-{$data['title_border_visibility']}" : null; $dynamicClass .= ! empty( $data['title_alignment'] ) ? " title-alignment-{$data['title_alignment']}" : null; $dynamicClass .= ! empty( $data['filter_v_alignment'] ) ? " tpg-filter-alignment-{$data['filter_v_alignment']}" : null; $dynamicClass .= ! empty( $data['border_style'] ) ? " filter-button-border-{$data['border_style']}" : null; $dynamicClass .= ! empty( $data['filter_next_prev_btn'] ) ? " filter-nex-prev-btn-{$data['filter_next_prev_btn']}" : null; $dynamicClass .= ! empty( $data['filter_h_alignment'] ) ? " tpg-filter-h-alignment-{$data['filter_h_alignment']}" : null; $dynamicClass .= ! empty( $data['is_box_border'] ) ? " tpg-el-box-border-{$data['is_box_border']}" : null; $dynamicClass .= ! empty( $data['category_style'] ) ? " tpg-cat-{$data['category_style']}" : null; //Slider layout $dynamicClass .= ! empty( $data['arrow_position'] ) ? " slider-arrow-position-{$data['arrow_position']}" : null; $dynamicClass .= ! empty( $data['dots'] ) ? " slider-dot-enable-{$data['dots']}" : null; $dynamicClass .= ! empty( $data['dots_style'] ) ? " slider-dots-style-{$data['dots_style']}" : null; $dynamicClass .= ! empty( $data['lazyLoad'] ) ? " is-lazy-load-{$data['lazyLoad']}" : null; $dynamicClass .= ! empty( $data['carousel_overflow'] ) ? " is-carousel-overflow-{$data['carousel_overflow']}" : null; $dynamicClass .= ! empty( $data['slider_direction'] ) ? " slider-direction-{$data['slider_direction']}" : null; $dynamicClass .= ! empty( $data['dots_text_align'] ) ? " slider-dots-align-{$data['dots_text_align']}" : null; $dynamicClass .= ! empty( $data['pagination_btn_space_btween'] ) && $data['pagination_btn_space_btween'] === 'space-between' ? " tpg-prev-next-space-between" : null; $dynamicClass .= ! empty( $data['pagination_btn_position'] ) && $data['pagination_btn_position'] === 'absolute' ? " tpg-prev-next-absolute" : null; $dynamicClass .= ! empty( $data['box_border_bottom'] ) && $data['box_border_bottom'] === 'enable' ? " tpg-border-bottom-enable" : null; $dynamicClass .= ! empty( $data['offset_img_position'] ) && $data['offset_img_position'] === 'offset-image-right' ? " offset-image-right" : null; $dynamicClass .= ! empty( $data['scroll_visibility'] ) && $data['scroll_visibility'] === 'yes' ? "" : " slider-scroll-hide"; $dynamicClass .= ! empty( $data['enable_external_link'] ) && $data['enable_external_link'] === 'show' ? " has-external-link" : ""; //ACF $dynamicClass .= ! empty( $data['acf_label_style'] ) ? " act-label-style-{$data['acf_label_style']}" : null; $dynamicClass .= ! empty( $data['acf_alignment'] ) && ! is_array( $data['acf_alignment'] ) ? " tpg-acf-align-{$data['acf_alignment']}" : null; return $dynamicClass; } /** * Get Section Title * * @param $data */ public static function get_section_title( $data ) { if ( 'show' != $data['show_section_title'] ) { return; } $_is_link = false; if ( ! empty( $data['section_title_link']['url'] ) ) { $_is_link = true; } ob_start(); ?>
", $data['section_title_tag'] ); ?> %s", esc_html( $archive_prefix ) ); if ( is_archive() ) { self::get_archive_title(); } else if ( is_search() ) { echo get_query_var( 's' ); } else { the_title(); } printf( "%s", esc_html( $archive_suffix ) ); } else { ?> ", $data['section_title_tag'] ); ?> '> "; ?>
$taxonomy, 'hide_empty' => 0, ] ); if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) { foreach ( $temp_terms as $term ) { $order = get_term_meta( $term->term_id, '_rt_order', true ); if ( $order === '' ) { update_term_meta( $term->term_id, '_rt_order', 0 ); } } global $wp_version; $args = [ 'taxonomy' => $taxonomy, 'orderby' => 'meta_value_num', 'meta_key' => '_rt_order', 'hide_empty' => apply_filters( 'rttpg_category_hide_empty', false ), ]; if ( $parent >= 0 && $parent !== false ) { $args['parent'] = absint( $parent ); } $args['orderby'] = 'meta_value_num'; $args['meta_key'] = '_rt_order'; $termObjs = get_terms( $args ); foreach ( $termObjs as $term ) { if ( $count ) { $terms[ $term->term_id ] = [ 'name' => $term->name, 'count' => $term->count, ]; } else { $terms[ $term->term_id ] = $term->name; } } } } return $terms; } public static function rt_get_selected_term_by_taxonomy( $taxonomy = null, $include = [], $count = false, $parent = false ) { $terms = []; if ( $taxonomy ) { $temp_terms = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => 0, ] ); if ( is_array( $temp_terms ) && ! empty( $temp_terms ) && empty( $temp_terms['errors'] ) ) { foreach ( $temp_terms as $term ) { $order = get_term_meta( $term->term_id, '_rt_order', true ); if ( $order === '' ) { update_term_meta( $term->term_id, '_rt_order', 0 ); } } global $wp_version; $args = [ 'taxonomy' => $taxonomy, 'orderby' => 'meta_value_num', 'meta_key' => '_rt_order', 'include' => $include, 'hide_empty' => false, ]; if ( $parent >= 0 && $parent !== false ) { $args['parent'] = absint( $parent ); } $args['orderby'] = 'meta_value_num'; $args['meta_key'] = '_rt_order'; $termObjs = get_terms( $args ); foreach ( $termObjs as $term ) { if ( $count ) { $terms[ $term->term_id ] = [ 'name' => $term->name, 'count' => $term->count, ]; } else { $terms[ $term->term_id ] = $term->name; } } } } return $terms; } public static function getCurrentUserRoles() { global $current_user; return $current_user->roles; } public static function rt_get_taxonomy_for_filter( $post_type = null ) { if ( ! $post_type ) { $post_type = get_post_meta( get_the_ID(), 'tpg_post_type', true ); } if ( ! $post_type ) { $post_type = 'post'; } return self::rt_get_all_taxonomy_by_post_type( $post_type ); } public static function rt_get_all_taxonomy_by_post_type( $post_type = null ) { $taxonomies = []; if ( $post_type && post_type_exists( $post_type ) ) { $taxObj = get_object_taxonomies( $post_type, 'objects' ); if ( is_array( $taxObj ) && ! empty( $taxObj ) ) { foreach ( $taxObj as $tKey => $taxonomy ) { $taxonomies[ $tKey ] = $taxonomy->label; } } } if ( $post_type == 'post' ) { unset( $taxonomies['post_format'] ); } return $taxonomies; } public static function rt_get_users() { $users = []; $u = get_users( apply_filters( 'tpg_author_arg', [] ) ); if ( ! empty( $u ) ) { foreach ( $u as $user ) { $users[ $user->ID ] = $user->display_name; } } return $users; } public static function rtFieldGenerator( $fields = [] ) { $html = null; if ( is_array( $fields ) && ! empty( $fields ) ) { $tpgField = new Field(); foreach ( $fields as $fieldKey => $field ) { $html .= $tpgField->Field( $fieldKey, $field ); } } return $html; } /** * Sanitize field value * * @param array $field * @param null $value * * @return array|null * @internal param $value */ public static function sanitize( $field = [], $value = null ) { $newValue = null; if ( is_array( $field ) ) { $type = ( ! empty( $field['type'] ) ? $field['type'] : 'text' ); if ( empty( $field['multiple'] ) ) { if ( $type == 'text' || $type == 'number' || $type == 'select' || $type == 'checkbox' || $type == 'radio' ) { $newValue = sanitize_text_field( $value ); } else if ( $type == 'url' ) { $newValue = esc_url( $value ); } else if ( $type == 'slug' ) { $newValue = sanitize_title_with_dashes( $value ); } else if ( $type == 'textarea' ) { $newValue = wp_kses_post( $value ); } else if ( $type == 'script' ) { $newValue = trim( $value ); } else if ( $type == 'colorpicker' ) { $newValue = self::sanitize_hex_color( $value ); } else if ( $type == 'image_size' ) { $newValue = []; foreach ( $value as $k => $v ) { $newValue[ $k ] = esc_attr( $v ); } } else if ( $type == 'style' ) { $newValue = []; foreach ( $value as $k => $v ) { if ( $k == 'color' ) { $newValue[ $k ] = self::sanitize_hex_color( $v ); } else { $newValue[ $k ] = self::sanitize( [ 'type' => 'text' ], $v ); } } } else { $newValue = sanitize_text_field( $value ); } } else { $newValue = []; if ( ! empty( $value ) ) { if ( is_array( $value ) ) { foreach ( $value as $key => $val ) { if ( $type == 'style' && $key == 0 ) { if ( function_exists( 'sanitize_hex_color' ) ) { $newValue = sanitize_hex_color( $val ); } else { $newValue[] = self::sanitize_hex_color( $val ); } } else { $newValue[] = sanitize_text_field( $val ); } } } else { $newValue[] = sanitize_text_field( $value ); } } } } return $newValue; } public static function sanitize_hex_color( $color ) { if ( function_exists( 'sanitize_hex_color' ) ) { return sanitize_hex_color( $color ); } else { if ( '' === $color ) { return ''; } // 3 or 6 hex digits, or the empty string. if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) { return $color; } } } public static function rtFieldGeneratorBackup( $fields = [], $multi = false ) { $html = null; if ( is_array( $fields ) && ! empty( $fields ) ) { $rtField = new Field(); if ( $multi ) { foreach ( $fields as $field ) { $html .= $rtField->Field( $field ); } } else { $html .= $rtField->Field( $fields ); } } return $html; } public static function rtSmartStyle( $fields = [] ) { $h = null; if ( ! empty( $fields ) ) { foreach ( $fields as $key => $label ) { $atts = ''; $proText = ''; $class = ''; $h .= '
'; $h .= '
'; $h .= "
"; // color. $h .= "
"; $h .= "
"; $h .= "Color"; $cValue = get_post_meta( get_the_ID(), $key . '_color', true ); $h .= ''; $h .= '
'; $h .= '
'; // Font size. $h .= "
"; $h .= "
"; $h .= "Font size"; $h .= ''; $h .= '
'; $h .= '
'; // Weight. $h .= "
"; $h .= "
"; $h .= "Weight"; $h .= ''; $h .= '
'; $h .= '
'; // Alignment. $h .= "
"; $h .= "
"; $h .= "Alignment"; $h .= ''; $h .= '
'; $h .= '
'; $h .= '
'; $h .= '
'; } } return $h; } public static function custom_variation_price( $product ) { $price = ''; $max = $product->get_variation_sale_price( 'max' ); $min = $product->get_variation_sale_price( 'min' ); if ( ! $min || $min !== $max ) { $price .= wc_price( $product->get_price() ); } if ( $max && $max !== $min ) { $price .= ' - '; $price .= wc_price( $max ); } return $price; } public static function getTPGShortCodeList() { $scList = null; $scQ = get_posts( [ 'post_type' => rtTPG()->post_type, 'order_by' => 'title', 'order' => 'DESC', 'post_status' => 'publish', 'posts_per_page' => - 1, 'meta_query' => [ [ 'key' => 'layout', 'value' => 'layout', 'compare' => 'LIKE', ], ], ] ); if ( ! empty( $scQ ) ) { foreach ( $scQ as $sc ) { $scList[ $sc->ID ] = $sc->post_title; } } return $scList; } public static function getAllTPGShortCodeList() { $scList = null; $scQ = get_posts( [ 'post_type' => rtTPG()->post_type, 'order_by' => 'title', 'order' => 'ASC', 'post_status' => 'publish', 'posts_per_page' => - 1, ] ); if ( ! empty( $scQ ) ) { foreach ( $scQ as $sc ) { $scList[ $sc->ID ] = $sc->post_title; } } return $scList; } public static function socialShare( $pLink ) { $html = null; $html .= "
"; $html .= '
'; $html .= " "; $html .= ""; $html .= ''; $html .= ''; return $html; } public static function get_image_sizes() { global $_wp_additional_image_sizes; $sizes = []; $interSizes = get_intermediate_image_sizes(); if ( ! empty( $interSizes ) ) { foreach ( get_intermediate_image_sizes() as $_size ) { if ( in_array( $_size, [ 'thumbnail', 'medium', 'large' ] ) ) { $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" ); $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" ); $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" ); } else if ( isset( $_wp_additional_image_sizes[ $_size ] ) ) { $sizes[ $_size ] = [ 'width' => $_wp_additional_image_sizes[ $_size ]['width'], 'height' => $_wp_additional_image_sizes[ $_size ]['height'], 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'], ]; } } } $imgSize = []; if ( ! empty( $sizes ) ) { $imgSize['full'] = esc_html__( 'Full Size', 'the-post-grid' ); foreach ( $sizes as $key => $img ) { $imgSize[ $key ] = ucfirst( $key ) . " ({$img['width']}*{$img['height']})"; } } return apply_filters( 'tpg_image_sizes', $imgSize ); } public static function getFeatureImageSrc( $post_id = null, $fImgSize = 'medium', $mediaSource = 'feature_image', $defaultImgId = null, $customImgSize = [], $img_Class = '' ) { global $post; $imgSrc = null; $img_class = 'rt-img-responsive '; if ( $img_Class ) { $img_class .= $img_Class; } $post_id = ( $post_id ? absint( $post_id ) : $post->ID ); $alt = get_the_title( $post_id ); $image = null; $cSize = false; if ( $fImgSize == 'rt_custom' ) { $fImgSize = 'full'; $cSize = true; } if ( $mediaSource == 'feature_image' ) { if ( $aID = get_post_thumbnail_id( $post_id ) ) { $image = wp_get_attachment_image( $aID, $fImgSize, '', [ 'class' => $img_class, 'loading' => false, ] ); $imgSrc = wp_get_attachment_image_src( $aID, $fImgSize ); if ( ! empty( $imgSrc ) && $img_Class == 'swiper-lazy' ) { $image = '' . esc_attr( $alt ) . '
'; } $imgSrc = ! empty( $imgSrc ) ? $imgSrc[0] : $imgSrc; } } else if ( $mediaSource == 'first_image' ) { if ( $img = preg_match_all( '//i', get_the_content( $post_id ), $matches ) ) { $imgSrc = $matches[1][0]; $size = ''; if ( strpos( $imgSrc, site_url() ) !== false ) { $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc ); } else { $imgAbs = ABSPATH . $imgSrc; } $imgAbs = apply_filters( 'rt_tpg_sc_first_image_src', $imgAbs ); if ( file_exists( $imgAbs ) ) { $info = getimagesize( $imgAbs ); $size = isset( $info[3] ) ? $info[3] : ''; } $image = '' . esc_attr( $alt ) . ''; if ( $img_Class == 'swiper-lazy' ) { $image = '' . esc_attr( $alt ) . '
'; } } } if ( ! $imgSrc && $defaultImgId ) { $image = wp_get_attachment_image( $defaultImgId, $fImgSize ); } if ( $imgSrc && $cSize ) { $w = ( ! empty( $customImgSize[0] ) ? absint( $customImgSize[0] ) : null ); $h = ( ! empty( $customImgSize[1] ) ? absint( $customImgSize[1] ) : null ); $c = ( ! empty( $customImgSize[2] ) && $customImgSize[2] == 'soft' ? false : true ); if ( $w && $h ) { $post_thumb_id = get_post_thumbnail_id( $post_id ); if ( $post_thumb_id ) { $featured_image = wp_get_attachment_image_src( $post_thumb_id, 'full' ); $w = $featured_image[1] < $w ? $featured_image[1] : $w; $h = $featured_image[2] < $h ? $featured_image[2] : $h; } $imgSrc = self::rtImageReSize( $imgSrc, $w, $h, $c ); if ( $img_Class !== 'swiper-lazy' ) { $image = '' . esc_attr( $alt ) . ''; } else { $image = '' . esc_attr( $alt ) . '
'; } } } return $image; } public static function getFeatureImageUrl( $post_id = null, $fImgSize = 'medium' ) { $image = $imgSrc = null; if ( $aID = get_post_thumbnail_id( $post_id ) ) { $image = wp_get_attachment_image_src( $aID, $fImgSize ); } if ( is_array( $image ) ) { $imgSrc = $image[0]; } return $imgSrc; } public static function tpgCharacterLimit( $limit, $content ) { $limit ++; $text = ''; if ( mb_strlen( $content ) > $limit ) { $subex = mb_substr( $content, 0, $limit ); $exwords = explode( ' ', $subex ); $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); if ( $excut < 0 ) { $text = mb_substr( $subex, 0, $excut ); } else { $text = $subex; } } else { $text = $content; } return $text; } public static function get_the_excerpt( $post_id, $data = [] ) { $type = $data['excerpt_type']; $post = get_post( $post_id ); if ( empty( $post ) ) { return ''; } if ( $type == 'full' ) { ob_start(); the_content(); $content = ob_get_clean(); return apply_filters( 'tpg_content_full', $content, $post_id, $data ); } else { if ( class_exists( 'ET_GB_Block_Layout' ) ) { $defaultExcerpt = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 ); } else if ( defined( 'WPB_VC_VERSION' ) ) { $the_content = $post->post_excerpt ?: wp_trim_words( $post->post_content, 55 ); $shortcode_tags = [ 'VC_COLUMN_INNTER' ]; $values = array_values( $shortcode_tags ); $exclude_codes = implode( '|', $values ); $defaultExcerpt = trim( preg_replace( "~(?:\[/?)(?!(?:$exclude_codes))[^/\]]+/?\]~s", '', $the_content ) ); } else { $defaultExcerpt = get_the_excerpt( $post_id ); } $limit = isset( $data['excerpt_limit'] ) && $data['excerpt_limit'] ? abs( $data['excerpt_limit'] ) : 0; $more = $data['excerpt_more_text']; $excerpt = preg_replace( '`\[[^\]]*\]`', '', $defaultExcerpt ); $excerpt = strip_shortcodes( $excerpt ); $excerpt = preg_replace( '`[[^]]*]`', '', $excerpt ); $excerpt = str_replace( '…', '', $excerpt ); if ( $limit ) { $excerpt = wp_strip_all_tags( $excerpt ); if ( $type == 'word' ) { $limit = $limit + 1; $rawExcerpt = $excerpt; $excerpt = explode( ' ', $excerpt, $limit ); if ( count( $excerpt ) >= $limit ) { array_pop( $excerpt ); $excerpt = implode( ' ', $excerpt ); } else { $excerpt = $rawExcerpt; } } else { $excerpt = self::tpgCharacterLimit( $limit, $excerpt ); } $excerpt = stripslashes( $excerpt ); } else { $allowed_html = [ 'a' => [ 'href' => [], 'title' => [], ], 'strong' => [], 'b' => [], 'br' => [ [] ], ]; $excerpt = nl2br( wp_kses( $excerpt, $allowed_html ) ); } $excerpt = ( $more ? rtrim($excerpt, " .,-_") . $more : $excerpt ); return apply_filters( 'tpg_get_the_excerpt', $excerpt, $post_id, $data, $defaultExcerpt ); } } public static function get_the_title( $post_id, $data = [] ) { $title = $originalTitle = get_the_title( $post_id ); $limit = isset( $data['title_limit'] ) ? absint( $data['title_limit'] ) : 0; $limit_type = isset( $data['title_limit_type'] ) ? trim( $data['title_limit_type'] ) : 'character'; if ( $limit ) { if ( $limit_type == 'word' ) { $limit = $limit + 1; $title = explode( ' ', $title, $limit ); if ( count( $title ) >= $limit ) { array_pop( $title ); $title = implode( ' ', $title ); } else { $title = $originalTitle; } } else { if ( $limit > 0 && strlen( $title ) > $limit ) { $title = mb_substr( $title, 0, $limit, 'utf-8' ); $title = preg_replace( '/\W\w+\s*(\W*)$/', '$1', $title ); } } } return apply_filters( 'tpg_get_the_title', $title, $post_id, $data, $originalTitle ); } public static function rt_pagination( $postGrid, $range = 4, $ajax = false ) { $html = $pages = null; $showitems = ( $range * 2 ) + 1; $wpQuery = $postGrid; global $wp_query; if ( empty( $wpQuery ) ) { $wpQuery = $wp_query; } $pages = ! empty( $wpQuery->max_num_pages ) ? $wpQuery->max_num_pages : 1; $paged = ! empty( $wpQuery->query['paged'] ) ? $wpQuery->query['paged'] : 1; if ( is_front_page() ) { $paged = ! empty( $wp_query->query['paged'] ) ? $wp_query->query['paged'] : 1; } $ajaxClass = null; $dataAttr = null; if ( $ajax ) { $ajaxClass = ' rt-ajax'; $dataAttr = "data-paged='1'"; } if ( 1 != $pages ) { $html .= '
'; $html .= ''; $html .= '
'; } return $html; } public static function rt_pagination_ajax( $scID, $range = 4, $pages = '' ) { $html = null; $html .= "
"; $html .= '
'; return $html; } /** * Call the Image resize model for resize function * * @param $url * @param null $width * @param null $height * @param null $crop * @param bool|true $single * @param bool|false $upscale * * @return array|bool|string * @throws Exception * @throws Rt_Exception */ public static function rtImageReSize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { $rtResize = new ReSizer(); return $rtResize->process( $url, $width, $height, $crop, $single, $upscale ); } /* Convert hexdec color string to rgb(a) string */ public static function rtHex2rgba( $color, $opacity = .5 ) { $default = 'rgb(0,0,0)'; // Return default if no color provided. if ( empty( $color ) ) { return $default; } // Sanitize $color if "#" is provided. if ( $color[0] == '#' ) { $color = substr( $color, 1 ); } // Check if color has 6 or 3 characters and get values. if ( strlen( $color ) == 6 ) { $hex = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ]; } else if ( strlen( $color ) == 3 ) { $hex = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ]; } else { return $default; } // Convert hexadec to rgb. $rgb = array_map( 'hexdec', $hex ); // Check if opacity is set(rgba or rgb). if ( $opacity ) { if ( absint( $opacity ) > 1 ) { $opacity = 1.0; } $output = 'rgba(' . implode( ',', $rgb ) . ',' . $opacity . ')'; } else { $output = 'rgb(' . implode( ',', $rgb ) . ')'; } // Return rgb(a) color string. return $output; } public static function meta_exist( $meta_key, $post_id = null, $type = 'post' ) { if ( ! $post_id ) { return false; } return metadata_exists( $type, $post_id, $meta_key ); } public static function get_offset_col( $col ) { $return = [ 'big' => 6, 'small' => 6, ]; if ( $col ) { if ( $col == 12 ) { $return['big'] = 12; $return['small'] = 12; } else if ( $col == 6 ) { $return['big'] = 6; $return['small'] = 6; } else if ( $col == 4 ) { $return['big'] = 4; $return['small'] = 8; } } return $return; } public static function formatSpacing( $data = '' ) { if ( ! empty( $data ) ) { $spacing = array_filter( explode( ',', $data ), 'is_numeric' ); if ( count( $spacing ) > 4 ) { $spacing = array_slice( $spacing, 0, 4, true ); } $data = implode( 'px ', $spacing ); } return $data; } public static function layoutStyle( $layoutID, $scMeta, $layout, $scId = null ) { $css = null; $css .= "'; return $css; } public static function get_meta_keys( $post_type ) { $meta_keys = self::generate_meta_keys( $post_type ); return $meta_keys; } public static function generate_meta_keys( $post_type ) { $meta_keys = []; if ( $post_type ) { global $wpdb; $query = "SELECT DISTINCT($wpdb->postmeta.meta_key) FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id WHERE $wpdb->posts.post_type = '%s' AND $wpdb->postmeta.meta_key != '' AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)' AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'"; $meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) ); } return $meta_keys; } public static function remove_all_shortcode( $content ) { return preg_replace( '#\[[^\]]+\]#', '', $content ); } public static function remove_divi_shortcodes( $content ) { $content = preg_replace( '/\[\/?et_pb.*?\]/', '', $content ); return $content; } public static function is_acf() { $plugin = null; if ( class_exists( 'acf' ) ) { $plugin = 'acf'; } return $plugin; } public static function is_woocommerce() { $plugin = null; if ( class_exists( 'WooCommerce' ) ) { $plugin = 'woo'; } return $plugin; } public static function get_groups_by_post_type( $post_type ) { $post_type = $post_type ? $post_type : 'post'; $groups = []; $plugin = self::is_acf(); switch ( $plugin ) { case 'acf': $groups = self::get_groups_by_post_type_acf( $post_type ); break; } return $groups; } /** * Get ACF post group * * @param $post_type * * @return array */ public static function get_groups_by_post_type_acf( $post_type ) { $groups = []; $groups_q = get_posts( [ 'post_type' => 'acf-field-group', 'posts_per_page' => - 1, ] ); if ( ! empty( $groups_q ) ) { foreach ( $groups_q as $group ) { $c = $group->post_content ? unserialize( $group->post_content ) : []; $flag = false; if ( ! empty( $c['location'] ) ) { foreach ( $c['location'] as $rules ) { foreach ( $rules as $rule ) { if ( 'all' === $post_type ) { if ( ( ! empty( $rule['param'] ) && $rule['param'] == 'post_type' ) && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' ) ) { $flag = true; } } else { if ( ( ! empty( $rule['param'] ) && ( $rule['param'] == 'post_type' || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) ) && ( ! empty( $rule['operator'] ) && $rule['operator'] == '==' ) && ( ! empty( $rule['value'] ) && ( $rule['value'] == $post_type || ( $rule['param'] == 'post_category' && 'post' == $post_type ) ) ) ) { $flag = true; } } } } } if ( $flag ) { $groups[ $group->ID ] = $group->post_title; } } } return $groups; } /** * Get Post view count meta key * * @return string */ public static function get_post_view_count_meta_key() { $count_key = 'tpg-post-view-count'; return apply_filters( 'tpg_post_view_count', $count_key ); } /** * Elementor Functionality * ************************************************ */ /** * Default layout style check * * @param $data * * @return bool */ public static function el_ignore_layout( $data ) { if ( isset( $data['category'] ) && 'category' == $data['category'] ) { return true; } $all_layout_list = [ 'grid-layout4', 'grid-layout5', 'grid-layout5-2', 'grid-layout6', 'grid-layout6-2', 'list-layout4', 'list-layout5', 'grid_hover-layout5', 'grid_hover-layout6', 'grid_hover-layout7', 'grid_hover-layout8', 'grid_hover-layout9', 'grid_hover-layout10', 'grid_hover-layout5-2', 'grid_hover-layout6-2', 'grid_hover-layout7-2', 'grid_hover-layout9-2', 'grid_hover-layout11', 'slider-layout3', 'slider-layout5', 'slider-layout6', 'slider-layout7', 'slider-layout8', 'slider-layout9', 'slider-layout11', 'slider-layout12', ]; if ( 'default' == $data['category_position'] && in_array( $data['layout'], $all_layout_list ) ) { return false; } return true; } /** * Get Post Link * * @param $data * @param $pID * * @return array */ public static function get_post_link( $pID, $data ) { $link_class = $link_start = $link_end = $readmore_link_start = $readmore_link_end = null; $external_link = get_post_meta($pID, 'tpg_read_more', true); if ( 'default' == $data['post_link_type'] ) { $link_class = 'tpg-post-link'; $link_start = $readmore_link_start = sprintf( '', absint( $pID ), esc_url( $external_link['url'] ?? get_permalink() ), esc_attr( $link_class ), esc_attr( $external_link['target'] ?? $data['link_target'] ) ); $link_end = $readmore_link_end = ''; } else if ( 'popup' == $data['post_link_type'] ) { $link_class = 'tpg-single-popup tpg-post-link'; if ( did_action( 'elementor/loaded' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { $link_class = 'tpg-post-link'; } $link_start = $readmore_link_start = sprintf( '', absint( $pID ), esc_url( get_permalink() ), esc_attr( $link_class ), esc_attr( $data['link_target'] ) ); $link_end = $readmore_link_end = ''; } else if ( 'multi_popup' == $data['post_link_type'] ) { $link_class = 'tpg-multi-popup tpg-post-link'; $link_start = $readmore_link_start = sprintf( '', absint( $pID ), esc_url( get_permalink() ), esc_attr( $link_class ), esc_attr( $data['link_target'] ) ); $link_end = $readmore_link_end = ''; } else { $link_class = 'tpg-post-link'; $readmore_link_start = sprintf( '', absint( $pID ), esc_url( get_permalink() ), esc_attr( $link_class ), esc_attr( $data['link_target'] ) ); $readmore_link_end = ''; } return [ 'link_start' => $link_start, 'link_end' => $link_end, 'readmore_link_start' => $readmore_link_start, 'readmore_link_end' => $readmore_link_end, ]; } /** * Get Post Type * * @return string[]|\WP_Post_Type[] */ public static function get_post_types() { $post_types = get_post_types( [ 'public' => true, 'show_in_nav_menus' => true, ], 'objects' ); $post_types = wp_list_pluck( $post_types, 'label', 'name' ); $exclude = [ 'attachment', 'revision', 'nav_menu_item', 'elementor_library', 'tpg_builder', 'e-landing-page' ]; foreach ( $exclude as $ex ) { unset( $post_types[ $ex ] ); } if ( ! rtTPG()->hasPro() ) { $post_types = [ 'post' => $post_types['post'], 'page' => $post_types['page'], ]; } return $post_types; } public static function rt_get_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) { $terms = get_the_terms( $post_id, $taxonomy ); if ( is_wp_error( $terms ) ) { return $terms; } if ( empty( $terms ) ) { return false; } $links = []; foreach ( $terms as $term ) { $meta_color = get_term_meta( $term->term_id, 'rttpg_category_color', true ); $meta_color_code = $meta_color ? "--tpg-primary-color:#" . ltrim( $meta_color, '#' ) : ''; $link = get_term_link( $term, $taxonomy ); if ( is_wp_error( $link ) ) { return $link; } if ( rtTPG()->hasPro() ) { $links[] = ''; } else { $links[] = ''; } } return $before . implode( $sep, $links ) . $after; } /** * Get Post Meta HTML for Elementor * * @param $post_id * @param $data * * @return html markup */ public static function get_post_meta_html( $post_id, $data ) { global $post; $author_id = $post->post_author; $author_name = get_the_author_meta( 'display_name', $post->post_author ); $author = apply_filters( 'rttpg_author_link', sprintf( '%s', get_author_posts_url( $author_id ), $author_name ) ); $comments_number = get_comments_number( $post_id ); $comment_label = ''; if ( isset( $data['show_comment_count_label'] ) && $data['show_comment_count_label'] ) { $comment_label = $data['comment_count_label_singular']; if ( $comments_number > 1 ) { $comment_label = $data['comment_count_label_plural']; } } $comments_text = sprintf( '%s (%s)', esc_html( $comment_label ), number_format_i18n( $comments_number ) ); $date = get_the_date(); //Category and Tags Management $_cat_id = isset( $data['post_type'] ) ? $data['post_type'] . '_taxonomy' : 'category'; $_tag_id = isset( $data['post_type'] ) ? $data['post_type'] . '_tags' : 'post_tag'; $_category_id = isset( $data[ $_cat_id ] ) ? $data[ $_cat_id ] : 'category'; $_tag_id = isset( $data[ $_tag_id ] ) ? $data[ $_tag_id ] : 'post_tag'; $categories = self::rt_get_the_term_list( $post_id, $_category_id, null, ',' ); $tags = self::rt_get_the_term_list( $post_id, $_tag_id, null, ',' ); $count_key = self::get_post_view_count_meta_key(); $get_view_count = get_post_meta( $post_id, $count_key, true ); $meta_separator = ( $data['meta_separator'] && 'default' !== $data['meta_separator'] ) ? sprintf( "%s", $data['meta_separator'] ) : null; // Author Meta. $post_meta_html = []; ob_start(); if ( 'show' === $data['show_author'] ) { $is_author_avatar = null; if ( 'icon' !== $data['show_author_image'] ) { $is_author_avatar = 'has-author-avatar'; } ?> 'true' ] ); } else { echo ""; } } } } if ( $data['author_prefix'] ) { echo "" . esc_html( $data['author_prefix'] ) . ''; } echo wp_kses( $author, self::allowedHtml() ); ?> hasPro() ) { $category_condition = ( $categories && 'show' == $data['show_category'] ); } if ( $category_condition ) { ?> 'true' ] ); } else { echo ""; } } echo wp_kses( $categories, self::allowedHtml( 'basic' ) ); ?> 'true' ] ); } else { echo ""; } } ?> 'true' ] ); } else { echo ""; } } echo wp_kses( $tags, self::allowedHtml() ); ?> 'true' ] ); } else { echo ""; } } echo wp_kses( $comments_text, self::allowedHtml() ); ?> hasPro() && 'show' == $data['show_post_count'] && ! empty( $get_view_count ) ) { ?> 'true' ] ); } else { echo ""; } } echo wp_kses( $get_view_count, self::allowedHtml() ); ?> [ 'href' => [], 'title' => [], 'data-id' => [], 'target' => [], 'class' => [], ], 'strong' => [], 'b' => [], 'br' => [ [] ], ]; return wp_kses( $string, $allowed_html ); } /** * Get Elementor Post Title for Elementor * * @param $title_tag * @param $title * @param $link_start * @param $link_end * @param $data */ public static function get_el_post_title( $title_tag, $title, $link_start, $link_end, $data ) { echo '
'; if ( rtTPG()->hasPro() && 'above_title' === $data['category_position'] || ! self::el_ignore_layout( $data ) ) { self::get_el_thumb_cat( $data, 'cat-above-title' ); } printf( '<%s class="entry-title">', esc_attr( $title_tag ) ); self::print_html( $link_start ); self::print_html( $title ); self::print_html( $link_end ); printf( '', esc_attr( $title_tag ) ); echo '
'; } static function get_el_thumb_cat( $data, $class = 'cat-over-image' ) { if ( ! ( 'show' == $data['show_meta'] && 'show' == $data['show_category'] ) ) { return; } $pID = get_the_ID(); $_cat_id = $data['post_type'] . '_taxonomy'; $_post_taxonomy = isset( $data[ $_cat_id ] ) ? $data[ $_cat_id ] : 'category'; $categories = self::rt_get_the_term_list( $pID, $_post_taxonomy, null, ',' ); $category_position = $data['category_position']; if ( in_array( $data['layout'], [ 'grid-layout4', 'slider-layout3', 'grid_hover-layout11' ] ) && 'default' === $data['category_position'] ) { $category_position = 'top_left'; } ?>
" : null; ?>
/i', get_the_content( $post_id ), $matches ) ) { $imgSrc = $matches[1][0]; $size = ''; $imgAbs = str_replace( trailingslashit( site_url() ), ABSPATH, $imgSrc ); if ( file_exists( $imgAbs ) ) { $info = getimagesize( $imgAbs ); $size = isset( $info[3] ) ? $info[3] : ''; } $attachment_id = attachment_url_to_postid( $imgSrc ); $alt_text = null; if ( ! empty( $attachment_id ) ) { $alt_text = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ); } $alt = $alt_text ? $alt_text : get_the_title( $post_id ); if ( $type == 'markup' ) { if ( $imgClass !== 'swiper-lazy' ) { return "{$alt}"; } else { return "{$alt}"; } } else { return $imgSrc; } } } /** * Get post thumbnail html * * @param $pID * @param $data * @param $link_start * @param $link_end * @param false $offset_size */ public static function get_post_thumbnail( $pID, $data, $link_start, $link_end, $offset_size = false ) { $thumb_cat_condition = ( ! ( 'above_title' === $data['category_position'] || 'default' === $data['category_position'] ) ); if ( 'grid-layout4' === $data['layout'] && 'default' === $data['category_position'] ) { $thumb_cat_condition = true; } else if ( in_array( $data['layout'], [ 'grid-layout4', 'grid_hover-layout11', 'slider-layout3' ] ) && 'default' === $data['category_position'] ) { $thumb_cat_condition = true; } if ( rtTPG()->hasPro() && $data['show_category'] == 'show' && $thumb_cat_condition && 'with_meta' !== $data['category_position'] ) { self::get_el_thumb_cat( $data ); } $img_link = get_the_post_thumbnail_url( $pID, 'full' ); $img_size_key = 'image_size'; if ( $offset_size ) { $img_size_key = 'image_offset_size'; } $lazy_load = ( $data['prefix'] == 'slider' && $data['lazy_load'] == 'yes' ) ? true : false; $lazy_class = 'rt-img-responsive'; if ( $lazy_load ) { $lazy_class = 'swiper-lazy'; } echo 'yes' === $data['is_thumb_linked'] ? self::print_html( $link_start ) : null; if ( has_post_thumbnail() && 'feature_image' === $data['media_source'] ) { $fImgSize = $data['image_size']; if ( $offset_size ) { echo get_the_post_thumbnail( $pID, $data['image_offset'] ); } else { if ( $data['image_size'] !== 'custom' ) { $attachment_id = get_post_thumbnail_id( $pID ); $thumb_info = wp_get_attachment_image_src( $attachment_id, $fImgSize ); $thumb_alt = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ); if ( $lazy_load ) { ?> <?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ); ?> <?php echo esc_attr( $thumb_alt ? $thumb_alt : the_title() ); ?> 'rt-img-responsive' ] ); } if ( ! empty( $data['default_image'] ) && isset( $data['default_image']['url'] ) ) { $img_link = $data['default_image']['url']; } } ?>
'true' ] ); } else { echo ""; } ?>
hasPro() && self::is_acf() ) ) { return; } if ( isset( $data['show_acf'] ) && 'show' == $data['show_acf'] ) { $cf_group = $data['cf_group']; $format = [ 'hide_empty' => ( isset( $data['cf_hide_empty_value'] ) && $data['cf_hide_empty_value'] ) ? 'yes' : '', 'show_value' => ( isset( $data['cf_show_only_value'] ) && $data['cf_show_only_value'] ) ? '' : 'yes', 'hide_group_title' => ( isset( $data['cf_hide_group_title'] ) && $data['cf_hide_group_title'] ) ? '' : 'yes', ]; if ( ! empty( $cf_group ) ) { $acf_html = "
"; $acf_html .= \RT\ThePostGridPro\Helpers\Functions::get_cf_formatted_fields( $cf_group, $format, $pID ); $acf_html .= '
'; if ( $return_type ) { self::print_html( $acf_html, true ); } else { return $acf_html; } } } } /** * Get Read More Button * * @param $data * @param $readmore_link_start * @param $readmore_link_end * * @return void */ public static function get_read_more_button( $data, $readmore_link_start, $readmore_link_end, $type = 'elementor' ) { ?>
hasPro() && ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show' || $data['show_sort_order'] == 'show' || $data['show_search'] == 'show' || ( $data['show_pagination'] == 'show' && $data['pagination_type'] != 'pagination' ) ) ) { return true; } return false; } //Get Custom post category: public static function tpg_get_categories_by_id( $cat = 'category' ) { $terms = get_terms( [ 'taxonomy' => $cat, 'hide_empty' => true, ] ); $options = []; if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { $options[ $term->term_id ] = $term->name; } } return $options; } /** * Gutenberg Functionality * :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ /** * Get Post Types. * * @since 1.0.9 */ public static function get_post_types_guten() { $post_types = get_post_types( [ 'public' => true, 'show_in_rest' => true, ], 'objects' ); $options = []; foreach ( $post_types as $post_type ) { if ( 'product' === $post_type->name ) { continue; } if ( 'attachment' === $post_type->name ) { continue; } if ( 'page' === $post_type->name ) { continue; } $options[] = [ 'value' => $post_type->name, 'label' => $post_type->label, ]; } return $options; } /** * Get all taxonomies. * * @since 1.0.9 */ public static function get_all_taxonomy_guten() { $post_types = Fns::get_post_types(); $taxonomies = get_taxonomies( [], 'objects' ); $all_taxonomies = []; foreach ( $taxonomies as $taxonomy => $object ) { if ( ! isset( $object->object_type[0] ) || ! in_array( $object->object_type[0], array_keys( $post_types ) ) || in_array( $taxonomy, Fns::get_excluded_taxonomy() ) ) { continue; } $all_taxonomies[ $taxonomy ] = Fns::tpg_get_categories_by_id( $taxonomy ); } return $all_taxonomies; } /** * Get all image sizes. * * @since 1.0.9 */ public static function get_all_image_sizes_guten() { global $_wp_additional_image_sizes; $sizes = get_intermediate_image_sizes(); $image_sizes = []; $image_sizes[] = [ 'value' => 'full', 'label' => esc_html__( 'Full', 'the-post-grid' ), ]; foreach ( $sizes as $size ) { if ( in_array( $size, [ 'thumbnail', 'medium', 'medium_large', 'large' ], true ) ) { $image_sizes[] = [ 'value' => $size, 'label' => ucwords( trim( str_replace( [ '-', '_' ], [ ' ', ' ' ], $size ) ) ), ]; } else { $image_sizes[] = [ 'value' => $size, 'label' => sprintf( '%1$s (%2$sx%3$s)', ucwords( trim( str_replace( [ '-', '_' ], [ ' ', ' ' ], $size ) ) ), $_wp_additional_image_sizes[ $size ]['width'], $_wp_additional_image_sizes[ $size ]['height'] ), ]; } } if ( rtTPG()->hasPro() ) { $image_sizes[] = [ 'value' => 'custom', 'label' => esc_html__( 'Custom', 'the-post-grid' ), ]; } return apply_filters( 'tpg_image_size_guten', $image_sizes ); } /** * Prints HTML. * * @param string $html HTML. * @param bool $allHtml All HTML. * * @return mixed */ public static function print_html( $html, $allHtml = false ) { if ( $allHtml ) { echo stripslashes_deep( $html ); } else { echo wp_kses_post( stripslashes_deep( $html ) ); } } /** * Allowed HTML for wp_kses. * * @param string $level Tag level. * * @return mixed */ public static function allowedHtml( $level = 'basic' ) { $allowed_html = []; switch ( $level ) { case 'basic': $allowed_html = [ 'b' => [ 'class' => [], 'id' => [], ], 'i' => [ 'class' => [], 'id' => [], ], 'u' => [ 'class' => [], 'id' => [], ], 'br' => [ 'class' => [], 'id' => [], ], 'em' => [ 'class' => [], 'id' => [], ], 'span' => [ 'class' => [], 'id' => [], ], 'strong' => [ 'class' => [], 'id' => [], ], 'hr' => [ 'class' => [], 'id' => [], ], 'a' => [ 'href' => [], 'title' => [], 'class' => [], 'id' => [], 'target' => [], 'style' => [], ], 'div' => [ 'class' => [], 'id' => [], ], ]; break; case 'advanced': $allowed_html = [ 'b' => [ 'class' => [], 'id' => [], ], 'i' => [ 'class' => [], 'id' => [], ], 'u' => [ 'class' => [], 'id' => [], ], 'br' => [ 'class' => [], 'id' => [], ], 'em' => [ 'class' => [], 'id' => [], ], 'span' => [ 'class' => [], 'id' => [], ], 'strong' => [ 'class' => [], 'id' => [], ], 'hr' => [ 'class' => [], 'id' => [], ], 'a' => [ 'href' => [], 'title' => [], 'class' => [], 'id' => [], 'data-id' => [], 'target' => [], ], 'input' => [ 'type' => [], 'name' => [], 'class' => [], 'value' => [], ], ]; break; case 'image': $allowed_html = [ 'img' => [ 'src' => [], 'data-src' => [], 'alt' => [], 'height' => [], 'width' => [], 'class' => [], 'id' => [], 'style' => [], 'srcset' => [], 'loading' => [], 'sizes' => [], ], 'div' => [ 'class' => [], ], ]; break; case 'anchor': $allowed_html = [ 'a' => [ 'href' => [], 'title' => [], 'class' => [], 'id' => [], 'style' => [], ], ]; break; default: // code... break; } return $allowed_html; } /** * Definition for wp_kses. * * @param string $string String to check. * @param string $level Tag level. * * @return mixed */ public static function htmlKses( $string, $level ) { if ( empty( $string ) ) { return; } return wp_kses( $string, self::allowedHtml( $level ) ); } /** * Insert Array Item in specific position * * @param $array * @param $position * @param $insert_array * * @return void */ public static function array_insert( &$array, $position, $insert_array ) { $first_array = array_splice( $array, 0, $position + 1 ); $array = array_merge( $first_array, $insert_array, $array ); } /** * tpg_option * * @param $option_name * @param $default_value * * @return string */ public static function tpg_option( $option_name, $default_value = '' ) { $settings = get_option( rtTPG()->options['settings'] ); if ( ! empty( $settings[ $option_name ] ) ) { return $settings[ $option_name ]; } else if ( $default_value ) { return $default_value; } return ''; } /** * change_icon * * @param $fontawesome * @param $flaticon * @param $default_class * * @return mixed|string */ public static function change_icon( $fontawesome, $flaticon, $default_class = '' ) { if ( self::tpg_option( 'tpg_icon_font' ) === 'fontawesome' ) { return $fontawesome . ' ' . $default_class; } else { return 'flaticon-tpg-' . $flaticon . ' ' . $default_class; } } }