Skip to content

Commit

Permalink
Fixes more for #373 and #377
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Jan 12, 2019
1 parent d67478a commit db7266c
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 74 deletions.
84 changes: 52 additions & 32 deletions inc/classes/generate-description.class.php
Expand Up @@ -104,6 +104,7 @@ protected function get_open_graph_description_from_custom_field( $args, $escape
* Falls back to meta description.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @see $this->get_open_graph_description()
* @see $this->get_open_graph_description_from_custom_field()
*
Expand All @@ -114,13 +115,18 @@ protected function get_custom_open_graph_description_from_query() {
$desc = '';

if ( $this->is_real_front_page() ) {
$desc = $this->get_option( 'homepage_og_description' ) ?: '';
}
if ( ! $desc ) {
if ( $this->is_singular() ) {
$desc = $this->get_custom_field( '_open_graph_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
if ( $this->is_static_frontpage() ) {
$desc = $this->get_option( 'homepage_og_description' )
?: $this->get_custom_field( '_open_graph_description' )
?: ''; // precision alignment ok
} else {
$desc = $this->get_option( 'homepage_og_description' ) ?: '';
}
} elseif ( $this->is_singular() ) {
$desc = $this->get_custom_field( '_open_graph_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
} elseif ( $this->is_term_meta_capable() ) {
$desc = $this->get_description_from_custom_field();
}

return $desc;
Expand All @@ -131,7 +137,8 @@ protected function get_custom_open_graph_description_from_query() {
* Falls back to meta description.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @since 3.2.2: 1. Now tests for the home page as page prior getting custom field data.
* 2. Now obtains custom field data for terms.
* @see $this->get_open_graph_description()
* @see $this->get_open_graph_description_from_custom_field()
*
Expand All @@ -143,7 +150,7 @@ protected function get_custom_open_graph_description_from_args( array $args ) {
$desc = '';

if ( $args['taxonomy'] ) {
$desc = '';
$desc = $this->get_description_from_custom_field( $args );
} else {
if ( $this->is_static_frontpage( $args['id'] ) ) {
$desc = $this->get_option( 'homepage_og_description' )
Expand Down Expand Up @@ -213,6 +220,8 @@ protected function get_twitter_description_from_custom_field( $args, $escape ) {
* Falls back to Open Graph description.
*
* @since 3.1.0
* @since 3.2.2: 1. Now tests for the home page as page prior getting custom field data.
* 2. Now obtains custom field data for terms.
* @see $this->get_twitter_description()
* @see $this->get_twitter_description_from_custom_field()
*
Expand All @@ -223,17 +232,23 @@ protected function get_custom_twitter_description_from_query() {
$desc = '';

if ( $this->is_real_front_page() ) {
$desc = $this->get_option( 'homepage_twitter_description' )
?: $this->get_custom_field( '_twitter_description' )
?: $this->get_option( 'homepage_og_description' )
?: $this->get_custom_field( '_open_graph_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
} else {
if ( $this->is_singular() ) {
$desc = $this->get_custom_field( '_twitter_description' )
?: $this->get_custom_field( '_open_graph_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
if ( $this->is_static_frontpage() ) {
$desc = $this->get_option( 'homepage_twitter_description' )
?: $this->get_custom_field( '_twitter_description' )
?: $this->get_option( 'homepage_og_description' )
?: $this->get_custom_field( '_open_graph_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
} else {
$desc = $this->get_option( 'homepage_twitter_description' )
?: $this->get_option( 'homepage_og_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
}
} elseif ( $this->is_singular() ) {
$desc = $this->get_custom_field( '_twitter_description' )
?: $this->get_custom_field( '_open_graph_description' )
?: $this->get_description_from_custom_field(); // precision alignment ok.
} elseif ( $this->is_term_meta_capable() ) {
$desc = $this->get_description_from_custom_field();
}

return $desc;
Expand All @@ -244,7 +259,8 @@ protected function get_custom_twitter_description_from_query() {
* Falls back to Open Graph description.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @since 3.2.2: 1. Now tests for the home page as page prior getting custom field data.
* 2. Now obtains custom field data for terms.
* @see $this->get_twitter_description()
* @see $this->get_twitter_description_from_custom_field()
*
Expand All @@ -256,7 +272,7 @@ protected function get_custom_twitter_description_from_args( array $args ) {
$desc = '';

if ( $args['taxonomy'] ) {
$desc = '';
$desc = $this->get_description_from_custom_field( $args );
} else {
if ( $this->is_static_frontpage( $args['id'] ) ) {
$desc = $this->get_option( 'homepage_twitter_description' )
Expand Down Expand Up @@ -321,6 +337,7 @@ public function get_description_from_custom_field( $args = null, $escape = true
* Gets a custom description, based on expected or current query, without escaping.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @internal
* @see $this->get_description_from_custom_field()
*
Expand All @@ -331,15 +348,18 @@ protected function get_custom_description_from_query() {
$desc = '';

if ( $this->is_real_front_page() ) {
$desc = $this->get_option( 'homepage_description' ) ?: '';
}
if ( ! $desc ) {
if ( $this->is_singular() ) {
$desc = $this->get_custom_field( '_genesis_description' ) ?: '';
} elseif ( $this->is_term_meta_capable() ) {
$data = $this->get_term_meta( $this->get_the_real_ID() );
$desc = ! empty( $data['description'] ) ? $data['description'] : '';
if ( $this->is_static_frontpage() ) {
$desc = $this->get_option( 'homepage_description' )
?: $this->get_custom_field( '_genesis_description' )
?: ''; // precision alignment ok.
} else {
$desc = $this->get_option( 'homepage_description' ) ?: '';
}
} elseif ( $this->is_singular() ) {
$desc = $this->get_custom_field( '_genesis_description' ) ?: '';
} elseif ( $this->is_term_meta_capable() ) {
$data = $this->get_term_meta( $this->get_the_real_ID() );
$desc = ! empty( $data['description'] ) ? $data['description'] : '';
}

return $desc;
Expand All @@ -361,7 +381,6 @@ protected function get_custom_description_from_args( array $args ) {
$desc = '';

if ( $args['taxonomy'] ) {
// $term = \get_term( $args['id'], $args['taxonomy'] ); // redundant
$data = $this->get_term_meta( $args['id'] );
$desc = ! empty( $data['description'] ) ? $data['description'] : '';
} else {
Expand Down Expand Up @@ -504,6 +523,7 @@ protected function get_description_excerpt_from_query() {
* Returns a description excerpt for the current query.
*
* @since 3.1.0
* @since 3.2.2 Fixed front-page as blog logic.
*
* @param array|null $args An array of 'id' and 'taxonomy' values.
* @return string
Expand All @@ -517,7 +537,7 @@ protected function get_description_excerpt_from_args( array $args ) {
} else {
if ( $this->is_blog_page( $args['id'] ) ) {
$excerpt = $this->get_blog_page_description_excerpt();
} elseif ( $this->is_front_page_by_id( $args['id'] ) ) {
} elseif ( $this->is_real_front_page_by_id( $args['id'] ) ) {
$excerpt = $this->get_front_page_description_excerpt();
} else {
$excerpt = $this->get_singular_description_excerpt( $args['id'] );
Expand Down Expand Up @@ -580,7 +600,6 @@ protected function get_archival_description_excerpt( $term = null ) {

/**
* @since 3.1.0
*
* @param string $excerpt The short circuit excerpt.
* @param \WP_Term $term The Term object.
*/
Expand Down Expand Up @@ -633,6 +652,7 @@ protected function get_singular_description_excerpt( $id = null ) {
* @since 3.1.0
* @since 3.2.0 : 1. Now no longer listens to options.
* 2. Now only works for the front and blog pages.
* @since 3.2.2 Now works for home pages from external requests.
* @see $this->get_generated_description()
*
* @param array|null $args An array of 'id' and 'taxonomy' values.
Expand All @@ -648,7 +668,7 @@ protected function get_description_additions( $args, $forced = false ) {
$title = $this->get_raw_generated_title( $args );
/* translators: %s = Blog page title. Front-end output. */
$title = sprintf( \__( 'Latest posts: %s', 'autodescription' ), $title );
} elseif ( $this->is_front_page_by_id( $args['id'] ) ) {
} elseif ( $this->is_real_front_page_by_id( $args['id'] ) ) {
$title = $this->get_home_page_tagline();
}

Expand Down
6 changes: 3 additions & 3 deletions inc/classes/generate-image.class.php
Expand Up @@ -188,7 +188,7 @@ public function get_social_image( $args = [], $set_og_dimension = false ) {
goto end;
}

// FIXME: is_archive() = Patch for taxonomies taking incorrect images...
// FIXME: `! $this->is_archive()` = Patch for taxonomies taking incorrect images...
if ( $args['post_id'] && ! $this->is_archive() ) {
//* 2. Fetch image from SEO meta upload.
if ( $all_allowed || false === in_array( 'postmeta', $args['disallowed'], true ) ) {
Expand Down Expand Up @@ -496,7 +496,7 @@ public function get_social_image_url_from_post_thumbnail( $id, $args = [], $set_
if ( ! $image_id )
return '';

$args = $this->reparse_image_args( $args );
$args = $this->reparse_image_args( $args );
$args['get_the_real_ID'] = true;

$src = $this->parse_og_image( $image_id, $args, $set_og_dimensions );
Expand All @@ -522,7 +522,7 @@ public function get_social_image_url_from_attachment( $id, $args = [], $set_og_d
if ( ! \wp_attachment_is_image( $id ) )
return '';

$args = $this->reparse_image_args( $args );
$args = $this->reparse_image_args( $args );
$args['get_the_real_ID'] = true;

$src = $this->parse_og_image( $id, $args, $set_og_dimensions );
Expand Down
6 changes: 3 additions & 3 deletions inc/classes/generate-ldjson.class.php
Expand Up @@ -409,14 +409,14 @@ public function get_ld_json_breadcrumbs_page() {
* @since 3.0.0 1: Now only returns one crumb.
* 2: Now listens to primary term ID.
*
* @return string LD+JSON breadcrumbs script for Posts.
* @return string LD+JSON breadcrumbs script for Posts on success. Empty string on failure.
*/
public function get_ld_json_breadcrumbs_post() {

$output = '';

$post_id = $this->get_the_real_ID();
$post_type = \get_post_type( $post_id );
$post_id = $this->get_the_real_ID();
$post_type = \get_post_type( $post_id );
$taxonomies = $this->get_hierarchical_taxonomies_as( 'names', \get_post_type( $post_id ) );

/**
Expand Down
62 changes: 39 additions & 23 deletions inc/classes/generate-title.class.php
Expand Up @@ -187,6 +187,7 @@ protected function get_twitter_title_from_custom_field( $args, $escape ) {
* Falls back to Open Graph title.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @see $this->get_twitter_title()
* @see $this->get_twitter_title_from_custom_field()
*
Expand All @@ -197,14 +198,21 @@ protected function get_custom_twitter_title_from_query() {
$title = '';

if ( $this->is_real_front_page() ) {
$title = $this->get_option( 'homepage_twitter_title' ) ?: $this->get_option( 'homepage_og_title' ) ?: '';
}
if ( ! $title ) {
if ( $this->is_singular() ) {
$title = $this->get_custom_field( '_twitter_title' )
if ( $this->is_static_frontpage() ) {
$title = $this->get_option( 'homepage_twitter_title' )
?: $this->get_custom_field( '_twitter_title' )
?: $this->get_option( 'homepage_og_title' )
?: $this->get_custom_field( '_open_graph_title' )
?: ''; // precision alignment ok.
} else {
$title = $this->get_option( 'homepage_twitter_title' )
?: $this->get_option( 'homepage_og_title' )
?: ''; // precision alignment ok.
}
} elseif ( $this->is_singular() ) {
$title = $this->get_custom_field( '_twitter_title' )
?: $this->get_custom_field( '_open_graph_title' )
?: ''; // precision alignment ok.
}

return $title;
Expand Down Expand Up @@ -316,6 +324,7 @@ protected function get_open_graph_title_from_custom_field( $args, $escape ) {
* Falls back to meta title.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @see $this->get_open_graph_title()
* @see $this->get_open_graph_title_from_custom_field()
*
Expand All @@ -326,12 +335,15 @@ protected function get_custom_open_graph_title_from_query() {
$title = '';

if ( $this->is_real_front_page() ) {
$title = $this->get_option( 'homepage_og_title' ) ?: '';
}
if ( ! $title ) {
if ( $this->is_singular() ) {
$title = $this->get_custom_field( '_open_graph_title' ) ?: '';
if ( $this->is_static_frontpage() ) {
$title = $this->get_option( 'homepage_og_title' )
?: $this->get_custom_field( '_open_graph_title' )
?: ''; // precision alignment ok.
} else {
$title = $this->get_option( 'homepage_og_title' ) ?: '';
}
} elseif ( $this->is_singular() ) {
$title = $this->get_custom_field( '_open_graph_title' ) ?: '';
}

return $title;
Expand Down Expand Up @@ -418,6 +430,7 @@ public function get_raw_custom_field_title( $args = null ) {
* Gets a custom title, based on current query, without additions or prefixes.
*
* @since 3.1.0
* @since 3.2.2 Now tests for the home page as page prior getting custom field data.
* @internal
* @see $this->get_raw_custom_field_title()
*
Expand All @@ -428,15 +441,18 @@ protected function get_custom_field_title_from_query() {
$title = '';

if ( $this->is_real_front_page() ) {
$title = $this->get_option( 'homepage_title' ) ?: '';
}
if ( ! $title ) {
if ( $this->is_singular() ) {
$title = $this->get_custom_field( '_genesis_title' ) ?: '';
} elseif ( $this->is_term_meta_capable() ) {
$data = $this->get_term_meta( $this->get_the_real_ID() );
$title = ! empty( $data['doctitle'] ) ? $data['doctitle'] : '';
if ( $this->is_static_frontpage() ) {
$title = $this->get_option( 'homepage_title' )
?: $this->get_custom_field( '_genesis_title' )
?: ''; // precision alignment ok.
} else {
$title = $this->get_option( 'homepage_title' ) ?: '';
}
} elseif ( $this->is_singular() ) {
$title = $this->get_custom_field( '_genesis_title' ) ?: '';
} elseif ( $this->is_term_meta_capable() ) {
$_data = $this->get_term_meta( $this->get_the_real_ID() );
$title = ! empty( $_data['doctitle'] ) ? $_data['doctitle'] : '';
}

return $title;
Expand All @@ -458,9 +474,8 @@ protected function get_custom_field_title_from_args( array $args ) {
$title = '';

if ( $args['taxonomy'] ) {
// $term = \get_term( $args['id'], $args['taxonomy'] ); // redundant
$data = $this->get_term_meta( $args['id'] );
$title = ! empty( $data['doctitle'] ) ? $data['doctitle'] : '';
$_data = $this->get_term_meta( $args['id'] );
$title = ! empty( $_data['doctitle'] ) ? $_data['doctitle'] : '';
} else {
if ( $this->is_static_frontpage( $args['id'] ) ) {
$title = $this->get_option( 'homepage_title' )
Expand Down Expand Up @@ -667,6 +682,7 @@ public function get_generated_archive_title( $term = null ) {
return $title;

$use_prefix = $this->use_generated_archive_prefix();

$_tax = isset( $term->taxonomy ) ? $term->taxonomy : '';

if ( ! $_query ) {
Expand Down Expand Up @@ -1081,7 +1097,7 @@ public function merge_title_protection( &$title, $args = null ) {
*/
// phpcs:ignore -- WordPress doesn't have a comment, either.
$protected_title_format = (string) \apply_filters( 'protected_title_format', \__( 'Protected: %s', 'default' ), $post );
$title = sprintf( $protected_title_format, $title );
$title = sprintf( $protected_title_format, $title );
} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
/**
* Filters the text prepended to the post title of private posts.
Expand All @@ -1096,7 +1112,7 @@ public function merge_title_protection( &$title, $args = null ) {
*/
// phpcs:ignore -- WordPress doesn't have a comment, either.
$private_title_format = (string) \apply_filters( 'private_title_format', \__( 'Private: %s', 'default' ), $post );
$title = sprintf( $private_title_format, $title );
$title = sprintf( $private_title_format, $title );
}
}

Expand Down

0 comments on commit db7266c

Please sign in to comment.