WPSEO_Meta::init
Register our actions and filters.
Метод класса: WPSEO_Meta{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$result = WPSEO_Meta::init();
Код WPSEO_Meta::init() WPSEO Meta::init Yoast 28.0
public static function init() {
foreach ( self::$social_networks as $option => $network ) {
if ( WPSEO_Options::get( $option, false, [ 'wpseo_social' ] ) === true ) {
foreach ( self::$social_fields as $box => $type ) {
self::$meta_fields['social'][ $network . '-' . $box ] = [
'type' => $type,
'default_value' => '',
];
}
}
}
unset( $option, $network, $box, $type );
/**
* Allow add-on plugins to register their meta fields for management by this class.
* Calls to add_filter() must be made before plugins_loaded prio 14.
*/
$extra_fields = apply_filters( 'add_extra_wpseo_meta_fields', [] );
if ( is_array( $extra_fields ) ) {
self::$meta_fields = self::array_merge_recursive_distinct( $extra_fields, self::$meta_fields );
}
unset( $extra_fields );
foreach ( self::$meta_fields as $subset => $field_group ) {
foreach ( $field_group as $key => $field_def ) {
// Register for all post types: sanitise callback only, REST disabled.
register_meta(
'post',
self::$meta_prefix . $key,
[ 'sanitize_callback' => [ self::class, 'sanitize_post_meta' ] ],
);
// Re-register for the 'post' subtype with REST exposure and auth callback when show_in_rest is enabled.
if ( ! empty( $field_def['show_in_rest'] ) ) {
register_meta(
'post',
self::$meta_prefix . $key,
[
'show_in_rest' => true,
'single' => ( $field_def['single'] ?? false ),
'type' => 'string',
'object_subtype' => 'post',
'sanitize_callback' => [ self::class, 'sanitize_post_meta' ],
'auth_callback' => static function ( $allowed, $meta_key, $object_id ) {
return current_user_can( 'edit_post', $object_id );
},
],
);
}
// Set the $fields_index property for efficiency.
self::$fields_index[ self::$meta_prefix . $key ] = [
'subset' => $subset,
'key' => $key,
];
// Set the $defaults property for efficiency.
if ( isset( $field_def['default_value'] ) ) {
self::$defaults[ self::$meta_prefix . $key ] = $field_def['default_value'];
}
else {
// Meta will always be a string, so let's make the meta meta default also a string.
self::$defaults[ self::$meta_prefix . $key ] = '';
}
}
}
unset( $subset, $field_group, $key, $field_def );
// Strip meta fields that have show_in_rest enabled from REST responses for users
// without edit_post capability. register_meta's auth_callback only covers writes,
// so read access must be restricted separately via this filter.
// Register only for 'post' post type. Other post types don't expose these fields.
add_filter( 'rest_prepare_post', [ self::class, 'hide_meta_from_unauthorized_rest_response' ], 10, 2 );
self::filter_schema_article_types();
add_filter( 'update_post_metadata', [ self::class, 'remove_meta_if_default' ], 10, 5 );
add_filter( 'add_post_metadata', [ self::class, 'dont_save_meta_if_default' ], 10, 4 );
}