本文整理汇总了PHP中WPSEO_Meta::meta_fields方法的典型用法代码示例。如果您正苦于以下问题:PHP WPSEO_Meta::meta_fields方法的具体用法?PHP WPSEO_Meta::meta_fields怎么用?PHP WPSEO_Meta::meta_fields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPSEO_Meta
的用法示例。
在下文中一共展示了WPSEO_Meta::meta_fields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Register our actions and filters
*
* @static
* @return void
*/
public static function init()
{
$options = WPSEO_Options::get_all();
foreach (array('opengraph' => 'opengraph', 'twitter' => 'twitter', 'googleplus' => 'google-plus') as $option => $network) {
if (true === $options[$option]) {
foreach (array('title' => 'text', 'description' => 'textarea', 'image' => 'upload') as $box => $type) {
self::$meta_fields['social'][$network . '-' . $box] = array('type' => $type, 'title' => '', 'default_value' => '', 'description' => '');
}
}
}
/**
* Allow add-on plugins to register their meta fields for management by this class
* add_filter() calls must be made before plugins_loaded prio 14
*/
$extra_fields = apply_filters('add_extra_wpseo_meta_fields', array());
if (is_array($extra_fields)) {
self::$meta_fields = self::array_merge_recursive_distinct($extra_fields, self::$meta_fields);
}
$register = function_exists('register_meta');
foreach (self::$meta_fields as $subset => $field_group) {
foreach ($field_group as $key => $field_def) {
if ($field_def['type'] !== 'snippetpreview') {
/* register_meta() is undocumented and not used by WP internally, wrapped in
function_exists as a precaution in case they remove it. */
if ($register === true) {
register_meta('post', self::$meta_prefix . $key, array(__CLASS__, 'sanitize_post_meta'));
} else {
add_filter('sanitize_post_meta_' . self::$meta_prefix . $key, array(__CLASS__, 'sanitize_post_meta'), 10, 2);
}
// Set the $fields_index property for efficiency
self::$fields_index[self::$meta_prefix . $key] = array('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] = '';
}
}
}
}
add_filter('update_post_metadata', array(__CLASS__, 'remove_meta_if_default'), 10, 5);
add_filter('add_post_metadata', array(__CLASS__, 'dont_save_meta_if_default'), 10, 4);
}