本文整理汇总了PHP中WP_User::has_prop方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User::has_prop方法的具体用法?PHP WP_User::has_prop怎么用?PHP WP_User::has_prop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_User
的用法示例。
在下文中一共展示了WP_User::has_prop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: user_meta_shortcode_handler
/**
* User Meta Shortcode handler
* Retrieve the value of a property or meta key from the users and usermeta tables.
* usage: [user_meta user_id=1 key="first_name" size="50" wpautop="on" pre="Pre Label " post="Post Label "]
* @param array $atts
* @param string $content
* @return stirng
*/
function user_meta_shortcode_handler($atts, $content = null)
{
if (!isset($atts['user_id'])) {
$user = wp_get_current_user();
$atts['user_id'] = $user->ID;
}
if (!isset($atts['size'])) {
$atts['size'] = '50';
}
$user = new WP_User($atts['user_id']);
if (!$user->exists()) {
return;
}
if ($atts['key'] == 'avatar') {
return $atts['pre'] . get_avatar($user->ID, $atts['size']) . $atts['post'];
}
if ($user->has_prop($atts['key'])) {
if ($atts['wpautop'] == 'on') {
$value = wpautop($user->get($atts['key']));
} else {
$value = $user->get($atts['key']);
}
}
if (!empty($value)) {
return $atts['pre'] . $value . $atts['post'];
}
return;
}
示例2:
function test_has_prop()
{
$user_id = self::factory()->user->create(array('role' => 'author', 'user_login' => 'test_wp_user_has_prop', 'user_pass' => 'password', 'user_email' => 'test2@test.com'));
$user = new WP_User($user_id);
$this->assertTrue($user->has_prop('user_email'));
$this->assertTrue($user->has_prop('use_ssl'));
$this->assertFalse($user->has_prop('field_that_does_not_exist'));
update_user_meta($user_id, 'dashed-key', 'abcdefg');
$this->assertTrue($user->has_prop('dashed-key'));
}
示例3: get_user_option
/**
* Retrieve user option that can be either per Site or per Network.
*
* If the user ID is not given, then the current user will be used instead. If
* the user ID is given, then the user data will be retrieved. The filter for
* the result, will also pass the original option name and finally the user data
* object as the third parameter.
*
* The option will first check for the per site name and then the per Network name.
*
* @since 2.0.0
* @uses $wpdb WordPress database object for queries.
* @uses apply_filters() Calls 'get_user_option_$option' hook with result,
* option parameter, and user data object.
*
* @param string $option User option name.
* @param int $user Optional. User ID.
* @param bool $deprecated Use get_option() to check for an option in the options table.
* @return mixed
*/
function get_user_option($option, $user = 0, $deprecated = '')
{
global $wpdb;
if (!empty($deprecated)) {
_deprecated_argument(__FUNCTION__, '3.0');
}
if (empty($user)) {
$user = wp_get_current_user();
} else {
$user = new WP_User($user);
}
if (!isset($user->ID)) {
return false;
}
if ($user->has_prop($wpdb->prefix . $option)) {
// Blog specific
$result = $user->get($wpdb->prefix . $option);
} elseif ($user->has_prop($option)) {
// User specific and cross-blog
$result = $user->get($option);
} else {
$result = false;
}
return apply_filters("get_user_option_{$option}", $result, $option, $user);
}
示例4: column_hidden
/**
* Hide the SEO Title, Meta Desc and Focus KW columns if the user hasn't chosen which columns to hide
*
* @param array|false $result
* @param string $option
* @param WP_User $user
*
* @return array|false $result
*/
public function column_hidden($result, $option, $user)
{
global $wpdb;
$prefix = $wpdb->get_blog_prefix();
if (!$user->has_prop($prefix . $option) && !$user->has_prop($option)) {
if (!is_array($result)) {
$result = array();
}
array_push($result, 'wpseo-title', 'wpseo-metadesc', 'wpseo-focuskw');
}
return $result;
}
示例5:
function test_has_prop()
{
$user = new WP_User(self::$author_id);
$this->assertTrue($user->has_prop('user_email'));
$this->assertTrue($user->has_prop('use_ssl'));
$this->assertFalse($user->has_prop('field_that_does_not_exist'));
update_user_meta(self::$author_id, 'dashed-key', 'abcdefg');
$this->assertTrue($user->has_prop('dashed-key'));
}