Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/seo-tool...
File: class-jetpack-seo.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Main class file for the SEO Tools module.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* An SEO expert walks into a bar, bars, pub, public house, Irish pub, drinks, beer, wine, liquor, Grey Goose, Cristal...
[8] Fix | Delete
*
[9] Fix | Delete
* @phan-constructor-used-for-side-effects
[10] Fix | Delete
*/
[11] Fix | Delete
class Jetpack_SEO {
[12] Fix | Delete
/**
[13] Fix | Delete
* Constructor.
[14] Fix | Delete
*/
[15] Fix | Delete
public function __construct() {
[16] Fix | Delete
add_action( 'init', array( $this, 'init' ) );
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Initialization method for Jetpack_SEO.
[21] Fix | Delete
*/
[22] Fix | Delete
public function init() {
[23] Fix | Delete
/**
[24] Fix | Delete
* Can be used to prevent SEO tools from inserting custom meta tags.
[25] Fix | Delete
*
[26] Fix | Delete
* @module seo-tools
[27] Fix | Delete
*
[28] Fix | Delete
* @since 4.4.0
[29] Fix | Delete
*
[30] Fix | Delete
* @param bool true Should Jetpack's SEO Meta Tags be enabled. Defaults to true.
[31] Fix | Delete
*/
[32] Fix | Delete
if ( apply_filters( 'jetpack_seo_meta_tags_enabled', true ) ) {
[33] Fix | Delete
add_action( 'wp_head', array( $this, 'meta_tags' ) );
[34] Fix | Delete
[35] Fix | Delete
// Add support for editing page excerpts in pages, regardless of theme support.
[36] Fix | Delete
add_post_type_support( 'page', 'excerpt' );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Can be used to prevent SEO tools from modifying site titles.
[41] Fix | Delete
*
[42] Fix | Delete
* @module seo-tools
[43] Fix | Delete
*
[44] Fix | Delete
* @since 4.4.0
[45] Fix | Delete
*
[46] Fix | Delete
* @param bool true Should Jetpack SEO modify site titles. Defaults to true.
[47] Fix | Delete
*/
[48] Fix | Delete
if ( apply_filters( 'jetpack_seo_custom_titles', true ) ) {
[49] Fix | Delete
// Overwrite page title with custom SEO meta title for themes that support title-tag.
[50] Fix | Delete
add_filter( 'pre_get_document_title', array( 'Jetpack_SEO_Titles', 'get_custom_title' ) );
[51] Fix | Delete
[52] Fix | Delete
// Add overwrite support for themes that don't support title-tag.
[53] Fix | Delete
add_filter( 'wp_title', array( 'Jetpack_SEO_Titles', 'get_custom_title' ) );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
add_filter( 'jetpack_open_graph_tags', array( $this, 'set_custom_og_tags' ) );
[57] Fix | Delete
Jetpack_SEO_Posts::register_post_meta();
[58] Fix | Delete
// Exclude posts with 'jetpack_seo_noindex' set true from the Jetpack sitemap.
[59] Fix | Delete
add_filter( 'jetpack_sitemap_skip_post', array( 'Jetpack_SEO_Posts', 'exclude_noindex_posts_from_jetpack_sitemap' ), 10, 2 );
[60] Fix | Delete
add_action( 'rest_api_init', array( $this, 'add_custom_field_post_type_meta' ) );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Add custom field meta to all public post types that don't already have it.
[65] Fix | Delete
*/
[66] Fix | Delete
public function add_custom_field_post_type_meta() {
[67] Fix | Delete
/**
[68] Fix | Delete
* Filter the list of post types for which custom fields support is added.
[69] Fix | Delete
*
[70] Fix | Delete
* This filter allows modification of the post types that will be processed
[71] Fix | Delete
* to add support for custom fields if they do not already support it.
[72] Fix | Delete
*
[73] Fix | Delete
* @since 14.2
[74] Fix | Delete
*
[75] Fix | Delete
* @param array $post_types An array of post type names.
[76] Fix | Delete
*/
[77] Fix | Delete
$post_types = apply_filters(
[78] Fix | Delete
'jetpack_seo_custom_field_post_types',
[79] Fix | Delete
get_post_types(
[80] Fix | Delete
array(
[81] Fix | Delete
'public' => true,
[82] Fix | Delete
'show_ui' => true,
[83] Fix | Delete
'_builtin' => false,
[84] Fix | Delete
)
[85] Fix | Delete
)
[86] Fix | Delete
);
[87] Fix | Delete
[88] Fix | Delete
foreach ( $post_types as $post_type ) {
[89] Fix | Delete
if ( ! post_type_supports( $post_type, 'custom-fields' ) ) {
[90] Fix | Delete
add_post_type_support( $post_type, 'custom-fields' );
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Helper method to fetch authors.
[97] Fix | Delete
*/
[98] Fix | Delete
private function get_authors() {
[99] Fix | Delete
global $wp_query;
[100] Fix | Delete
[101] Fix | Delete
$authors = array();
[102] Fix | Delete
[103] Fix | Delete
foreach ( $wp_query->posts as $post ) {
[104] Fix | Delete
if ( ! $post instanceof WP_Post ) {
[105] Fix | Delete
continue;
[106] Fix | Delete
}
[107] Fix | Delete
$authors[] = get_the_author_meta( 'display_name', (int) $post->post_author );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$authors = array_unique( $authors );
[111] Fix | Delete
[112] Fix | Delete
return $authors;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Constructs open graph tag data.
[117] Fix | Delete
*
[118] Fix | Delete
* @param array $tags Array of tag data.
[119] Fix | Delete
* @return array of tag data.
[120] Fix | Delete
*/
[121] Fix | Delete
public function set_custom_og_tags( $tags ) {
[122] Fix | Delete
$custom_title = Jetpack_SEO_Titles::get_custom_title();
[123] Fix | Delete
[124] Fix | Delete
if ( ! empty( $custom_title ) ) {
[125] Fix | Delete
$tags['og:title'] = $custom_title;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$post_custom_description = Jetpack_SEO_Posts::get_post_custom_description( get_post() );
[129] Fix | Delete
$front_page_meta = Jetpack_SEO_Utils::get_front_page_meta_description();
[130] Fix | Delete
[131] Fix | Delete
if ( class_exists( 'woocommerce' ) && is_shop() ) {
[132] Fix | Delete
$shop_page_id = get_option( 'woocommerce_shop_page_id' );
[133] Fix | Delete
if ( $shop_page_id ) {
[134] Fix | Delete
$post_custom_description = Jetpack_SEO_Posts::get_post_custom_description( get_post( $shop_page_id ) );
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
if ( is_front_page() && ! empty( $front_page_meta ) ) {
[139] Fix | Delete
$tags['og:description'] = $front_page_meta;
[140] Fix | Delete
} elseif ( ! empty( $post_custom_description ) ) {
[141] Fix | Delete
$tags['og:description'] = $post_custom_description;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
return $tags;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Outputs Jetpack's SEO <meta> tags.
[149] Fix | Delete
*/
[150] Fix | Delete
public function meta_tags() {
[151] Fix | Delete
global $wp_query;
[152] Fix | Delete
[153] Fix | Delete
$post_count = is_countable( $wp_query->posts ) ? count( $wp_query->posts ) : 0;
[154] Fix | Delete
$period = '';
[155] Fix | Delete
$template = '';
[156] Fix | Delete
$meta = array();
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Can be used to specify a list of themes that set their own meta tags.
[160] Fix | Delete
*
[161] Fix | Delete
* If current site is using one of the themes listed as conflicting, inserting Jetpack SEO
[162] Fix | Delete
* meta tags will be prevented.
[163] Fix | Delete
*
[164] Fix | Delete
* @module seo-tools
[165] Fix | Delete
*
[166] Fix | Delete
* @since 4.4.0
[167] Fix | Delete
*
[168] Fix | Delete
* @param array List of conflicted theme names. Defaults to empty array.
[169] Fix | Delete
*/
[170] Fix | Delete
$conflicted_themes = apply_filters( 'jetpack_seo_meta_tags_conflicted_themes', array() );
[171] Fix | Delete
[172] Fix | Delete
if ( isset( $conflicted_themes[ get_option( 'template' ) ] ) ) {
[173] Fix | Delete
return;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
$front_page_meta = Jetpack_SEO_Utils::get_front_page_meta_description();
[177] Fix | Delete
$description = $front_page_meta ? $front_page_meta : get_bloginfo( 'description' );
[178] Fix | Delete
$meta['description'] = trim( $description );
[179] Fix | Delete
[180] Fix | Delete
// Try to target things if we're on a "specific" page of any kind.
[181] Fix | Delete
if ( is_singular() ) {
[182] Fix | Delete
if ( ! ( is_front_page() && Jetpack_SEO_Utils::get_front_page_meta_description() ) ) {
[183] Fix | Delete
$description = Jetpack_SEO_Posts::get_post_description( get_post() );
[184] Fix | Delete
[185] Fix | Delete
if ( $description ) {
[186] Fix | Delete
$description = wp_trim_words(
[187] Fix | Delete
strip_shortcodes(
[188] Fix | Delete
wp_strip_all_tags( $description, true )
[189] Fix | Delete
)
[190] Fix | Delete
);
[191] Fix | Delete
$meta['description'] = $description;
[192] Fix | Delete
}
[193] Fix | Delete
}
[194] Fix | Delete
} elseif ( is_author() ) {
[195] Fix | Delete
$obj = get_queried_object();
[196] Fix | Delete
[197] Fix | Delete
$meta['description'] = sprintf(
[198] Fix | Delete
/* translators: first property is an user's display name, the second is the site's title. */
[199] Fix | Delete
_x( 'Read all of the posts by %1$s on %2$s', 'Read all of the posts by Author Name on Blog Title', 'jetpack' ),
[200] Fix | Delete
isset( $obj->display_name ) ? $obj->display_name : __( 'the author', 'jetpack' ),
[201] Fix | Delete
get_bloginfo( 'title' )
[202] Fix | Delete
);
[203] Fix | Delete
} elseif ( is_tag() || is_category() || is_tax() ) {
[204] Fix | Delete
$obj = get_queried_object();
[205] Fix | Delete
$description = '';
[206] Fix | Delete
[207] Fix | Delete
if ( isset( $obj->term_id ) && isset( $obj->taxonomy ) ) {
[208] Fix | Delete
$description = get_term_field( 'description', $obj->term_id, $obj->taxonomy, 'raw' );
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
if ( ! is_wp_error( $description ) && $description ) {
[212] Fix | Delete
$meta['description'] = wp_trim_words( $description );
[213] Fix | Delete
} else {
[214] Fix | Delete
$authors = $this->get_authors();
[215] Fix | Delete
[216] Fix | Delete
$meta['description'] = wp_sprintf(
[217] Fix | Delete
/* translators: %1$s: A post category. %2$l: Post authors. */
[218] Fix | Delete
_x( 'Posts about %1$s written by %2$l', 'Posts about Category written by John and Bob', 'jetpack' ),
[219] Fix | Delete
single_term_title( '', false ),
[220] Fix | Delete
$authors
[221] Fix | Delete
);
[222] Fix | Delete
}
[223] Fix | Delete
} elseif ( is_date() ) {
[224] Fix | Delete
if ( is_year() ) {
[225] Fix | Delete
$period = get_query_var( 'year' );
[226] Fix | Delete
[227] Fix | Delete
/* translators: %1$s: Number of posts published. %2$l: Post author. %3$s: A year date. */
[228] Fix | Delete
$template = _nx(
[229] Fix | Delete
'%1$s post published by %2$l in the year %3$s', // Singular.
[230] Fix | Delete
'%1$s posts published by %2$l in the year %3$s', // Plural.
[231] Fix | Delete
$post_count, // Number.
[232] Fix | Delete
'10 posts published by John in the year 2012', // Context.
[233] Fix | Delete
'jetpack'
[234] Fix | Delete
);
[235] Fix | Delete
} elseif ( is_month() ) {
[236] Fix | Delete
$period = gmdate( 'F Y', mktime( 0, 0, 0, get_query_var( 'monthnum' ), 1, get_query_var( 'year' ) ) );
[237] Fix | Delete
[238] Fix | Delete
/* translators: %1$s: Number of posts published. %2$l: Post author. %3$s: A month/year date. */
[239] Fix | Delete
$template = _nx(
[240] Fix | Delete
'%1$s post published by %2$l during %3$s', // Singular.
[241] Fix | Delete
'%1$s posts published by %2$l during %3$s', // Plural.
[242] Fix | Delete
$post_count, // Number.
[243] Fix | Delete
'10 posts publishes by John during May 2012', // Context.
[244] Fix | Delete
'jetpack'
[245] Fix | Delete
);
[246] Fix | Delete
} elseif ( is_day() ) {
[247] Fix | Delete
$period = gmdate(
[248] Fix | Delete
'F j, Y',
[249] Fix | Delete
mktime( 0, 0, 0, get_query_var( 'monthnum' ), get_query_var( 'day' ), get_query_var( 'year' ) )
[250] Fix | Delete
);
[251] Fix | Delete
[252] Fix | Delete
/* translators: %1$s: Number of posts published. %2$l: Post author. %3$s: A month/day/year date. */
[253] Fix | Delete
$template = _nx(
[254] Fix | Delete
'%1$s post published by %2$l on %3$s', // Singular.
[255] Fix | Delete
'%1$s posts published by %2$l on %3$s', // Plural.
[256] Fix | Delete
$post_count, // Number.
[257] Fix | Delete
'10 posts published by John on May 30, 2012', // Context.
[258] Fix | Delete
'jetpack'
[259] Fix | Delete
);
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
$authors = $this->get_authors();
[263] Fix | Delete
$meta['description'] = wp_sprintf( $template, $post_count, $authors, $period );
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
$mark_as_noindex = Jetpack_SEO_Posts::get_post_noindex_setting( get_post() );
[267] Fix | Delete
if ( $mark_as_noindex ) {
[268] Fix | Delete
$meta['robots'] = 'noindex';
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Can be used to edit the default SEO tools meta tags.
[273] Fix | Delete
*
[274] Fix | Delete
* @module seo-tools
[275] Fix | Delete
*
[276] Fix | Delete
* @since 4.4.0
[277] Fix | Delete
*
[278] Fix | Delete
* @param array Array that consists of meta name and meta content pairs.
[279] Fix | Delete
*/
[280] Fix | Delete
$meta = apply_filters( 'jetpack_seo_meta_tags', $meta );
[281] Fix | Delete
[282] Fix | Delete
// Output them.
[283] Fix | Delete
foreach ( $meta as $name => $content ) {
[284] Fix | Delete
if ( ! empty( $content ) ) {
[285] Fix | Delete
echo '<meta name="' . esc_attr( $name ) . '" content="' . esc_attr( $content ) . '" />' . "\n";
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function