name, 2 - Separator (raquo), 3 - Term name, 4: Taxonomy singular name. 'taxtitle' => __( '%1$s %2$s %3$s %4$s Feed', 'all-in-one-seo-pack' ), // Translators: 1 - Blog name, 2 - Separator (raquo), 3 - Author name. 'authortitle' => __( '%1$s %2$s Posts by %3$s Feed', 'all-in-one-seo-pack' ), // Translators: 1 - Blog name, 2 - Separator (raquo), 3 - Search query. 'searchtitle' => __( '%1$s %2$s Search Results for “%3$s” Feed', 'all-in-one-seo-pack' ), // Translators: 1 - Blog name, 2 - Separator (raquo), 3 - Post type name. 'posttypetitle' => __( '%1$s %2$s %3$s Feed', 'all-in-one-seo-pack' ), ]; $args = wp_parse_args( $args, $defaults ); $attributes = [ 'title' => null, 'href' => null ]; if ( aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->postComments && is_singular() ) { $attributes = $this->getPostCommentsAttributes( $args ); } $archives = aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->archives->included; $postType = $this->getTheQueriedPostType(); if ( ( aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->archives->all || in_array( $postType, $archives, true ) ) && is_post_type_archive() ) { $attributes = $this->getPostTypeArchivesAttributes( $args ); } // All taxonomies. $taxonomies = aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->taxonomies->included; $term = get_queried_object(); if ( $term && isset( $term->taxonomy ) && ( aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->taxonomies->all || in_array( $term->taxonomy, $taxonomies, true ) ) && ( is_category() || is_tag() || is_tax() ) ) { $attributes = $this->getTaxonomiesAttributes( $args, $term ); } if ( aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->authors && is_author() ) { $attributes = $this->getAuthorAttributes( $args ); } if ( aioseo()->options->searchAppearance->advanced->crawlCleanup->feeds->search && is_search() ) { $attributes = $this->getSearchAttributes( $args ); } if ( ! empty( $attributes['title'] ) && ! empty( $attributes['href'] ) ) { echo '' . "\n"; } } /** * Retrieve the attributes for post comments feed. * * @since 4.2.1 * * @param array $args An array of arguments. * @return array An array of attributes. */ private function getPostCommentsAttributes( $args ) { $id = 0; $post = get_post( $id ); $title = null; $href = null; if ( comments_open() || pings_open() || 0 < $post->comment_count ) { $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( [ 'echo' => false ] ) ); $href = get_post_comments_feed_link( $post->ID ); } return [ 'title' => $title, 'href' => $href ]; } /** * Retrieve the attributes for post type archives feed. * * @since 4.2.1 * * @param array $args An array of arguments. * @return array An array of attributes. */ private function getPostTypeArchivesAttributes( $args ) { $postTypeObject = get_post_type_object( $this->getQueriedPostType() ); $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $postTypeObject->labels->name ); $href = get_post_type_archive_feed_link( $postTypeObject->name ); return [ 'title' => $title, 'href' => $href ]; } /** * Retrieve the attributes for taxonomies feed. * * @since 4.2.1 * * @param array $args An array of arguments. * @param \WP_Term $term The term. * @return array An array of attributes. */ private function getTaxonomiesAttributes( $args, $term ) { $title = null; $href = null; if ( is_category() ) { $title = sprintf( $args['cattitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); $href = get_category_feed_link( $term->term_id ); } if ( is_tag() ) { $title = sprintf( $args['tagtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); $href = get_tag_feed_link( $term->term_id ); } if ( is_tax() ) { $tax = get_taxonomy( $term->taxonomy ); $title = sprintf( $args['taxtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name, $tax->labels->singular_name ); $href = get_term_feed_link( $term->term_id, $term->taxonomy ); } return [ 'title' => $title, 'href' => $href ]; } /** * Retrieve the attributes for the author feed. * * @since 4.2.1 * * @param array $args An array of arguments. * @return array An array of attributes. */ private function getAuthorAttributes( $args ) { $authorId = (int) get_query_var( 'author' ); $title = sprintf( $args['authortitle'], get_bloginfo( 'name' ), $args['separator'], get_the_author_meta( 'display_name', $authorId ) ); $href = get_author_feed_link( $authorId ); return [ 'title' => $title, 'href' => $href ]; } /** * Retrieve the attributes for the search feed. * * @since 4.2.1 * * @param array $args An array of arguments. * @return array An array of attributes. */ private function getSearchAttributes( $args ) { $title = sprintf( $args['searchtitle'], get_bloginfo( 'name' ), $args['separator'], get_search_query( false ) ); $href = get_search_feed_link(); return [ 'title' => $title, 'href' => $href ]; } /** * Get the currently queried post type. * * @since 4.2.1 * * @return string The currently queried post type. */ private function getQueriedPostType() { $postType = get_query_var( 'post_type' ); if ( is_array( $postType ) ) { $postType = reset( $postType ); } return $postType; } }