* @copyright Copyright (c) 2018, Pixelative */ // Exit if accessed directly. if( !defined('ABSPATH') ) { exit; } if( !function_exists( 'amp_wp_locate_template' ) ) : /** * Retrieve the Name of the Highest Priority Amp Template File That Exists. * * @see locate_template for more doc * * @param string|array $template_names Template file(s) to search for, in order. * @param bool $load If TRUE the Template File Will Be Loaded If It Is Found. * @param bool $require_once Whether to Require_once or Require. Default TRUE. Has No Effect If $load Is FALSE. * * @since 1.0.0 * * @return string The template filename if one is located. */ function amp_wp_locate_template( $template_names, $load = FALSE, $require_once = TRUE ) { $wp_theme_can_override = current_theme_supports( 'amp-wp-template' ); /** * Scan WordPress theme directory at first, if override feature was enabled */ if( $wp_theme_can_override ) { $scan_directories = array( STYLESHEETPATH . '/' . AMPWP_OVERRIDE_TPL_DIR . '/', TEMPLATEPATH . '/' . AMPWP_OVERRIDE_TPL_DIR . '/', amp_wp_get_template_directory() ); } else { $scan_directories = array( amp_wp_get_template_directory(), STYLESHEETPATH . '/' . AMPWP_OVERRIDE_TPL_DIR . '/', TEMPLATEPATH . '/' . AMPWP_OVERRIDE_TPL_DIR . '/', ); } $scan_directories = array_unique( array_filter( $scan_directories ) ); foreach( $scan_directories as $theme_directory ) { if( $theme_file_path = amp_wp_load_template( $template_names, $theme_directory, $load, $require_once ) ) { return $theme_file_path; } } } endif; if( !function_exists( 'amp_wp_load_template' ) ) : /** * Require the Template File * * @param string|array $templates * @param string $theme_directory base directory. scan $templates files into this directory * @param bool $load * @param bool $require_once * * @see amp_wp_locate_template for parameters documentation * * @since 1.0.0 * * @return bool|string */ function amp_wp_load_template( $templates, $theme_directory, $load = FALSE, $require_once = TRUE ) { foreach ( (array) $templates as $theme_file ) { $theme_file = ltrim( $theme_file, '/' ); $theme_directory = trailingslashit( $theme_directory ); if( file_exists( $theme_directory . $theme_file ) ) { if( $load ) { if( $require_once ) { require_once $theme_directory . $theme_file; } else { require $theme_directory . $theme_file; } } return $theme_directory . $theme_file; } } return FALSE; } endif; // Start Template Hierarchy Related Functions if( !function_exists( 'amp_wp_head' ) ) : /** * Fire the amp_wp_head action. * * @since 1.0.0 */ function amp_wp_head() { do_action( 'amp_wp_template_head' ); } endif; if( !function_exists( 'amp_wp_footer' ) ) : /** * Fire the amp_wp_footer action. * * @since 1.0.0 */ function amp_wp_footer() { do_action( 'amp_wp_template_footer' ); } endif; if( !function_exists( 'amp_wp_body_class' ) ) : /** * Display the classes for the body element. * * @param string|array $class One or more classes to add to the class list. * * @version 1.0.0 * @since 1.0.0 */ function amp_wp_body_class( $class = '' ) { echo 'class="' . join( ' ', get_body_class( $class ) ) . '"'; } endif; if( !function_exists( 'amp_wp_get_header' ) ) { /** * Load footer template. * * @param string $name The name of the specialised header. * * @since 1.0.0 */ function amp_wp_get_header( $name = NULL ) { $templates = array(); $name = (string) $name; if ( '' !== $name ) { $templates[] = "header-{$name}.php"; } $templates[] = 'header.php'; amp_wp_locate_template( $templates, TRUE ); } } if( !function_exists( 'amp_wp_get_footer' ) ) : /** * Load footer template. * * @param string $name Name of the specific footer file to use. * * @since 1.0.0 */ function amp_wp_get_footer( $name = NULL ) { $templates = array(); $name = (string) $name; if ( '' !== $name ) { $templates[] = "footer-{$name}.php"; } $templates[] = 'footer.php'; amp_wp_locate_template( $templates, TRUE ); } endif; if( !function_exists( 'amp_wp_get_sidebar' ) ) : /** * Load sidebar template. * * @param string $name The name of the specialised sidebar. * * @since 1.0.0 */ function amp_wp_get_sidebar( $name = NULL ) { $templates = array(); $name = (string) $name; if ( '' !== $name ) { $templates[] = "sidebar-{$name}.php"; } $templates[] = 'sidebar.php'; amp_wp_locate_template( $templates, TRUE ); } endif; if( !function_exists( 'amp_wp_get_search_form' ) ) : /** * Retrieve path of search form in current or parent template. * * @since 1.0.0 * * @return string Full path to index template file. */ function amp_wp_get_search_form() { add_theme_support( 'amp-wp-form' ); return amp_wp_locate_template( 'searchform.php', TRUE ); } endif; if( !function_exists( 'amp_wp_get_template_info' ) ) : /** * Get active amp theme information * * array { * * @type string $Version Template Semantic Version Number {@link http://semver.org/} * @type string $ScreenShot -optional:screenshot.png- Relative Path to ScreenShot. * @type int|string $MaxWidth -optional:780- Maximum Template Container Width. * @type string $TemplateRoot Absolute Path to Template Directory * @type string $Description Template Description * @type string $AuthorURI Template Author URL * @type string $Author Template Author * @type string $Name Template name * @type string $ThemeURI Template URL * } * * @since 1.0.0 * * @return array */ function amp_wp_get_template_info() { return wp_parse_args( apply_filters( 'amp_wp_template_active_template', array() ), array( 'Name' => __( 'Default Template', 'amp-wp' ), 'ThemeURI' => 'https://ampwp.io', 'Description' => 'AMPWP Default Template', 'Author' => 'Pixelative', 'AuthorURI' => 'https://pixelative.co', 'Version' => '1.0.0', 'ScreenShot' => 'screenshot.png', 'TemplateRoot' => AMPWP_TPL_DIR, 'MaxWidth' => 768, 'view' => 'general' ) ); } endif; if( !function_exists( 'amp_wp_get_template_directory' ) ) : /** * Get Absolute Path to Active Amp-Wp Theme Directory * * @version 1.0.0 * @since 1.0.0 * * @return string */ function amp_wp_get_template_directory() { if( $theme_info = amp_wp_get_template_info() ) { return $theme_info['TemplateRoot']; } return ''; } endif; if( !function_exists( 'amp_wp_get_container_width' ) ) : /** * Get Maximum Container Width * * @version 1.0.0 * @since 1.0.0 * * @return int */ function amp_wp_get_container_width() { $info = amp_wp_get_template_info(); return (int) $info['MaxWidth']; } endif; if( !function_exists( 'amp_wp_guess_height' ) ) : /** * Calculate height fits to width * * @version 1.0.0 * @since 1.0.0 * * @return int */ function amp_wp_guess_height() { return amp_wp_get_container_width() * 0.75; } endif; if( !function_exists( 'amp_wp_get_hw_attr' ) ) : /** * Get Width & Height Attribute * * @param string $width Custom width * @param string $height Custom height * * @version 1.0.0 * @since 1.0.0 * * @return string */ function amp_wp_get_hw_attr( $width = '', $height = '' ) { $attr = ''; if( empty( $width ) ) { $width = amp_wp_get_container_width(); } if( $width ) { $attr .= 'width="' . intval( $width ) . '" '; } if( empty( $height ) ) { $height = amp_wp_guess_height(); } if( $height ) { $attr .= 'height="' . intval( $height ) . '" '; } return $attr; } endif; if( !function_exists( 'amp_wp_hw_attr' ) ) : /** * Get Width & Height Attribute * * @param string $width * @param string $height * * @since 1.0.0 * * @return int */ function amp_wp_hw_attr( $width = '', $height = '' ) { echo amp_wp_get_hw_attr( $width, $height ); } endif; if( !function_exists( 'amp_wp_print_rel_canonical' ) ) : /** * Print rel="canonical" Tag in AMP Version * * @version 1.0.0 * @since 1.0.0 */ function amp_wp_print_rel_canonical() { $canonical_url = amp_wp_get_canonical_url(); if ( ! $canonical_url ) { $canonical_url = amp_wp_site_url(); } $canonical = Amp_WP_Content_Sanitizer::transform_to_none_amp_url( $canonical_url ); if ( $canonical ) { ?> ID ); /** * Fix paginated pages canonical. */ if ( get_query_var( 'page' ) > 1 ) { $num_pages = ( substr_count( $queried->post_content, '' ) + 1 ); if ( $num_pages && get_query_var( 'page' ) <= $num_pages ) { if ( ! $GLOBALS['wp_rewrite']->using_permalinks() ) { $canonical = add_query_arg( 'page', get_query_var( 'page' ), $canonical ); } else { $canonical = user_trailingslashit( trailingslashit( $canonical ) . get_query_var( 'page' ) ); } } } } elseif ( is_search() ) { $search_query = get_search_query(); // Regex catches case when /search/page/N without search term is itself mistaken for search term. R. if ( ! empty( $search_query ) && ! preg_match( '|^page/\d+$|', $search_query ) ) { $canonical = get_search_link(); } } elseif ( is_front_page() ) { $canonical = get_bloginfo( 'url' ); } elseif ( is_tax() || is_tag() || is_category() ) { $term = get_queried_object(); if ( ! empty( $term ) ) { $queried_terms = $GLOBALS['wp_query']->tax_query->queried_terms; /** * Check if term archive query is for multiple terms */ if ( ! isset( $queried_terms[ $term->taxonomy ]['terms'] ) || count( $queried_terms[ $term->taxonomy ]['terms'] ) <= 1 ) { $term_link = get_term_link( $term, $term->taxonomy ); if ( $term_link && ! is_wp_error( $term_link ) ) { $canonical = $term_link; } } } } elseif ( is_post_type_archive() ) { $post_type = get_query_var( 'post_type' ); if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $canonical = get_post_type_archive_link( $post_type ); } elseif ( is_author() ) { $canonical = get_author_posts_url( get_query_var( 'author' ), get_query_var( 'author_name' ) ); } elseif ( is_archive() ) { if ( is_date() ) { if ( is_day() ) { $canonical = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) ); } elseif ( is_month() ) { $canonical = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ); } elseif ( is_year() ) { $canonical = get_year_link( get_query_var( 'year' ) ); } } } return $canonical; } endif; if( !function_exists( 'amp_wp_print_rel_amphtml' ) ) : /** * Print rel=amphtml tag * * @since 1.0.0 */ function amp_wp_print_rel_amphtml() { if( !Amp_WP_Public::amp_version_exists() ) { return; } $canonical = Amp_WP_Content_Sanitizer::transform_to_amp_url( amp_wp_get_canonical_url() ); if( $canonical ) { ?> body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}} AMP_Boilerplate; } endif; if( !function_exists( 'amp_wp_template_part' ) ) : /** * Load a Template Part Into a Template * * @see get_template_part for more documentation * * @param string $slug The slug name for the generic template. * @param string $name The name of the specialised template. * * @since 1.0.0 */ function amp_wp_template_part( $slug, $name = NULL ) { $templates = array(); $name = (string) $name; if ( '' !== $name ) { $templates[] = "{$slug}-{$name}.php"; } $templates[] = "{$slug}.php"; amp_wp_locate_template( $templates, TRUE, FALSE ); } endif; if( !function_exists( 'amp_wp_get_search_page_url' ) ) : /** * Get Search Page URL * * @version 1.0.0 * @since 1.0.0 * * @return string */ function amp_wp_get_search_page_url() { return esc_url( add_query_arg( 's', '', amp_wp_site_url() ) ); } endif; if( !function_exists( 'amp_wp_get_thumbnail' ) ) : /** * Used to get thumbnail image for posts with support of default thumbnail image * * @param string $thumbnail_size * @param null $post_id * * @since 1.0.0 * * @return string */ function amp_wp_get_thumbnail( $thumbnail_size = 'thumbnail', $post_id = NULL ) { if( is_null( $post_id ) ) { $post_id = get_the_ID(); } $thumbnail_id = get_post_thumbnail_id( $post_id ); $img = wp_get_attachment_image_src( $thumbnail_id, $thumbnail_size ); if( $img ) { return array( 'src' => $img[0], 'width' => $img[1], 'height' => $img[2], ); } $img = array( 'src' => '', 'width' => '', 'height' => '', ); // todo add default thumbnail functionality or extension here return $img; } endif; if( !function_exists( 'amp_wp_element_unique_id' ) ) : /** * Create Unique Id for Element * * @version 1.0.0 * @since 1.0.0 * * @return string */ function amp_wp_element_unique_id() { return uniqid( 'element-' . rand() . '-' ); } endif; if( !function_exists( 'amp_wp_theme_set_menu_walker' ) ) : /** * Change Menu Walker Only for Main Amp Site Navigation * * Walker of navigation menu with 'amp-wp-sidebar-nav' theme_location going to change' Amp_WP_Menu_Walker'. * * * @param array $args Array of wp_nav_menu() arguments. * * @see Amp_WP_Menu_Walker * @see default-filters.php file * * @since 1.0.0 * @return array modified $args */ function amp_wp_theme_set_menu_walker( $args ) { if( !is_amp_wp() | !has_nav_menu( $args['theme_location'] ) ) { return $args; } if( apply_filters( 'amp_wp_template_set_menu_walker', $args['theme_location'] === 'amp-wp-sidebar-nav', $args ) ) { add_theme_support( 'amp-wp-navigation' ); $args['walker'] = new Amp_WP_Menu_Walker; } return $args; } endif; if( !function_exists( 'amp_wp_direction' ) ) : /** * Handy Function to Print ‘Right’ String on Rtl Mode and ‘Left’ Otherwise! * * @param bool $reverse * * @version 1.0.0. * @since 1.0.0 * @return void */ function amp_wp_direction( $reverse = FALSE ) { if ( $reverse ) { echo is_rtl() ? 'right' : 'left'; } else { echo is_rtl() ? 'left' : 'right'; } } endif; if( !function_exists( 'amp_wp_fix_customizer_statics' ) ) : /** * Fix for Loading JS/CSS Static Files in customize.php Page * * @version 1.0.0 * @since 1.0.0 */ function amp_wp_fix_customizer_statics() { if( is_customize_preview() ) { add_action( 'amp_wp_template_head', 'wp_head', 1, 1 ); add_action( 'amp_wp_template_footer', 'wp_footer', 1, 1 ); } } endif; if( !function_exists( 'amp_wp_site_url' )) : /** * Get AMP Index Page URL * * @param string $path Optional. Path relative to the site URL. Default empty. * @param string $before_sp Custom string to append before amp start point. Default empty. * * @return string * @since 1.0.0 * */ function amp_wp_site_url($path = '', $before_sp = '') { $structure = get_option( 'permalink_structure' ); if( empty( $structure ) ) { $url = site_url('/?'); $url .= Amp_WP_Public::AMP_WP_STARTPOINT; if( $path ) { $path = ltrim($path, '/'); $url .= "&".str_replace('?','',$path); } return $url; } else { $url = site_url('/'); // $url .= $before_sp ? trailingslashit($before_sp) : ''; $url .= Amp_WP_Public::AMP_WP_STARTPOINT; if( $path ) { $path = ltrim($path, '/'); $url .= "/$path"; } return $url; } } endif; if( !function_exists( 'amp_wp_get_branding_info' ) ) : /** * Returns Site Branding Info * * @param string $position * * @version 1.0.0 * @since 1.0.0 * * @return array */ function amp_wp_get_branding_info( $position = 'header' ) { if( $info = amp_wp_get_global( $position . '-site-info', FALSE ) ) { return $info; } else { $info = array( 'logo' => '', 'logo-tag' => '', 'name' => get_bloginfo( 'name', 'display' ), 'description' => get_bloginfo( 'description', 'display' ), ); } if( $name = amp_wp_get_option( 'amp-wp-' . $position . '-logo-text', FALSE ) ) { $info['name'] = $name; } if( $logo = amp_wp_get_option( 'amp-wp-' . $position . '-logo-img' ) ) { $logo = wp_get_attachment_image_src( $logo, 'full' ); if( $logo ) { $logo = array( 'src' => $logo[0], 'width' => $logo[1], 'height' => $logo[2], ); } if( !empty( $logo['src'] ) ) { $info['logo'] = $logo; $info['logo']['alt'] = $info['name'] . ' - ' . $info['description']; $info['logo-tag'] = amp_wp_create_image( $info['logo'], FALSE ); } } amp_wp_set_global( $position . '-site-info', $info ); return $info; } endif; if( !function_exists( 'amp_wp_get_theme_mod' ) ) : /** * Returns saved value of option or default from config * * @param $name * @param bool $check_customize_preview * * @todo remove this function and use amp_wp_get_option instead * @since 1.0.0 * * @return bool|string */ function amp_wp_get_theme_mod( $name, $check_customize_preview = TRUE ) { amp_wp_get_default_theme_setting( $name ); $result = get_theme_mod( $name, amp_wp_get_default_theme_setting( $name ) ); if( !$result && $check_customize_preview ) { $result = amp_wp_is_customize_preview(); } return $result; } endif; // End Template Hierarchy Related Functions // Start Template Hierarchy if( !function_exists( 'amp_wp_static_home_page_template' ) ) : /** * Retrieve Path of Static Homepage Template in Current or Parent Template. * * @version 1.0.0 * @since 1.0.0 * * @return string Full Path to Static Home Page Template File. */ function amp_wp_static_home_page_template() { if ( $template = amp_wp_page_template() ): endif; return $template; } endif; if( !function_exists( 'amp_wp_home_template' ) ) : /** * Retrieve path of home template in current or parent template. * * @see get_home_template() * * @since 1.0.0 * * @return string Full path to home template file. */ function amp_wp_home_template() { $templates = array( 'home.php', 'index.php' ); return amp_wp_locate_template( $templates ); } endif; if( !function_exists( 'amp_wp_archive_template' ) ) : /** * Retrieve path of archive template in current or parent template. * * @see get_archive_template() * * @since 1.0.0 * * @return string Full path to archive template file. */ function amp_wp_archive_template() { $post_types = array_filter( (array) get_query_var( 'post_type' ) ); $templates = array(); if ( count( $post_types ) == 1 ) { $post_type = reset( $post_types ); $templates[] = "archive-{$post_type}.php"; } $templates[] = 'archive.php'; return amp_wp_locate_template( $templates ); } endif; if( !function_exists( 'amp_wp_archive_post_type_template' ) ) : /** * Retrieve path of post type archive template in current or parent template. * * @see amp_wp_archive_template() * @see get_post_type_archive_template() * * @since 1.0.0 * * @return string Full path to archive template file. */ function amp_wp_archive_post_type_template() { $post_type = get_query_var( 'post_type' ); if( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $obj = get_post_type_object( $post_type ); if( !$obj->has_archive ) { return ''; } return amp_wp_archive_template(); } endif; if( !function_exists( 'amp_wp_single_template' ) ) : /** * Retrieve path of single template in current or parent template. * * @since 1.0.0 * * @return string Full path to single template file. */ function amp_wp_single_template() { $object = get_queried_object(); $templates = array(); if( !empty( $object->post_type ) ) { $templates[] = "single-{$object->post_type}-{$object->post_name}.php"; $templates[] = "single-{$object->post_type}.php"; } $templates[] = "single.php"; return amp_wp_locate_template( $templates ); } endif; if( !function_exists( 'amp_wp_attachment_template' ) ) : /** * Retrieve Path of Attachment Template in Current or Parent Template. * * @global array $posts * * @since 1.0.0 * * @return string Full path to attachment template file. */ function amp_wp_attachment_template() { $attachment = get_queried_object(); $templates = array(); if( $attachment ) { if( FALSE !== strpos( $attachment->post_mime_type, '/' ) ) { list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); } else { list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); } if( !empty( $subtype ) ) { $templates[] = "{$type}-{$subtype}.php"; $templates[] = "{$subtype}.php"; } $templates[] = "{$type}.php"; } $templates[] = 'attachment.php'; return amp_wp_locate_template( $templates ); } endif; if( !function_exists( 'amp_wp_is_static_home_page' ) ) : /** * Is current page static home page * * @return bool true on success or false on failure * @since 1.0.0 */ function amp_wp_is_static_home_page() { return is_home() && apply_filters( 'amp_wp_template_show_on_front', 'posts' ) === 'page' && apply_filters( 'amp_wp_template_page_on_front', 0 ); } endif; if( !function_exists( 'amp_wp_page_template' ) ) : /** * Retrieve path of page template in current or parent template. * * @see get_page_template() * * @since 1.0.0 * * @return string Full path to page template file. */ function amp_wp_page_template() { $id = get_queried_object_id(); $template = get_page_template_slug(); $pagename = get_query_var( 'pagename' ); if( !$pagename && $id ) { // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object $post = get_queried_object(); if( $post ) { $pagename = $post->post_name; } } $templates = array(); if( $template && 0 === validate_file( $template ) ) { $templates[] = $template; } if( $pagename ) { $templates[] = "page-$pagename.php"; } if( $id ) { $templates[] = "page-$id.php"; } $templates[] = 'page.php'; return amp_wp_locate_template( $templates ); } endif; if( !function_exists( 'amp_wp_404_template' ) ) : /** * Retrieve path of 404 template in current or parent template. * * @see get_404_template() * * @since 1.0.0 * * @return string Full path to 404 template file. */ function amp_wp_404_template() { return amp_wp_locate_template( '404.php' ); } endif; if( !function_exists( 'amp_wp_search_template' ) ) : /** * Retrieve path of search template in current or parent template. * * @see get_search_template() * * @since 1.0.0 * * @return string Full path to search template file. */ function amp_wp_search_template() { return amp_wp_locate_template( 'search.php' ); } endif; if( !function_exists( 'amp_wp_index_template' ) ) : /** * Retrieve path of index template in current or parent template. * * @since 1.0.0 * * @return string Full path to index template file. */ function amp_wp_index_template() { return amp_wp_locate_template( 'index.php' ); } endif; // End Template Hierarchy // Start Global Variables if( !function_exists( 'amp_wp_set_global' ) ) : /** * Used to set a global variable. * * @param string $id * @param mixed $value * * @since 1.0.0 * * @return mixed */ function amp_wp_set_global( $id, $value ) { global $amp_wp_theme_core_globals_cache; $amp_wp_theme_core_globals_cache[ $id ] = $value; } endif; if( !function_exists( 'amp_wp_unset_global' ) ) : /** * Used to Remove a Global Variable. * * @param string $id * * @since 1.0.0 * * @return mixed */ function amp_wp_unset_global( $id ) { global $amp_wp_theme_core_globals_cache; unset( $amp_wp_theme_core_globals_cache[ $id ] ); } endif; if( !function_exists( 'amp_wp_get_global' ) ) : /** * Used to get a global value. * * @param string $id * @param mixed $default * * @since 1.0.0 * * @return mixed */ function amp_wp_get_global( $id, $default = NULL ) { global $amp_wp_theme_core_globals_cache; if( isset( $amp_wp_theme_core_globals_cache[$id] ) ) { return $amp_wp_theme_core_globals_cache[$id]; } else { return $default; } } endif; if( !function_exists( 'amp_wp_echo_global' ) ) : /** * Used to Print a Global Value. * * @param string $id * @param mixed $default * * @since 1.0.0 * * @return mixed */ function amp_wp_echo_global( $id, $default = NULL ) { global $amp_wp_theme_core_globals_cache; if( isset( $amp_wp_theme_core_globals_cache[$id] ) ) { echo $amp_wp_theme_core_globals_cache[$id]; // escaped before } else { echo $default; // escaped before } } endif; if( !function_exists( 'amp_wp_clear_globals' ) ) : /** * Used to clear all properties. * * @since 1.0.0 * * @return void */ function amp_wp_clear_globals() { global $amp_wp_theme_core_globals_cache; $amp_wp_theme_core_globals_cache = array(); } endif; // End Global Variables // Start Blocks Properties if( !function_exists( 'amp_wp_get_prop' ) ) : /** * Used to get a property value. * * @param string $id * @param mixed $default * * @since 1.0.0 * * @return mixed */ function amp_wp_get_prop( $id, $default = NULL ) { global $amp_wp_theme_core_props_cache; if ( isset( $amp_wp_theme_core_props_cache[ $id ] ) ) { return $amp_wp_theme_core_props_cache[ $id ]; } else { return $default; } } endif; if( !function_exists( 'amp_wp_echo_prop' ) ) : /** * Used to print a property value. * * @param string $id * @param mixed $default * * @since 1.0.0 * * @return mixed */ function amp_wp_echo_prop( $id, $default = NULL ) { global $amp_wp_theme_core_props_cache; if ( isset( $amp_wp_theme_core_props_cache[ $id ] ) ) { echo $amp_wp_theme_core_props_cache[ $id ]; // escaped before } else { echo $default; // escaped before } } endif; if( !function_exists( 'amp_wp_get_prop_class' ) ) : /** * Used to get block class property. * * @since 1.0.0 * * @return string */ function amp_wp_get_prop_class() { global $amp_wp_theme_core_props_cache; if ( isset( $amp_wp_theme_core_props_cache['class'] ) ) { return $amp_wp_theme_core_props_cache['class']; } else { return ''; } } endif; if( !function_exists( 'amp_wp_get_prop_thumbnail_size' ) ) : /** * Used to get block thumbnail size property. * * @param string $default * * @since 1.0.0 * * @return string */ function amp_wp_get_prop_thumbnail_size( $default = 'thumbnail' ) { global $amp_wp_theme_core_props_cache; if ( isset( $amp_wp_theme_core_props_cache['thumbnail-size'] ) ) { return $amp_wp_theme_core_props_cache['thumbnail-size']; } else { return $default; } } endif; if( !function_exists( 'amp_wp_set_prop' ) ) : /** * Used to set a block property value. * * @param string $id * @param mixed $value * * @since 1.0.0 * * @return mixed */ function amp_wp_set_prop( $id, $value ) { global $amp_wp_theme_core_props_cache; $amp_wp_theme_core_props_cache[ $id ] = $value; } endif; if( !function_exists( 'amp_wp_set_prop_class' ) ) : /** * Used to set a block class property value. * * @param mixed $value * @param bool $clean * * @since 1.0.0 * * @return mixed */ function amp_wp_set_prop_class( $value, $clean = FALSE ) { global $amp_wp_theme_core_props_cache; if ( $clean ) { $amp_wp_theme_core_props_cache['class'] = $value; } else { $amp_wp_theme_core_props_cache['class'] = $value . ' ' . amp_wp_get_prop_class(); } } endif; if( !function_exists( 'amp_wp_set_prop_thumbnail_size' ) ) : /** * Used to set a block property value. * * @param mixed $value * * @since 1.0.0 * * @return mixed */ function amp_wp_set_prop_thumbnail_size( $value = 'thumbnail' ) { global $amp_wp_theme_core_props_cache; $amp_wp_theme_core_props_cache['thumbnail-size'] = $value; } endif; if( !function_exists( 'amp_wp_unset_prop' ) ) : /** * Used to remove a property from block property list. * * @param string $id * * @since 1.0.0 * * @return mixed */ function amp_wp_unset_prop( $id ) { global $amp_wp_theme_core_props_cache; unset( $amp_wp_theme_core_props_cache[ $id ] ); } endif; if( !function_exists( 'amp_wp_clear_props' ) ) : /** * Used to clear all properties. * * @since 1.0.0 * * @return void */ function amp_wp_clear_props() { global $amp_wp_theme_core_props_cache; $amp_wp_theme_core_props_cache = array(); } endif; // End Blocks Properties if( !function_exists( 'amp_wp_get_option' ) ) : /** * Returns option value * * @param string $option_key * @param string $default_value * * @since 1.0.0 * * @return string */ function amp_wp_get_option( $option_key = '', $default_value = NULL ) { if( empty( $option_key ) ) { return $default_value; } if( is_null( $default_value ) ) { $default_value = apply_filters( 'amp-wp-template-default-theme-mod', $default_value, $option_key ); } return get_theme_mod( $option_key, $default_value ); } endif; if( !function_exists( 'amp_wp_get_server_ip_address' ) ) : /** * Handy Function for Get Server IP * * @version 1.0.0 * @since 1.0.0 * * @return string|null IP address on success or null on failure. */ function amp_wp_get_server_ip_address() { global $is_IIS; $ip = ( $is_IIS && isset( $_SERVER['LOCAL_ADDR'] ) ) ? $_SERVER['LOCAL_ADDR'] : $_SERVER['SERVER_ADDR']; if( $ip === '::1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) { return $ip; } } endif; if( !function_exists( 'amp_wp_is_localhost' ) ) : /** * Utility function to detect is site currently running on localhost? * * @since 1.0.0 * * @return bool */ function amp_wp_is_localhost() { $server_ip = amp_wp_get_server_ip_address(); $server_ip_long = ip2long( $server_ip ); return $server_ip === '::1' || ( $server_ip_long >= 2130706433 && $server_ip_long <= 2147483646 ); } endif; // Start Queries if( !function_exists( 'amp_wp_get_query' ) ) : /** * Used to get current query. * * @since 1.0.0 * * @return WP_Query|null */ function amp_wp_get_query() { global $amp_wp_theme_core_query; // Add default query to ThemeName query if its not added or default query is used. if( !is_a( $amp_wp_theme_core_query, 'WP_Query' ) ) { global $wp_query; $amp_wp_theme_core_query = &$wp_query; } return $amp_wp_theme_core_query; } endif; if( !function_exists( 'amp_wp_set_query' ) ) : /** * Used to get current query. * * @param WP_Query $query * * @since 1.0.0 * */ function amp_wp_set_query( &$query ) { global $amp_wp_theme_core_query; $amp_wp_theme_core_query = $query; } endif; if( !function_exists( 'amp_wp_clear_query' ) ) : /** * Used to get current query. * * @param bool $reset_query * * @since 1.0.0 * */ function amp_wp_clear_query( $reset_query = TRUE ) { global $amp_wp_theme_core_query; $amp_wp_theme_core_query = NULL; // This will remove obscure bugs that occur when the previous wp_query object is not destroyed properly before another is set up. if ( $reset_query ) { wp_reset_query(); } } endif; // End Queries // Start Post Related Functions if( !function_exists( 'amp_wp_have_posts' ) ) : /** * Used for checking have posts in advanced way! * * @since 1.0.0 */ function amp_wp_have_posts() { // Add default query to amp_wp_template query if its not added or default query is used. if( !amp_wp_get_query() instanceof WP_Query ) { global $wp_query; amp_wp_set_query( $wp_query ); } // If Count Customized if( amp_wp_get_prop( 'posts-count', NULL ) != NULL ) { if( amp_wp_get_prop( 'posts-counter', 1 ) > amp_wp_get_prop( 'posts-count' ) ) { return FALSE; } else { if( amp_wp_get_query()->current_post + 1 < amp_wp_get_query()->post_count ) { return TRUE; } else { return FALSE; } } } else { return amp_wp_get_query()->current_post + 1 < amp_wp_get_query()->post_count; } } endif; if( !function_exists( 'amp_wp_the_post' ) ) : /** * Custom the_post for custom counter functionality * * @since 1.0.0 */ function amp_wp_the_post() { // If count customized if( amp_wp_get_prop( 'posts-count', NULL ) != NULL ) { amp_wp_set_prop( 'posts-counter', absint( amp_wp_get_prop( 'posts-counter', 1 ) ) + 1 ); } // Do default the_post amp_wp_get_query()->the_post(); } endif; if( !function_exists( 'amp_wp_the_post_thumbnail' ) ) : /** * Display the post thumbnail. * * @since 1.0.0 * * @param string $size * @param string $attr */ function amp_wp_the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { if( empty( $attr ) ) { $attr = array( 'alt' => the_title_attribute( array( 'echo' => FALSE ) ), 'layout' => 'responsive', ); } the_post_thumbnail( $size, $attr ); } endif; if( !function_exists( 'amp_wp_human_number_format' ) ) : /** * Format number to human friendly style * * @param $number * * @return string */ function amp_wp_human_number_format( $number ) { if( !is_numeric( $number ) ) { return $number; } if( $number >= 1000000 ) { return round( ( $number / 1000 ) / 1000, 1 ) . "M"; } elseif ( $number >= 100000 ) { return round( $number / 1000, 0 ) . "k"; } else { return @number_format( $number ); } } endif; if( !function_exists( 'amp_wp_get_archive_title_fields' ) ) : /** * Handy function used to get archive pages title fields * * @since 1.0.0 * * @return array */ function amp_wp_get_archive_title_fields() { $icon = ''; $pre_title = ''; $title = ''; if( is_category() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_category' ); $title = single_cat_title( '', FALSE ); } elseif ( is_tag() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_tag' ); $title = single_tag_title( '', FALSE ); } elseif ( is_author() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_author' ); $title = '' . get_the_author() . ''; } elseif ( is_year() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_yearly' ); $title = get_the_date( _x( 'Y', 'yearly archives date format', 'amp-wp' ) ); } elseif ( is_month() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_monthly' ); $title = get_the_date( _x( 'F Y', 'monthly archives date format', 'amp-wp' ) ); } elseif ( is_day() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_daily' ); $title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'amp-wp' ) ); } elseif ( is_tax( 'post_format' ) ) { if ( is_tax( 'post_format', 'post-format-aside' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'asides' ); } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'galleries' ); } elseif ( is_tax( 'post_format', 'post-format-image' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'images' ); } elseif ( is_tax( 'post_format', 'post-format-video' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'videos' ); } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'quotes' ); } elseif ( is_tax( 'post_format', 'post-format-link' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'links' ); } elseif ( is_tax( 'post_format', 'post-format-status' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'statuses' ); } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'audio' ); } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = amp_wp_translation_get( 'chats' ); } } elseif ( is_post_type_archive() ) { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = post_type_archive_title( '', FALSE ); } elseif ( is_tax() ) { $tax = get_taxonomy( get_queried_object()->taxonomy ); $icon = ''; $pre_title = amp_wp_translation_get( 'browsing_archive' ); $title = sprintf( __( '%1$s: %2$s', 'beetter-amp' ), $tax->labels->singular_name, single_term_title( '', FALSE ) ); } else { $icon = ''; $pre_title = amp_wp_translation_get( 'browsing' ); $title = amp_wp_translation_get( 'archive' ); } return compact( 'icon', 'pre_title', 'title' ); } endif; if( !function_exists( 'amp_wp_post_classes' ) ) : /** * Handy function to generate class attribute for posts * * @since 1.0.0 * * @param string|array $append One or more classes to add to the class list. */ function amp_wp_post_classes( $append = '' ) { $class = get_post_class( $append ); if( !has_post_thumbnail() ) { $class[] = 'no-thumbnail'; } else { $class[] = 'have-thumbnail'; } $class[] = 'clearfx'; $class = str_replace( 'hentry', '', join( ' ', $class ) ); echo 'class = "' . $class . '"'; unset( $class ); } endif; if( !function_exists( 'amp_wp_related_posts_query_args' ) ) : /** * Get Related Posts * * @param integer $count number of posts to return * @param string $type * @param integer|null $post_id * @param array $params query extra arguments * * @return array query args array */ function amp_wp_related_posts_query_args( $count = 5, $type = 'cat', $post_id = NULL, $params = array() ) { $post = get_post( $post_id ); if( !$post_id && isset( $post->ID ) ) { $post_id = $post->ID; } $args = array( 'posts_per_page' => $count, 'post__not_in' => array( $post_id ), 'ignore_sticky_posts' => TRUE, ); switch ( $type ) { case 'cat': $args['category__in'] = wp_get_post_categories( $post_id ); break; case 'tag': $tag_in = wp_get_object_terms( $post_id, 'post_tag', array( 'fields' => 'ids' ) ); if ( $tag_in && ! is_wp_error( $tag_in ) ) { $args['tag__in'] = $tag_in; } break; case 'author': if( isset( $post->post_author ) ) { $args['author'] = $post->post_author; } break; case 'cat-tag': $args['category__in'] = wp_get_post_categories( $post_id ); $args['tag__in'] = wp_get_object_terms( $post_id, 'post_tag', array( 'fields' => 'ids' ) ); break; case 'cat-tag-author': $args['category__in'] = wp_get_post_categories( $post_id ); if ( isset( $post->post_author ) ) { $args['author'] = $post->post_author; } $tag_in = wp_get_object_terms( $post_id, 'post_tag', array( 'fields' => 'ids' ) ); if ( $tag_in && ! is_wp_error( $tag_in ) ) { $args['tag__in'] = $tag_in; } break; case 'rand': case 'random': case 'randomly': $args['orderby'] = 'rand'; break; } if ( $params ) { $args = array_merge( $args, $params ); } return $args; } endif; if( !function_exists( 'amp_wp_get_post_parent' ) ) : /** * Get post parent * * @param int $attachment_id * * @since 1.0.0 * @return bool|WP_Post WP_Post on success or false on failure */ function amp_wp_get_post_parent( $attachment_id = NULL ) { $attachment = ( empty( $attachment_id ) && isset( $GLOBALS['post'] ) ) ? $GLOBALS['post'] : get_post( $attachment_id ); // Validate attachment if( !$attachment || is_wp_error( $attachment ) ) { return FALSE; } $parent = FALSE; if( !empty( $attachment->post_parent ) ) { $parent = get_post( $attachment->post_parent ); if( !$parent || is_wp_error( $parent ) ) { $parent = FALSE; } } return $parent; } endif; // End Post Related Functions // Start Scial Share Post Related Functions if( !function_exists( 'amp_wp_social_shares_count' ) ) : /** * Returns all social share count for post. * * @param $sites * * @since 1.0.0 * * @return array|mixed|void */ function amp_wp_social_shares_count( $sites ) { $sites = array_intersect_key( $sites, array( // Valid sites 'facebook' => '', 'twitter' => '', 'google_plus' => '', 'pinterest' => '', 'linkedin' => '', 'tumblr' => '', 'reddit' => '', 'stumbleupon' => '', )); // Disable social share in localhost if( amp_wp_is_localhost() ) { return array(); } $post_id = get_queried_object_id(); $expired = (int) get_post_meta( $post_id, '_amp_wp_social_share_interval', TRUE ); $results = array(); $update_cache = FALSE; if( $expired < time() ) { $update_cache = TRUE; } else { // get count from cache storage foreach( $sites as $site_id => $is_active ) { if( !$is_active ) { continue; } $count_number = get_post_meta( $post_id, '_amp_wp_social_share_'.$site_id, TRUE ); $update_cache = $count_number === ''; if( $update_cache ) { break; } $results[ $site_id ] = $count_number; } } if( $update_cache ) { // Update cache storage if needed $current_page = amp_wp_social_share_guss_current_page(); foreach( $sites as $site_id => $is_active ) { if( !$is_active ) { continue; } $count_number = amp_wp_social_share_fetch_count( $site_id, $current_page['page_permalink'] ); update_post_meta( $post_id, '_amp_wp_social_share_' . $site_id, $count_number ); $results[ $site_id ] = $count_number; } /** * This filter can be used to change share count time. */ $cache_time = apply_filters( 'amp_wp_social_share_cache_time', MINUTE_IN_SECONDS * 120, $post_id ); update_post_meta( $post_id, '_amp_wp_social_share_interval', time() + $cache_time ); } return apply_filters( 'amp_wp_social_share_count', $results ); } endif; if( !function_exists( 'amp_wp_social_share_guss_current_page' ) ) : /** * Detects and returns current page info for social share * * @version 1.0.0 * @since 1.0.0 * * @return array */ function amp_wp_social_share_guss_current_page() { $page_permalink = ''; $need_short_link = amp_wp_get_theme_mod( 'amp-wp-post-social-share-link-format' ) === 'short'; if( is_home() || is_front_page() ) { $page_title = get_bloginfo( 'name' ); } elseif( is_single( get_the_ID() ) && ! ( is_front_page() ) ) { $page_title = get_the_title(); if ( $need_short_link ) { $page_permalink = wp_get_shortlink(); } } elseif( is_page() ) { $page_title = get_the_title(); if( $need_short_link ) { $page_permalink = wp_get_shortlink(); } } elseif( is_category() || is_tag() || is_tax() ) { $page_title = single_term_title( '', FALSE ); if( $need_short_link ) { $queried_object = get_queried_object(); if( !empty( $queried_object->taxonomy ) ) { if( 'category' == $queried_object->taxonomy ) { $page_permalink = "?cat=$queried_object->term_id"; } else { $tax = get_taxonomy( $queried_object->taxonomy ); if ( $tax->query_var ) { $page_permalink = "?$tax->query_var=$queried_object->slug"; } else { $page_permalink = "?taxonomy=$queried_object->taxonomy&term=$queried_object->term_id"; } } $page_permalink = home_url( $page_permalink ); } } } else { $page_title = get_bloginfo( 'name' ); } if( !$page_permalink ) { $page_permalink = amp_wp_guess_none_amp_url(); } return compact( 'page_title', 'page_permalink' ); } endif; if( !function_exists( 'amp_wp_social_share_get_li' ) ) : /** * Used for generating lis for social share list * * @param string $id * @param bool $show_title * @param int $count_label * * @since 1.0.0 * * @return string */ function amp_wp_social_share_get_li( $id = '', $show_title = TRUE, $count_label = 0 ) { if( empty( $id ) ) { return ''; } static $initialized; static $page_title; static $page_permalink; wp_reset_postdata(); // fix for after other loops if( is_null( $initialized ) ) { $cur_page = amp_wp_social_share_guss_current_page(); $page_title = esc_attr( $cur_page['page_title'] ); $page_permalink = urlencode( $cur_page['page_permalink'] ); $initialized = TRUE; } switch ( $id ) { case 'facebook': $link = 'https://www.facebook.com/sharer.php?u=' . $page_permalink; $title = __( 'Facebook', 'amp-wp' ); $icon = ''; break; case 'twitter': $by = ''; $link = 'https://twitter.com/share?text=' . $page_title . $by . '&url=' . $page_permalink; $title = __( 'Twitter', 'amp-wp' ); $icon = ''; break; case 'google_plus': $link = 'https://plus.google.com/share?url=' . $page_permalink; $title = __( 'Google+', 'amp-wp' ); $icon = ''; break; case 'pinterest': $_img_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); $link = 'https://pinterest.com/pin/create/button/?url=' . $page_permalink . '&media=' . $_img_src[0] . '&description=' . $page_title; $title = __( 'Pinterest', 'amp-wp' ); $icon = ''; break; case 'linkedin': $link = 'https://www.linkedin.com/shareArticle?mini=true&url=' . $page_permalink . '&title=' . $page_title; $title = __( 'Linkedin', 'amp-wp' ); $icon = ''; break; case 'tumblr': $link = 'https://www.tumblr.com/share/link?url=' . $page_permalink . '&name=' . $page_title; $title = __( 'Tumblr', 'amp-wp' ); $icon = ''; break; case 'email': $link = "mailto:?subject=" . $page_title . "&body=" . $page_permalink; $title = __( 'Email', 'amp-wp' ); $icon = ''; break; case 'telegram': $link = 'https://telegram.me/share/url?url=' . $page_permalink . '&text=' . $page_title; $title = __( 'Telegram', 'amp-wp' ); $icon = ''; break; case 'whatsapp': $link = 'whatsapp://send?text=' . $page_title . ' %0A%0A ' . $page_permalink; $title = __( 'WhatsApp', 'amp-wp' ); $icon = ''; break; case 'digg': $link = 'https://www.digg.com/submit?url=' . $page_permalink; $title = __( 'Digg', 'amp-wp' ); $icon = ''; break; case 'reddit': $link = 'https://reddit.com/submit?url=' . $page_permalink . '&title=' . $page_title; $title = __( 'ReddIt', 'amp-wp' ); $icon = ''; break; case 'stumbleupon': $link = 'https://www.stumbleupon.com/submit?url=' . $page_permalink . '&title=' . $page_title; $title = __( 'StumbleUpon', 'amp-wp' ); $icon = ''; break; case 'vk': $link = 'https://vkontakte.ru/share.php?url=' . $page_permalink; $title = __( 'VK', 'amp-wp' ); $icon = ''; break; default: return ''; } $extra_classes = $count_label ? ' has-count' : ''; $output = '
  • '; $output .= $icon; if( $show_title ) { $output .= ''.wp_kses( $title, amp_wp_trans_allowed_html() ).''; } if ( $count_label ) { $output .= sprintf( '%s', amp_wp_human_number_format( $count_label ) ); } $output .= '
  • '; return $output; } // amp_wp_social_share_get_li endif; // End Scial Share Post Related Functions // Start Comments Related Functions if( !function_exists( 'amp_wp_get_comment_link' ) ) : /** * Returns Non-AMP comment link for AMP post * * @since 1.0.0 * * @return int */ function amp_wp_get_comment_link() { $prev = Amp_WP_Content_Sanitizer::turn_url_transform_off_on( FALSE ); $comments_url = get_permalink() . '#respond'; Amp_WP_Content_Sanitizer::turn_url_transform_off_on( $prev ); return $comments_url; } endif; if( !function_exists( 'amp_wp_comment_reply_link' ) ) : /** * Retrieve the HTML Content for Reply to Comment Link. * * @param array $args @see comment_reply_link for documentation * * @version 1.0.0 * @since 1.0.0 * * @return void|false|string */ function amp_wp_comment_reply_link( $args = array() ) { $current_value = Amp_WP_Content_Sanitizer::$enable_url_transform; Amp_WP_Content_Sanitizer::$enable_url_transform = FALSE; $result = comment_reply_link( $args ); Amp_WP_Content_Sanitizer::$enable_url_transform = $current_value; return $result; } endif; if( !function_exists( 'amp_wp_comment_link' ) ) : /** * Non-AMP comment link for AMP post * * @since 1.0.0 * * @return int */ function amp_wp_comment_link() { echo esc_attr( amp_wp_get_comment_link() ); } endif; if( !function_exists( 'amp_wp_list_comments' ) ) : /** * List comments for a particular post. * * @see wp_list_comments for more documentation * * @param string|array $args wp_list_comments first argument * @param array $comment_query_args comment query arguments * * @global WP_Query $wp_query Global WP_Query instance. * * @since 1.0.0 * * @return string|void */ function amp_wp_list_comments( $args = array(), $comment_query_args = array() ) { global $wp_query; $post_id = get_the_ID(); $comment_args = array( 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve', 'post_id' => $post_id, 'no_found_rows' => FALSE, ); if( empty( $args['callback'] ) && amp_wp_locate_template( 'comment-item.php' ) ) { $args['callback'] = 'amp_wp_comment_item'; $args['end-callback'] = 'amp_wp_comment_item_end'; } $comments = new WP_Comment_Query( array_merge( $comment_args, $comment_query_args ) ); /** * Filters the comments array. * * @see comments_template * * @param array $comments Array of comments supplied to the comments template. * @param int $post_ID Post ID. */ $comments_list = apply_filters( 'comments_array', $comments->comments, $post_id ); // Save comments list to comments property of the main query to enable wordpress core // function such as get_next_comments_link works in comments page $wp_query->comments = $comments_list; return wp_list_comments( $args ); } endif; if( !function_exists( 'amp_wp_comments_paginate' ) ) : /** * Displays pagination links for the comments on the current post. * * @see wp_list_comments for more documentation * * @since 1.0.0 * */ function amp_wp_comments_paginate() { // Nav texts with RTL support if ( is_rtl() ) { $prev = ' ' . amp_wp_translation_get( 'comment_previous' ); $next = amp_wp_translation_get( 'comment_next' ) . ' '; } else { $next = amp_wp_translation_get( 'comment_next' ) . ' '; $prev = ' ' . amp_wp_translation_get( 'comment_previous' ); } previous_comments_link( $prev ); next_comments_link( $next ); } endif; if( !function_exists( 'amp_wp_comment_item' ) ) : /** * Load comment-item.php file in the current or parent template. * * @staticvar string $path * @param WP_Comment_Query $comment * * @version 1.0.0 * @since 1.0.0 */ function amp_wp_comment_item( $comment ) { static $path; if( is_null( $path ) ) { $path = amp_wp_locate_template( 'comment-item.php' ); } if( $path ) { include $path; } } endif; if( !function_exists( 'amp_wp_comment_item_end' ) ) : /** * Print li Closing Tag * * @version 1.0.0 * @since 1.0.0 */ function amp_wp_comment_item_end() { echo ''; } endif; // End Comments Related Functions if( !function_exists( 'amp_wp_min_suffix' ) ) : /** * Returns Appropriate Suffix for Static Files (Min or Not) * * @param string $before * @param string $after * * @return string */ function amp_wp_min_suffix( $before = '', $after = '' ) { static $suffix; if( !$suffix ) { $suffix = ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'AMPWP_DEV_MODE' ) && AMPWP_DEV_MODE ) ) ? '' : '.min'; } return "$before$suffix$after"; } endif;