thoughtis / cata-co-authors-plus

Common functions, configuration and compatibility fixes for Co-Authors Plus when used in Cata child themes. Not a fork or replacement for CAP.
GNU General Public License v3.0
0 stars 0 forks source link

Skip images uploaded to Guest Author profiles in Jetpack Sitemaps #1

Closed douglas-johnson closed 3 years ago

douglas-johnson commented 3 years ago

We have experienced this issue on Thought Catalog and Creepy Catalog where Jetpack image sitemaps produce URLs like /?post_type=guest-author&p=000 which link to non-public pages. The issue is that the image was uploaded to a Guest Author profile.

Example from Creepy Catalog:

Screen Shot 2021-09-08 at 3 22 41 PM

We solved it like this on Thought Catalog, but we need to solution on multiple sites using CAP.

/**
 * Jetpack Sitemap Image Skip Avatars
 * 
 * @param bool $skip
 * @param stdClass|WP_Post $post
 * @return bool
 */
public static function jetpack_sitemap_image_skip_avatars( bool $skip, $post ) : bool {
  if ( ! is_object( $post ) || ! property_exists( $post, 'post_parent' ) ) {
      return $skip;
  }

  $parent_id = absint( $post->post_parent );

  if ( 0 === $parent_id ) {
      return $skip;
  }

  if ( 'guest-author' === get_post_type( $parent_id ) ) {
      return true;
  }

  return $skip;
}