case 'attachment': if ( ! $this->isInvalidAttachment( $post ) ) { $remainingPosts[] = $post; } break; default: $remainingPosts[] = $post; break; } } return $remainingPosts; } /** * Excludes attachments if their post parent isn't published or parent post type isn't registered anymore. * * @since 4.0.0 * * @param Object $post The post. * @return boolean Whether the attachment is invalid. */ private function isInvalidAttachment( $post ) { if ( empty( $post->post_parent ) ) { return false; } $parent = get_post( $post->post_parent ); if ( ! is_object( $parent ) ) { return false; } if ( 'publish' !== $parent->post_status || ! in_array( $parent->post_type, get_post_types(), true ) || $parent->post_password ) { return true; } return false; } /** * Returns all eligble sitemap entries for a given taxonomy. * * @since 4.0.0 * * @param string $taxonomy The taxonomy. * @param array $additionalArgs Any additional arguments for the term query. * @return array|int The term objects or the term count. */ public function terms( $taxonomy, $additionalArgs = [] ) { // Set defaults. $fields = 't.term_id'; $offset = aioseo()->sitemap->offset; // Override defaults if passed as additional arg. foreach ( $additionalArgs as $name => $value ) { $$name = esc_sql( $value ); if ( 'root' === $name && $value ) { $fields = 't.term_id'; } if ( 'count' === $name && $value ) { $fields = 'count(t.term_id) as total'; } } $termRelationshipsTable = aioseo()->core->db->db->prefix . 'term_relationships'; $termTaxonomyTable = aioseo()->core->db->db->prefix . 'term_taxonomy'; $query = aioseo()->core->db ->start( aioseo()->core->db->db->terms . ' as t', true ) ->select( $fields ) ->whereRaw( " ( `t`.`term_id` IN ( SELECT `tt`.`term_id` FROM `$termTaxonomyTable` as tt WHERE `tt`.`taxonomy` = '$taxonomy' AND `tt`.`count` > 0 ) )" ); $excludedTerms = aioseo()->sitemap->helpers->excludedTerms(); if ( $excludedTerms ) { $query->whereRaw(" ( `t`.`term_id` NOT IN ( SELECT `tr`.`term_taxonomy_id` FROM `$termRelationshipsTable` as tr WHERE `tr`.`term_taxonomy_id` IN ( $excludedTerms ) ) )" ); } if ( aioseo()->sitemap->indexes && empty( $additionalArgs['root'] ) && ( empty( $additionalArgs['count'] ) || ! $additionalArgs['count'] ) ) { $query->limit( aioseo()->sitemap->linksPerIndex, $offset ); } // Return the total if we are just counting the terms. if ( ! empty( $additionalArgs['count'] ) && $additionalArgs['count'] ) { return (int) $query->run( true, 'var' ) ->result(); } $terms = $query->orderBy( '`t`.`term_id` ASC' ) ->run() ->result(); foreach ( $terms as $term ) { // Convert ID from string to int. $term->term_id = (int) $term->term_id; // Add taxonomy name to object manually instead of querying it to prevent redundant join. $term->taxonomy = $taxonomy; } return $terms; } /** * Wipes all data and forces the plugin to rescan the site for images. * * @since 4.0.13 * * @return void */ public function resetImages() { aioseo()->core->db ->update( 'aioseo_posts' ) ->set( [ 'images' => null, 'image_scan_date' => null ] ) ->run(); } }