replacement = null; if ( ! empty( $this->args->ID ) ) { $replacement = $this->args->ID; } return $replacement; } /** * Retrieve the post/page/cpt modified time for use as replacement string. * * @return string|null */ private function retrieve_modified() { $replacement = null; if ( ! empty( $this->args->post_modified ) ) { $replacement = mysql2date( get_option( 'date_format' ), $this->args->post_modified, true ); } return $replacement; } /** * Retrieve the post/page/cpt author's "nice name" for use as replacement string. * * @return string|null */ private function retrieve_name() { $replacement = null; $user_id = $this->retrieve_userid(); $name = get_the_author_meta( 'display_name', $user_id ); if ( $name !== '' ) { $replacement = $name; } return $replacement; } /** * Retrieve the post/page/cpt author's users description for use as a replacement string. * * @return null|string */ private function retrieve_user_description() { $replacement = null; $user_id = $this->retrieve_userid(); $description = get_the_author_meta( 'description', $user_id ); if ( $description !== '' ) { $replacement = $description; } return $replacement; } /** * Retrieve the current page number with context (i.e. 'page 2 of 4') for use as replacement string. * * @return string */ private function retrieve_page() { $replacement = null; $max = $this->determine_pagenumbering( 'max' ); $nr = $this->determine_pagenumbering( 'nr' ); $sep = $this->retrieve_sep(); if ( $max > 1 && $nr > 1 ) { /* translators: 1: current page number, 2: total number of pages. */ $replacement = sprintf( $sep . ' ' . __( 'Page %1$d of %2$d', 'wordpress-seo' ), $nr, $max ); } return $replacement; } /** * Retrieve the current page number for use as replacement string. * * @return string|null */ private function retrieve_pagenumber() { $replacement = null; $nr = $this->determine_pagenumbering( 'nr' ); if ( isset( $nr ) && $nr > 0 ) { $replacement = (string) $nr; } return $replacement; } /** * Retrieve the current page total for use as replacement string. * * @return string|null */ private function retrieve_pagetotal() { $replacement = null; $max = $this->determine_pagenumbering( 'max' ); if ( isset( $max ) && $max > 0 ) { $replacement = (string) $max; } return $replacement; } /** * Retrieve the post type plural label for use as replacement string. * * @return string|null */ private function retrieve_pt_plural() { $replacement = null; $name = $this->determine_pt_names( 'plural' ); if ( isset( $name ) && $name !== '' ) { $replacement = $name; } return $replacement; } /** * Retrieve the post type single label for use as replacement string. * * @return string|null */ private function retrieve_pt_single() { $replacement = null; $name = $this->determine_pt_names( 'single' ); if ( isset( $name ) && $name !== '' ) { $replacement = $name; } return $replacement; } /** * Retrieve the slug which caused the 404 for use as replacement string. * * @return string|null */ private function retrieve_term404() { $replacement = null; if ( $this->args->term404 !== '' ) { $replacement = sanitize_text_field( str_replace( '-', ' ', $this->args->term404 ) ); } else { $error_request = get_query_var( 'pagename' ); if ( $error_request !== '' ) { $replacement = sanitize_text_field( str_replace( '-', ' ', $error_request ) ); } else { $error_request = get_query_var( 'name' ); if ( $error_request !== '' ) { $replacement = sanitize_text_field( str_replace( '-', ' ', $error_request ) ); } } } return $replacement; } /** * Retrieve the post/page/cpt author's user id for use as replacement string. * * @return string */ private function retrieve_userid() { $replacement = ! empty( $this->args->post_author ) ? $this->args->post_author : get_query_var( 'author' ); return $replacement; } /* *********************** HELP TEXT RELATED ************************** */ /** * Create a variable help text table. * * @param string $type Either 'basic' or 'advanced'. * * @return string Help text table. */ private static function create_variable_help_table( $type ) { if ( ! in_array( $type, array( 'basic', 'advanced' ), true ) ) { return ''; } $table = '
' . esc_html__( 'Label', 'wordpress-seo' ) . ' | ' . esc_html__( 'Variable', 'wordpress-seo' ) . ' | ' . esc_html__( 'Description', 'wordpress-seo' ) . ' |
---|---|---|
' . esc_html( $replacement_variable->get_label() ) . ' | %%' . esc_html( $replacement_variable->get_variable() ) . '%% | ' . esc_html( $replacement_variable->get_description() ) . ' |
wp_title()
'
'wp_title()'
);
$replacement_variables = array(
new WPSEO_Replacement_Variable( 'date', __( 'Date', 'wordpress-seo' ), __( 'Replaced with the date of the post/page', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'title', __( 'Title', 'wordpress-seo' ), __( 'Replaced with the title of the post/page', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'parent_title', __( 'Parent title', 'wordpress-seo' ), __( 'Replaced with the title of the parent page of the current page', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'archive_title', __( 'Archive title', 'wordpress-seo' ), __( 'Replaced with the normal title for an archive generated by WordPress', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'sitename', __( 'Site title', 'wordpress-seo' ), __( 'The site\'s name', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'sitedesc', __( 'Tagline', 'wordpress-seo' ), __( 'The site\'s tagline', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'excerpt', __( 'Excerpt', 'wordpress-seo' ), __( 'Replaced with the post/page excerpt (or auto-generated if it does not exist)', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'excerpt_only', __( 'Excerpt only', 'wordpress-seo' ), __( 'Replaced with the post/page excerpt (without auto-generation)', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'tag', __( 'Tag', 'wordpress-seo' ), __( 'Replaced with the current tag/tags', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'category', __( 'Category', 'wordpress-seo' ), __( 'Replaced with the post categories (comma separated)', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'primary_category', __( 'Primary category', 'wordpress-seo' ), __( 'Replaced with the primary category of the post/page', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'category_description', __( 'Category description', 'wordpress-seo' ), __( 'Replaced with the category description', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'tag_description', __( 'Tag description', 'wordpress-seo' ), __( 'Replaced with the tag description', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'term_description', __( 'Term description', 'wordpress-seo' ), __( 'Replaced with the term description', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'term_title', __( 'Term title', 'wordpress-seo' ), __( 'Replaced with the term name', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'searchphrase', __( 'Search phrase', 'wordpress-seo' ), __( 'Replaced with the current search phrase', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'sep', __( 'Separator', 'wordpress-seo' ), $separator_description ),
);
foreach ( $replacement_variables as $replacement_variable ) {
self::register_help_text( 'basic', $replacement_variable );
}
}
/**
* Set/translate the help texts for the WPSEO standard advanced variables.
*/
private static function set_advanced_help_texts() {
$replacement_variables = array(
new WPSEO_Replacement_Variable( 'pt_single', __( 'Post type (singular)', 'wordpress-seo' ), __( 'Replaced with the content type single label', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'pt_plural', __( 'Post type (plural)', 'wordpress-seo' ), __( 'Replaced with the content type plural label', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'modified', __( 'Modified', 'wordpress-seo' ), __( 'Replaced with the post/page modified time', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'id', __( 'ID', 'wordpress-seo' ), __( 'Replaced with the post/page ID', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'name', __( 'Name', 'wordpress-seo' ), __( 'Replaced with the post/page author\'s \'nicename\'', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'user_description', __( 'User description', 'wordpress-seo' ), __( 'Replaced with the post/page author\'s \'Biographical Info\'', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'page', __( 'Page number', 'wordpress-seo' ), __( 'Replaced with the current page number with context (i.e. page 2 of 4)', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'pagetotal', __( 'Pagetotal', 'wordpress-seo' ), __( 'Replaced with the current page total', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'pagenumber', __( 'Pagenumber', 'wordpress-seo' ), __( 'Replaced with the current page number', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'caption', __( 'Caption', 'wordpress-seo' ), __( 'Attachment caption', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'focuskw', __( 'Focus keyword', 'wordpress-seo' ), __( 'Replaced with the posts focus keyphrase', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'term404', __( 'Term404', 'wordpress-seo' ), __( 'Replaced with the slug which caused the 404', 'wordpress-seo' ) ),
new WPSEO_Replacement_Variable( 'cf_