Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/accelera.../includes/vendor/amp/includes
File: class-amp-post-template.php
<?php
[0] Fix | Delete
namespace AMPforWP\AMPVendor;
[1] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[2] Fix | Delete
exit;
[3] Fix | Delete
}
[4] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/utils/class-amp-dom-utils.php' );
[5] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/utils/class-amp-html-utils.php' );
[6] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/utils/class-amp-string-utils.php' );
[7] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/utils/class-amp-wp-utils.php' );
[8] Fix | Delete
[9] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/class-amp-content.php' );
[10] Fix | Delete
[11] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-style-sanitizer.php' );
[12] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-blacklist-sanitizer.php' );
[13] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-img-sanitizer.php' );
[14] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-video-sanitizer.php' );
[15] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-iframe-sanitizer.php' );
[16] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-audio-sanitizer.php' );
[17] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-playbuzz-sanitizer.php' );
[18] Fix | Delete
[19] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-rule-spec.php' );
[20] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-allowed-tags-generated.php' );
[21] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php' );
[22] Fix | Delete
global $wp_version;
[23] Fix | Delete
if ( version_compare( $wp_version, '5.3', '>=' ) ) {
[24] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-gallery-block-sanitizer-5-3.php' );
[25] Fix | Delete
}else{
[26] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-gallery-block-sanitizer.php' );
[27] Fix | Delete
}
[28] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/sanitizers/class-amp-block-sanitizer.php' );
[29] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-reddit-embed.php' );
[30] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-twitter-embed.php' );
[31] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-youtube-embed.php' );
[32] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-dailymotion-embed.php' );
[33] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-gallery-embed.php' );
[34] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-instagram-embed.php' );
[35] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-vine-embed.php' );
[36] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-facebook-embed.php' );
[37] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-vimeo-embed.php' );
[38] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-soundcloud-embed.php' );
[39] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-pinterest-embed.php' );
[40] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-wistia-embed.php' );
[41] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-core-block-handler.php' );
[42] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-playlist-embed-handler.php' );
[43] Fix | Delete
require_once( AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-tiktok-embed.php' );
[44] Fix | Delete
[45] Fix | Delete
if ( file_exists( AMPFORWP_PLUGIN_DIR .'includes/vendor/css-parser/autoload.php' ) ) {
[46] Fix | Delete
require_once AMPFORWP_PLUGIN_DIR .'includes/vendor/css-parser/autoload.php';
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
require_once( AMP__VENDOR__DIR__ . 'includes/sanitizers/class-amp-tree-style-sanitizer.php' );
[50] Fix | Delete
[51] Fix | Delete
require_once( AMPFORWP_PLUGIN_DIR . 'includes/vendor/css-parser/parser-helper-function.php' );
[52] Fix | Delete
use \AllowDynamicProperties;
[53] Fix | Delete
#[AllowDynamicProperties]
[54] Fix | Delete
class AMP_Post_Template {
[55] Fix | Delete
const SITE_ICON_SIZE = 32;
[56] Fix | Delete
const CONTENT_MAX_WIDTH = 600;
[57] Fix | Delete
[58] Fix | Delete
// Needed for 0.3 back-compat
[59] Fix | Delete
const DEFAULT_NAVBAR_BACKGROUND = '#0a89c0';
[60] Fix | Delete
const DEFAULT_NAVBAR_COLOR = '#fff';
[61] Fix | Delete
[62] Fix | Delete
private $template_dir;
[63] Fix | Delete
private $data;
[64] Fix | Delete
[65] Fix | Delete
public function __construct( $post_id ) {
[66] Fix | Delete
$this->template_dir = apply_filters( 'amp_post_template_dir', AMP__VENDOR__DIR__ . '/templates' );
[67] Fix | Delete
if ( ampforwp_is_front_page() ) {
[68] Fix | Delete
$post_id = ampforwp_get_frontpage_id();
[69] Fix | Delete
}
[70] Fix | Delete
$this->ID = $post_id;
[71] Fix | Delete
$this->post = get_post( $post_id );
[72] Fix | Delete
$content_max_width = self::CONTENT_MAX_WIDTH;
[73] Fix | Delete
if ( isset( $GLOBALS['content_width'] ) && $GLOBALS['content_width'] > 0 ) {
[74] Fix | Delete
$content_max_width = $GLOBALS['content_width'];
[75] Fix | Delete
}
[76] Fix | Delete
$content_max_width = apply_filters( 'amp_content_max_width', $content_max_width );
[77] Fix | Delete
[78] Fix | Delete
$this->data = array(
[79] Fix | Delete
'content_max_width' => $content_max_width,
[80] Fix | Delete
[81] Fix | Delete
'document_title' => function_exists( 'wp_get_document_title' ) ? wp_get_document_title() : wp_title( '', false ), // back-compat with 4.3
[82] Fix | Delete
'canonical_url' => get_permalink( $post_id ),
[83] Fix | Delete
'home_url' => home_url(),
[84] Fix | Delete
'blog_name' => get_bloginfo( 'name' ),
[85] Fix | Delete
[86] Fix | Delete
'html_tag_attributes' => array(),
[87] Fix | Delete
'body_class' => '',
[88] Fix | Delete
[89] Fix | Delete
'site_icon_url' => apply_filters( 'amp_site_icon_url', function_exists( 'get_site_icon_url' ) ? get_site_icon_url( self::SITE_ICON_SIZE ) : '' ),
[90] Fix | Delete
'placeholder_image_url' => AMPFORWP_IMAGE_DIR. '/placeholder-icon.png' ,
[91] Fix | Delete
[92] Fix | Delete
'featured_image' => false,
[93] Fix | Delete
'comments_link_url' => false,
[94] Fix | Delete
'comments_link_text' => false,
[95] Fix | Delete
[96] Fix | Delete
'amp_runtime_script' => 'https://cdn.ampproject.org/v0.js',
[97] Fix | Delete
'amp_component_scripts' => array(),
[98] Fix | Delete
[99] Fix | Delete
'customizer_settings' => array(),
[100] Fix | Delete
[101] Fix | Delete
'font_urls' => array(
[102] Fix | Delete
'merriweather' => 'https://fonts.googleapis.com/css?family=Merriweather:400,400italic,700,700italic',
[103] Fix | Delete
),
[104] Fix | Delete
[105] Fix | Delete
'post_amp_styles' => array(),
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Add amp-analytics tags.
[109] Fix | Delete
*
[110] Fix | Delete
* This filter allows you to easily insert any amp-analytics tags without needing much heavy lifting.
[111] Fix | Delete
*
[112] Fix | Delete
* @since 0.4
[113] Fix | Delete
*.
[114] Fix | Delete
* @param array $analytics An associative array of the analytics entries we want to output. Each array entry must have a unique key, and the value should be an array with the following keys: `type`, `attributes`, `script_data`. See readme for more details.
[115] Fix | Delete
* @param object $post The current post.
[116] Fix | Delete
*/
[117] Fix | Delete
'amp_analytics' => apply_filters( 'amp_post_template_analytics', array(), $this->post ),
[118] Fix | Delete
);
[119] Fix | Delete
[120] Fix | Delete
$this->build_post_content();
[121] Fix | Delete
$this->build_post_data();
[122] Fix | Delete
$this->build_customizer_settings();
[123] Fix | Delete
$this->build_html_tag_attributes();
[124] Fix | Delete
[125] Fix | Delete
$this->data = apply_filters( 'amp_post_template_data', $this->data, $this->post );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
public function get( $property, $default = null ) {
[129] Fix | Delete
if ( isset( $this->data[ $property ] ) ) {
[130] Fix | Delete
return $this->data[ $property ];
[131] Fix | Delete
} else {
[132] Fix | Delete
//_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Called for non-existant key ("%s").', 'accelerated-mobile-pages' ), esc_html( $property ) ), '0.1' );
[133] Fix | Delete
[134] Fix | Delete
// We commented the below line because php notice as per #3967
[135] Fix | Delete
return $default;
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
public function set( $property, $value = '' ) {
[139] Fix | Delete
if ( isset( $this->data[ $property ] ) ) {
[140] Fix | Delete
return $this->data[ $property ] = $value ;
[141] Fix | Delete
} else {
[142] Fix | Delete
_doing_it_wrong( __METHOD__, sprintf( __( 'Called for non-existant key ("%s").', 'accelerated-mobile-pages' ), esc_html( $property ) ), '0.1' );
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
return $value;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
public function get_customizer_setting( $name, $default = null ) {
[149] Fix | Delete
$settings = $this->get( 'customizer_settings' );
[150] Fix | Delete
if ( ! empty( $settings[ $name ] ) ) {
[151] Fix | Delete
return $settings[ $name ];
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
return $default;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
public function load() {
[158] Fix | Delete
$this->load_parts( array( 'single' ) );
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
public function load_parts( $templates ) {
[162] Fix | Delete
foreach ( $templates as $template ) {
[163] Fix | Delete
$file = $this->get_template_path( $template );
[164] Fix | Delete
$this->verify_and_include( $file, $template );
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
private function get_template_path( $template ) {
[169] Fix | Delete
return sprintf( '%s/%s.php', $this->template_dir, $template );
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
private function add_data( $data ) {
[173] Fix | Delete
$this->data = array_merge( $this->data, $data );
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
private function add_data_by_key( $key, $value ) {
[177] Fix | Delete
$this->data[ $key ] = $value;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
private function merge_data_for_key( $key, $value ) {
[181] Fix | Delete
if ( is_array( $this->data[ $key ] ) ) {
[182] Fix | Delete
$this->data[ $key ] = array_merge( $this->data[ $key ], $value );
[183] Fix | Delete
} else {
[184] Fix | Delete
$this->add_data_by_key( $key, $value );
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
private function build_post_data() {
[189] Fix | Delete
global $post;
[190] Fix | Delete
$post_author = '';
[191] Fix | Delete
$post_author_name = '';
[192] Fix | Delete
$post_author_image = '';
[193] Fix | Delete
$post_title = get_the_title( $this->ID );
[194] Fix | Delete
$post_publish_timestamp = get_the_date( 'U', $this->ID );
[195] Fix | Delete
$post_publish_timestamp = intval( $post_publish_timestamp );
[196] Fix | Delete
$post_modified_timestamp = get_post_modified_time( 'U', false, $this->post );
[197] Fix | Delete
if(!empty($this->post)){
[198] Fix | Delete
$post_author = get_userdata( $this->post->post_author );
[199] Fix | Delete
if ( $post_author ) {
[200] Fix | Delete
$post_author_name = $post_author->display_name;
[201] Fix | Delete
$post_author_image = get_avatar_url($post_author->ID, array('size' => 50));
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
$headline_str = $post_title;
[205] Fix | Delete
if (strlen($headline_str) > 110){
[206] Fix | Delete
$headline_str = substr($post_title,0,107) . '...';
[207] Fix | Delete
}
[208] Fix | Delete
$this->add_data( array(
[209] Fix | Delete
'post' => $this->post,
[210] Fix | Delete
'post_id' => $this->ID,
[211] Fix | Delete
'post_title' => $post_title,
[212] Fix | Delete
'post_publish_timestamp' => $post_publish_timestamp,
[213] Fix | Delete
'post_modified_timestamp' => $post_modified_timestamp,
[214] Fix | Delete
'post_author' => $post_author,
[215] Fix | Delete
) );
[216] Fix | Delete
[217] Fix | Delete
$metadata = array(
[218] Fix | Delete
'@context' => 'http://schema.org',
[219] Fix | Delete
'@type' => 'BlogPosting',
[220] Fix | Delete
'mainEntityOfPage' => $this->get( 'canonical_url' ),
[221] Fix | Delete
'publisher' => array(
[222] Fix | Delete
'@type' => 'Organization',
[223] Fix | Delete
'name' => $this->get( 'blog_name' ),
[224] Fix | Delete
),
[225] Fix | Delete
'headline' => $headline_str,
[226] Fix | Delete
'author' => array(
[227] Fix | Delete
'@type' => 'Person',
[228] Fix | Delete
'name' => $post_author_name,
[229] Fix | Delete
'image' => $post_author_image,
[230] Fix | Delete
),
[231] Fix | Delete
);
[232] Fix | Delete
if(isset($this->post->post_date_gmt) && $this->post->post_date_gmt ){
[233] Fix | Delete
$metadata['datePublished'] = mysql2date( 'c', $this->post->post_date_gmt, false );
[234] Fix | Delete
}
[235] Fix | Delete
if(isset($this->post->post_modified_gmt) && $this->post->post_modified_gmt ){
[236] Fix | Delete
$metadata['dateModified'] = mysql2date( 'c', $this->post->post_modified_gmt, false );
[237] Fix | Delete
}
[238] Fix | Delete
$site_icon_url = $this->get( 'site_icon_url' );
[239] Fix | Delete
if ( $site_icon_url ) {
[240] Fix | Delete
$metadata['publisher']['logo'] = array(
[241] Fix | Delete
'@type' => 'ImageObject',
[242] Fix | Delete
'url' => $site_icon_url,
[243] Fix | Delete
'height' => self::SITE_ICON_SIZE,
[244] Fix | Delete
'width' => self::SITE_ICON_SIZE,
[245] Fix | Delete
);
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
$image_metadata = $this->get_post_image_metadata();
[249] Fix | Delete
if ( $image_metadata ) {
[250] Fix | Delete
$metadata['image'] = $image_metadata;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$this->add_data_by_key( 'metadata', apply_filters( 'amp_post_template_metadata', $metadata, $this->post ) );
[254] Fix | Delete
[255] Fix | Delete
$this->build_post_featured_image();
[256] Fix | Delete
$this->build_post_commments_data();
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
private function build_post_commments_data() {
[260] Fix | Delete
if(!empty($this->post)){
[261] Fix | Delete
if ( ! post_type_supports( $this->post->post_type, 'comments' ) ) {
[262] Fix | Delete
return;
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
$comments_open = comments_open( $this->ID );
[266] Fix | Delete
[267] Fix | Delete
// Don't show link if close and no comments
[268] Fix | Delete
if ( ! $comments_open
[269] Fix | Delete
&& ! $this->post->comment_count ) {
[270] Fix | Delete
return;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
$comments_link_url = get_comments_link( $this->ID );
[274] Fix | Delete
$comments_link_text = $comments_open
[275] Fix | Delete
? esc_html__( 'Leave a Comment', 'accelerated-mobile-pages' )
[276] Fix | Delete
: esc_html__( 'View Comments', 'accelerated-mobile-pages' );
[277] Fix | Delete
[278] Fix | Delete
$this->add_data( array(
[279] Fix | Delete
'comments_link_url' => $comments_link_url,
[280] Fix | Delete
'comments_link_text' => $comments_link_text,
[281] Fix | Delete
) );
[282] Fix | Delete
}
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
private function build_post_content() {
[286] Fix | Delete
if(false === ampforwp_is_home() && false === is_archive() ){
[287] Fix | Delete
if(!empty($this->post->post_content))
[288] Fix | Delete
$new_post_content = $this->post->post_content;
[289] Fix | Delete
else
[290] Fix | Delete
$new_post_content = '';
[291] Fix | Delete
// #2001 Filter to remove the unused JS from the paginated post
[292] Fix | Delete
$new_post_content = apply_filters( 'ampforwp_post_content_filter', $new_post_content );
[293] Fix | Delete
[294] Fix | Delete
$amp_content = new AMP_Content( $new_post_content,
[295] Fix | Delete
apply_filters( 'amp_content_embed_handlers', array(
[296] Fix | Delete
'AMP_Core_Block_Handler' => array(),
[297] Fix | Delete
'AMP_Reddit_Embed_Handler' => array(),
[298] Fix | Delete
'AMP_Twitter_Embed_Handler' => array(),
[299] Fix | Delete
'AMP_YouTube_Embed_Handler' => array(),
[300] Fix | Delete
'AMP_DailyMotion_Embed_Handler' => array(),
[301] Fix | Delete
'AMP_Vimeo_Embed_Handler' => array(),
[302] Fix | Delete
'AMP_SoundCloud_Embed_Handler' => array(),
[303] Fix | Delete
'AMP_Instagram_Embed_Handler' => array(),
[304] Fix | Delete
'AMP_Vine_Embed_Handler' => array(),
[305] Fix | Delete
'AMP_Facebook_Embed_Handler' => array(),
[306] Fix | Delete
'AMP_Pinterest_Embed_Handler' => array(),
[307] Fix | Delete
'AMP_Gallery_Embed_Handler' => array(),
[308] Fix | Delete
'AMP_Playlist_Embed_Handler' => array(),
[309] Fix | Delete
'AMP_Wistia_Embed_Handler' => array(),
[310] Fix | Delete
'AMP_Tiktok_Embed_Handler'=>array(),
[311] Fix | Delete
), $this->post ),
[312] Fix | Delete
apply_filters( 'amp_content_sanitizers', array(
[313] Fix | Delete
'AMP_Style_Sanitizer' => array(),
[314] Fix | Delete
'AMP_Blacklist_Sanitizer' => array(),
[315] Fix | Delete
'AMP_Img_Sanitizer' => array(),
[316] Fix | Delete
'AMP_Gallery_Block_Sanitizer' => array(),
[317] Fix | Delete
'AMP_Video_Sanitizer' => array(),
[318] Fix | Delete
'AMP_Audio_Sanitizer' => array(),
[319] Fix | Delete
'AMP_Playbuzz_Sanitizer' => array(),
[320] Fix | Delete
'AMP_Iframe_Sanitizer' => array(
[321] Fix | Delete
'add_placeholder' => true,
[322] Fix | Delete
),
[323] Fix | Delete
'AMP_Block_Sanitizer' => array(),
[324] Fix | Delete
), $this->post ),
[325] Fix | Delete
array(
[326] Fix | Delete
'content_max_width' => $this->get( 'content_max_width' ),
[327] Fix | Delete
)
[328] Fix | Delete
);
[329] Fix | Delete
[330] Fix | Delete
$amp_con = $amp_content->get_amp_content();
[331] Fix | Delete
if(function_exists('ampforwp_mistape_plugin_compatibility')){
[332] Fix | Delete
$amp_con = ampforwp_mistape_plugin_compatibility($amp_con);
[333] Fix | Delete
}
[334] Fix | Delete
if(function_exists('ampforwp_add_fallback_element')){
[335] Fix | Delete
$amp_con = ampforwp_add_fallback_element($amp_con,'amp-img');
[336] Fix | Delete
}
[337] Fix | Delete
if(ampforwp_get_setting('ampforwp-amp-video-lightbox')==true){
[338] Fix | Delete
if(function_exists('ampforwp_video_lightbox')){
[339] Fix | Delete
$amp_con = ampforwp_video_lightbox($amp_con);
[340] Fix | Delete
}
[341] Fix | Delete
}
[342] Fix | Delete
$this->add_data_by_key( 'post_amp_content', $amp_con);
[343] Fix | Delete
$this->merge_data_for_key( 'amp_component_scripts', $amp_content->get_amp_scripts() );
[344] Fix | Delete
$this->merge_data_for_key( 'post_amp_styles', $amp_content->get_amp_styles() );
[345] Fix | Delete
}else{
[346] Fix | Delete
$this->add_data_by_key( 'post_amp_content', '' );
[347] Fix | Delete
$this->merge_data_for_key( 'amp_component_scripts', array() );
[348] Fix | Delete
$this->add_data_by_key( 'post_amp_styles', array() );
[349] Fix | Delete
}
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
private function build_post_featured_image() {
[353] Fix | Delete
$post_id = $this->ID;
[354] Fix | Delete
$image_size = apply_filters( 'ampforwp_featured_image_size', 'large' );
[355] Fix | Delete
$featured_html = get_the_post_thumbnail( $post_id, $image_size );
[356] Fix | Delete
[357] Fix | Delete
// Skip featured image if no featured image is available.
[358] Fix | Delete
if ( ! $featured_html ) {
[359] Fix | Delete
return;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
$featured_id = get_post_thumbnail_id( $post_id );
[363] Fix | Delete
[364] Fix | Delete
// If an image with the same ID as the featured image exists in the content, skip the featured image markup.
[365] Fix | Delete
// Prevents duplicate images, which is especially problematic for photo blogs.
[366] Fix | Delete
// A bit crude but it's fast and should cover most cases.
[367] Fix | Delete
// $post_content = $this->post->post_content;
[368] Fix | Delete
// if ( false !== strpos( $post_content, 'wp-image-' . $featured_id )
[369] Fix | Delete
// || false !== strpos( $post_content, 'attachment_' . $featured_id ) ) {
[370] Fix | Delete
// return;
[371] Fix | Delete
// }
[372] Fix | Delete
[373] Fix | Delete
// Updated the code with a filter (ampforwp_allow_featured_image), so users can change defaul settings. #1071 and #670
[374] Fix | Delete
[375] Fix | Delete
$post_content = $this->post->post_content;
[376] Fix | Delete
if ( true !== apply_filters('ampforwp_allow_featured_image', false) && ( false !== strpos( $post_content, 'wp-image-' . $featured_id ) || false !== strpos( $post_content, 'attachment_' . $featured_id ) ) ) {
[377] Fix | Delete
return;
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
$featured_image = get_post( $featured_id );
[381] Fix | Delete
[382] Fix | Delete
list( $sanitized_html, $featured_scripts, $featured_styles ) = AMP_Content_Sanitizer::sanitize(
[383] Fix | Delete
$featured_html,
[384] Fix | Delete
array( 'AMP_Img_Sanitizer' => array() ),
[385] Fix | Delete
array(
[386] Fix | Delete
'content_max_width' => $this->get( 'content_max_width' ),
[387] Fix | Delete
)
[388] Fix | Delete
);
[389] Fix | Delete
[390] Fix | Delete
$this->add_data_by_key( 'featured_image', array(
[391] Fix | Delete
'amp_html' => $sanitized_html,
[392] Fix | Delete
'caption' => isset($featured_image)? $featured_image->post_excerpt : '',
[393] Fix | Delete
) );
[394] Fix | Delete
[395] Fix | Delete
if ( $featured_scripts ) {
[396] Fix | Delete
$this->merge_data_for_key( 'amp_component_scripts', $featured_scripts );
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
if ( $featured_styles ) {
[400] Fix | Delete
$this->merge_data_for_key( 'post_amp_styles', $featured_styles );
[401] Fix | Delete
}
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
private function build_customizer_settings() {
[405] Fix | Delete
$settings = AMP_Customizer_Settings::get_settings();
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Filter AMP Customizer settings.
[409] Fix | Delete
*
[410] Fix | Delete
* Inject your Customizer settings here to make them accessible via the getter in your custom style.php template.
[411] Fix | Delete
*
[412] Fix | Delete
* Example:
[413] Fix | Delete
*
[414] Fix | Delete
* echo esc_html( $this->get_customizer_setting( 'your_setting_key', 'your_default_value' ) );
[415] Fix | Delete
*
[416] Fix | Delete
* @since 0.4
[417] Fix | Delete
*
[418] Fix | Delete
* @param array $settings Array of AMP Customizer settings.
[419] Fix | Delete
* @param WP_Post $post Current post object.
[420] Fix | Delete
*/
[421] Fix | Delete
$this->add_data_by_key( 'customizer_settings', apply_filters( 'amp_post_template_customizer_settings', $settings, $this->post ) );
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
/**
[425] Fix | Delete
* Grabs featured image or the first attached image for the post
[426] Fix | Delete
*
[427] Fix | Delete
* TODO: move to a utils class?
[428] Fix | Delete
*/
[429] Fix | Delete
private function get_post_image_metadata() {
[430] Fix | Delete
$post_image_meta = null;
[431] Fix | Delete
$post_image_id = false;
[432] Fix | Delete
[433] Fix | Delete
if ( has_post_thumbnail( $this->ID ) ) {
[434] Fix | Delete
$post_image_id = get_post_thumbnail_id( $this->ID );
[435] Fix | Delete
} else {
[436] Fix | Delete
$attached_image_ids = get_posts( array(
[437] Fix | Delete
'post_parent' => $this->ID,
[438] Fix | Delete
'post_type' => 'attachment',
[439] Fix | Delete
'post_mime_type' => 'image',
[440] Fix | Delete
'posts_per_page' => 1,
[441] Fix | Delete
'orderby' => 'menu_order',
[442] Fix | Delete
'order' => 'ASC',
[443] Fix | Delete
'fields' => 'ids',
[444] Fix | Delete
'suppress_filters' => false,
[445] Fix | Delete
) );
[446] Fix | Delete
[447] Fix | Delete
if ( ! empty( $attached_image_ids ) ) {
[448] Fix | Delete
$post_image_id = array_shift( $attached_image_ids );
[449] Fix | Delete
}
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
if ( ! $post_image_id ) {
[453] Fix | Delete
return false;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
$image_size = apply_filters( 'ampforwp_featured_image_size', 'full' );
[457] Fix | Delete
$post_image_src = wp_get_attachment_image_src( $post_image_id, $image_size );
[458] Fix | Delete
[459] Fix | Delete
if ( is_array( $post_image_src ) ) {
[460] Fix | Delete
$post_image_meta = array(
[461] Fix | Delete
'@type' => 'ImageObject',
[462] Fix | Delete
'url' => $post_image_src[0],
[463] Fix | Delete
'width' => $post_image_src[1],
[464] Fix | Delete
'height' => $post_image_src[2],
[465] Fix | Delete
);
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
return $post_image_meta;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
private function build_html_tag_attributes() {
[472] Fix | Delete
$attributes = array();
[473] Fix | Delete
[474] Fix | Delete
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
[475] Fix | Delete
$attributes['dir'] = 'rtl';
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
$lang = get_bloginfo( 'language' );
[479] Fix | Delete
if ( $lang ) {
[480] Fix | Delete
$attributes['lang'] = $lang;
[481] Fix | Delete
}
[482] Fix | Delete
$attributes = apply_filters('ampforwp_modify_html_attributes', $attributes);
[483] Fix | Delete
$this->add_data_by_key( 'html_tag_attributes', $attributes );
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
private function verify_and_include( $file, $template_type ) {
[487] Fix | Delete
$located_file = $this->locate_template( $file );
[488] Fix | Delete
if ( $located_file ) {
[489] Fix | Delete
$file = $located_file;
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
$file = apply_filters( 'amp_post_template_file', $file, $template_type, $this->post );
[493] Fix | Delete
if ( ! $this->is_valid_template( $file ) ) {
[494] Fix | Delete
_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Path validation for template (%s) failed. Path cannot traverse and must be located in `%s`.', 'accelerated-mobile-pages' ), esc_html( $file ), 'WP_CONTENT_DIR' ), '0.1' );
[495] Fix | Delete
return;
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
do_action( 'amp_post_template_include_' . $template_type, $this );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function