tion( $row ) { return (int) $row->element_id; }, $rows ); $hiddenObjectIds = array_merge( $hiddenObjectIds, $ids ); } } $hasFilter = has_filter( 'aioseo_sitemap_' . aioseo()->helpers->toSnakeCase( $option ) ); $advanced = aioseo()->options->sitemap->$type->advancedSettings->enable; $excluded = array_merge( $hiddenObjectIds, aioseo()->options->sitemap->{$type}->advancedSettings->{$option} ); if ( ! $advanced && empty( $excluded ) && ! $hasFilter ) { return ''; } $ids = []; foreach ( $excluded as $object ) { if ( is_numeric( $object ) ) { $ids[] = (int) $object; continue; } $object = json_decode( $object ); if ( is_int( $object->value ) ) { $ids[] = $object->value; } } if ( 'excludePosts' === $option ) { $ids = apply_filters( 'aioseo_sitemap_exclude_posts', $ids, $type ); } if ( 'excludeTerms' === $option ) { $ids = apply_filters( 'aioseo_sitemap_exclude_terms', $ids, $type ); } return count( $ids ) ? esc_sql( implode( ', ', $ids ) ) : ''; } /** * Returns the URLs of all active sitemaps. * * @since 4.0.0 * @version 4.6.2 Removed the prefix from the list of URLs. * * @return array $urls The sitemap URLs. */ public function getSitemapUrls() { static $urls = []; if ( $urls ) { return $urls; } $addonsUrls = array_filter( aioseo()->addons->doAddonFunction( 'helpers', 'getSitemapUrls' ) ); foreach ( $addonsUrls as $addonUrls ) { $urls = array_merge( $urls, $addonUrls ); } if ( aioseo()->options->sitemap->general->enable ) { $urls[] = $this->getUrl( 'general' ); } if ( aioseo()->options->sitemap->rss->enable ) { $urls[] = $this->getUrl( 'rss' ); } return $urls; } /** * Returns the URLs of all active sitemaps with the 'Sitemap: ' prefix. * * @since 4.6.2 * * @return array $urls The sitemap URLs. */ public function getSitemapUrlsPrefixed() { $urls = $this->getSitemapUrls(); foreach ( $urls as &$url ) { $url = 'Sitemap: ' . $url; } return $urls; } /** * Extracts existing sitemap URLs from the robots.txt file. * We need this in case users have existing sitemap directives added to their robots.txt file. * * @since 4.0.10 * @version 4.4.9 * * @return array The sitemap URLs. */ public function extractSitemapUrlsFromRobotsTxt() { // First, we need to remove our filter, so that it doesn't run unintentionally. remove_filter( 'robots_txt', [ aioseo()->robotsTxt, 'buildRules' ], 10000 ); $robotsTxt = apply_filters( 'robots_txt', '', true ); add_filter( 'robots_txt', [ aioseo()->robotsTxt, 'buildRules' ], 10000 ); if ( ! $robotsTxt ) { return []; } $lines = explode( "\n", $robotsTxt ); if ( ! is_array( $lines ) || ! count( $lines ) ) { return []; } return aioseo()->robotsTxt->extractSitemapUrls( $robotsTxt ); } /** * Returns the URL of the given sitemap type. * * @since 4.1.5 * * @param string $type The sitemap type. * @return string The sitemap URL. */ public function getUrl( $type ) { $url = home_url( 'sitemap.xml' ); if ( 'rss' === $type ) { $url = home_url( 'sitemap.rss' ); } if ( 'general' === $type ) { // Check if user has a custom filename from the V3 migration. $filename = $this->filename( 'general' ) ?: 'sitemap'; $url = home_url( $filename . '.xml' ); } $addon = aioseo()->addons->getLoadedAddon( $type ); if ( ! empty( $addon->helpers ) && method_exists( $addon->helpers, 'getUrl' ) ) { $url = $addon->helpers->getUrl(); } return $url; } /** * Returns if images should be excluded from the sitemap. * * @since 4.2.2 * * @return bool */ public function excludeImages() { $shouldExclude = aioseo()->options->sitemap->general->advancedSettings->enable && aioseo()->options->sitemap->general->advancedSettings->excludeImages; return apply_filters( 'aioseo_sitemap_exclude_images', $shouldExclude ); } /** * Returns the post types to check against for the author sitemap. * * @since 4.4.4 * * @return array The post types. */ public function getAuthorPostTypes() { // By default, WP only considers posts for author archives, but users can include additional post types. $postTypes = [ 'post' ]; return apply_filters( 'aioseo_sitemap_author_post_types', $postTypes ); } /** * Decode the Urls from Posts and Terms so they properly show in the Sitemap. * * @since 4.6.9 * * @param mixed $data The data to decode. * @return array $result The converted data with decoded URLs. */ public function decodeSitemapEntries( $data ) { $result = []; // Decode Url to properly show Unicode Characters. foreach ( $data as $item ) { if ( isset( $item['loc'] ) ) { $item['loc'] = aioseo()->helpers->decodeUrl( $item['loc'] ); } // This is for the RSS Sitemap. if ( isset( $item['guid'] ) ) { $item['guid'] = aioseo()->helpers->decodeUrl( $item['guid'] ); } $result[] = $item; } return $result; } }