ith an associated meta table. * @param string $meta_key Metadata key. * @param string $object_subtype Optional. The subtype of the object type. Default empty string. * @return bool True if successful. False if the meta key was not registered. */ function unregister_meta_key( $object_type, $meta_key, $object_subtype = '' ) { global $wp_meta_keys; if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { return false; } $args = $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ]; if ( isset( $args['sanitize_callback'] ) && is_callable( $args['sanitize_callback'] ) ) { if ( ! empty( $object_subtype ) ) { remove_filter( "sanitize_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['sanitize_callback'] ); } else { remove_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'] ); } } if ( isset( $args['auth_callback'] ) && is_callable( $args['auth_callback'] ) ) { if ( ! empty( $object_subtype ) ) { remove_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'] ); } else { remove_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'] ); } } unset( $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] ); // Do some clean up. if ( empty( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) { unset( $wp_meta_keys[ $object_type ][ $object_subtype ] ); } if ( empty( $wp_meta_keys[ $object_type ] ) ) { unset( $wp_meta_keys[ $object_type ] ); } return true; } /** * Retrieves a list of registered metadata args for an object type, keyed by their meta keys. * * @since 4.6.0 * @since 4.9.8 The `$object_subtype` parameter was added. * * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', * or any other object type with an associated meta table. * @param string $object_subtype Optional. The subtype of the object type. Default empty string. * @return array[] List of registered metadata args, keyed by their meta keys. */ function get_registered_meta_keys( $object_type, $object_subtype = '' ) { global $wp_meta_keys; if ( ! is_array( $wp_meta_keys ) || ! isset( $wp_meta_keys[ $object_type ] ) || ! isset( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) { return array(); } return $wp_meta_keys[ $object_type ][ $object_subtype ]; } /** * Retrieves registered metadata for a specified object. * * The results include both meta that is registered specifically for the * object's subtype and meta that is registered for the entire object type. * * @since 4.6.0 * * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', * or any other object type with an associated meta table. * @param int $object_id ID of the object the metadata is for. * @param string $meta_key Optional. Registered metadata key. If not specified, retrieve all registered * metadata for the specified object. * @return mixed A single value or array of values for a key if specified. An array of all registered keys * and values for an object ID if not. False if a given $meta_key is not registered. */ function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) { $object_subtype = get_object_subtype( $object_type, $object_id ); if ( ! empty( $meta_key ) ) { if ( ! empty( $object_subtype ) && ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { $object_subtype = ''; } if ( ! registered_meta_key_exists( $object_type, $meta_key, $object_subtype ) ) { return false; } $meta_keys = get_registered_meta_keys( $object_type, $object_subtype ); $meta_key_data = $meta_keys[ $meta_key ]; $data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data['single'] ); return $data; } $data = get_metadata( $object_type, $object_id ); if ( ! $data ) { return array(); } $meta_keys = get_registered_meta_keys( $object_type ); if ( ! empty( $object_subtype ) ) { $meta_keys = array_merge( $meta_keys, get_registered_meta_keys( $object_type, $object_subtype ) ); } return array_intersect_key( $data, $meta_keys ); } /** * Filters out `register_meta()` args based on an allowed list. * * `register_meta()` args may change over time, so requiring the allowed list * to be explicitly turned off is a warranty seal of sorts. * * @access private * @since 5.5.0 * * @param array $args Arguments from `register_meta()`. * @param array $default_args Default arguments for `register_meta()`. * @return array Filtered arguments. */ function _wp_register_meta_args_allowed_list( $args, $default_args ) { return array_intersect_key( $args, $default_args ); } /** * Returns the object subtype for a given object ID of a specific type. * * @since 4.9.8 * * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', * or any other object type with an associated meta table. * @param int $object_id ID of the object to retrieve its subtype. * @return string The object subtype or an empty string if unspecified subtype. */ function get_object_subtype( $object_type, $object_id ) { $object_id = (int) $object_id; $object_subtype = ''; switch ( $object_type ) { case 'post': $post_type = get_post_type( $object_id ); if ( ! empty( $post_type ) ) { $object_subtype = $post_type; } break; case 'term': $term = get_term( $object_id ); if ( ! $term instanceof WP_Term ) { break; } $object_subtype = $term->taxonomy; break; case 'comment': $comment = get_comment( $object_id ); if ( ! $comment ) { break; } $object_subtype = 'comment'; break; case 'user': $user = get_user_by( 'id', $object_id ); if ( ! $user ) { break; } $object_subtype = 'user'; break; } /** * Filters the object subtype identifier for a non-standard object type. * * The dynamic portion of the hook name, `$object_type`, refers to the meta object type * (post, comment, term, user, or any other type with an associated meta table). * * Possible hook names include: * * - `get_object_subtype_post` * - `get_object_subtype_comment` * - `get_object_subtype_term` * - `get_object_subtype_user` * * @since 4.9.8 * * @param string $object_subtype Empty string to override. * @param int $object_id ID of the object to get the subtype for. */ return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id ); } ress Core from outputting a robots tag in disableWpRobotsCore(), we need to noindex/nofollow non-public sites ourselves. if ( ! get_option( 'blog_public' ) ) { $this->attributes['noindex'] = 'noindex'; $this->attributes['nofollow'] = 'nofollow'; } $this->attributes = array_filter( (array) apply_filters( 'aioseo_robots_meta', $this->attributes ) ); return $array ? $this->attributes : implode( ', ', $this->attributes ); } /** * Sets the attributes for the current post. * * @since 4.0.0 * * @param \WP_Post|null $post The post object. * @return void */ public function post( $post = null ) { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $post = aioseo()->helpers->getPost( $post ); $metaData = aioseo()->meta->metaData->getMetaData( $post ); if ( ! empty( $metaData ) && ! $metaData->robots_default ) { $this->metaValues( $metaData ); return; } if ( $dynamicOptions->searchAppearance->postTypes->has( $post->post_type ) ) { $this->globalValues( [ 'postTypes', $post->post_type ], true ); } } /** * Returns the robots meta tag value for the current term. * * @since 4.0.6 * * @param \WP_Term|null $term The term object if any. * @return void */ public function term( $term = null ) { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $term = is_a( $term, 'WP_Term' ) ? $term : get_queried_object(); if ( $dynamicOptions->searchAppearance->taxonomies->has( $term->taxonomy ) ) { $this->globalValues( [ 'taxonomies', $term->taxonomy ], true ); return; } $this->globalValues(); } /** * Sets the attributes for the current archive. * * @since 4.0.0 * * @return void */ private function archives() { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $postType = get_queried_object(); if ( ! empty( $postType->name ) && $dynamicOptions->searchAppearance->archives->has( $postType->name ) ) { $this->globalValues( [ 'archives', $postType->name ], true ); } } /** * Sets the attributes based on the global values. * * @since 4.0.0 * * @param array $optionOrder The order in which the options need to be called to get the relevant robots meta settings. * @param boolean $isDynamicOption Whether this is for a dynamic option. * @return void */ protected function globalValues( $optionOrder = [], $isDynamicOption = false ) { $robotsMeta = []; if ( count( $optionOrder ) ) { $options = $isDynamicOption ? aioseo()->dynamicOptions->noConflict( true )->searchAppearance : aioseo()->options->noConflict()->searchAppearance; foreach ( $optionOrder as $option ) { if ( ! $options->has( $option, false ) ) { return; } $options = $options->$option; } $clonedOptions = clone $options; if ( ! $clonedOptions->show ) { $this->attributes['noindex'] = 'noindex'; } $robotsMeta = $options->advanced->robotsMeta->all(); if ( $robotsMeta['default'] ) { $robotsMeta = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->all(); } } else { $robotsMeta = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->all(); } $this->attributes['max-image-preview'] = 'max-image-preview:large'; if ( $robotsMeta['default'] ) { return; } if ( $robotsMeta['noindex'] ) { $this->attributes['noindex'] = 'noindex'; } if ( $robotsMeta['nofollow'] ) { $this->attributes['nofollow'] = 'nofollow'; } if ( $robotsMeta['noarchive'] ) { $this->attributes['noarchive'] = 'noarchive'; } $noSnippet = $robotsMeta['nosnippet']; if ( $noSnippet ) { $this->attributes['nosnippet'] = 'nosnippet'; } if ( $robotsMeta['noodp'] ) { $this->attributes['noodp'] = 'noodp'; } if ( $robotsMeta['notranslate'] ) { $this->attributes['notranslate'] = 'notranslate'; } $maxSnippet = $robotsMeta['maxSnippet']; if ( ! $noSnippet && $maxSnippet && intval( $maxSnippet ) ) { $this->attributes['max-snippet'] = "max-snippet:$maxSnippet"; } $maxImagePreview = $robotsMeta['maxImagePreview']; $noImageIndex = $robotsMeta['noimageindex']; if ( ! $noImageIndex && $maxImagePreview && in_array( $maxImagePreview, [ 'none', 'standard', 'large' ], true ) ) { $this->attributes['max-image-preview'] = "max-image-preview:$maxImagePreview"; } $maxVideoPreview = $robotsMeta['maxVideoPreview']; if ( isset( $maxVideoPreview ) && is_numeric( $maxVideoPreview ) ) { $this->attributes['max-video-preview'] = "max-video-preview:$maxVideoPreview"; } // Check this last so that we can prevent max-image-preview from being output if noimageindex is enabled. if ( $noImageIndex ) { $this->attributes['max-image-preview'] = ''; $this->attributes['noimageindex'] = 'noimageindex'; } } /** * Sets the attributes from the meta data. * * @since 4.0.0 * * @param \AIOSEO\Plugin\Common\Models\Post|\AIOSEO\Plugin\Pro\Models\Term $metaData The post/term meta data. * @return void */ protected function metaValues( $metaData ) { if ( $metaData->robots_noindex || $this->isPasswordProtected() ) { $this->attributes['noindex'] = 'noindex'; } if ( $metaData->robots_nofollow ) { $this->attributes['nofollow'] = 'nofollow'; } if ( $metaData->robots_noarchive ) { $this->attributes['noarchive'] = 'noarchive'; } if ( $metaData->robots_nosnippet ) { $this->attributes['nosnippet'] = 'nosnippet'; } if ( $metaData->robots_noodp ) { $this->attributes['noodp'] = 'noodp'; } if ( $metaData->robots_notranslate ) { $this->attributes['notranslate'] = 'notranslate'; } if ( ! $metaData->robots_nosnippet && $metaData->robots_max_snippet && intval( $metaData->robots_max_snippet ) ) { $this->attributes['max-snippet'] = "max-snippet:$metaData->robots_max_snippet"; } if ( ! $metaData->robots_noimageindex && $metaData->robots_max_imagepreview && in_array( $metaData->robots_max_imagepreview, [ 'none', 'standard', 'large' ], true ) ) { $this->attributes['max-image-preview'] = "max-image-preview:$metaData->robots_max_imagepreview"; } if ( isset( $metaData->robots_max_videopreview ) && is_numeric( $metaData->robots_max_videopreview ) ) { $this->attributes['max-video-preview'] = "max-video-preview:$metaData->robots_max_videopreview"; } // Check this last so that we can prevent max-image-preview from being output if noimageindex is enabled. if ( $metaData->robots_noimageindex ) { $this->attributes['max-image-preview'] = ''; $this->attributes['noimageindex'] = 'noimageindex'; } } /** * Checks whether the current post is password protected. * * @since 4.0.0 * * @return bool Whether the post is password protected. */ private function isPasswordProtected() { $post = aioseo()->helpers->getPost(); return is_object( $post ) && $post->post_password; } }