本文整理汇总了PHP中get_user_meta函数的典型用法代码示例。如果您正苦于以下问题:PHP get_user_meta函数的具体用法?PHP get_user_meta怎么用?PHP get_user_meta使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_meta函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_user
public function load_user()
{
if ($this->id > 0) {
$current_user = get_user_by('ID', $this->id);
} elseif (function_exists('is_user_logged_in') && is_user_logged_in()) {
$current_user = wp_get_current_user();
}
if (isset($current_user) && $current_user) {
$this->id = $current_user->ID;
$this->first_name = $current_user->user_firstname;
$this->last_name = $current_user->user_lastname;
$this->email = $current_user->user_email;
$this->address = get_user_meta($current_user->ID, 'address', TRUE);
$this->is_on_mailing_list = get_user_meta($current_user->ID, 'mailing_list', TRUE);
$this->is_on_mailing_list = $this->is_on_mailing_list == 1 ? TRUE : FALSE;
$neighborhood_id = get_user_meta($current_user->ID, 'neighborhood_id', TRUE);
if (!empty($neighborhood_id) && $neighborhood_id > 0) {
$args = array('post_type' => 'wbb_neighborhood', 'post_status' => 'publish');
$query = new \WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
if (get_the_ID() == $neighborhood_id) {
$this->neighborhood = new Neighborhood();
$this->neighborhood->post_id = get_the_ID();
$this->neighborhood->title = get_the_title();
break;
}
}
}
$this->get_locations();
}
}
示例2: is_notification_dismissed
/**
* Check if the user has dismissed a notification
*
* @param Yoast_Notification $notification The notification to check for dismissal.
* @param null|int $user_id User ID to check on.
*
* @return bool
*/
public static function is_notification_dismissed(Yoast_Notification $notification, $user_id = null)
{
$user_id = !is_null($user_id) ? $user_id : get_current_user_id();
$dismissal_key = $notification->get_dismissal_key();
$current_value = get_user_meta($user_id, $dismissal_key, $single = true);
return !empty($current_value);
}
示例3: test_update_metadata_by_mid
function test_update_metadata_by_mid()
{
// Setup
$meta = get_metadata_by_mid('user', $this->meta_id);
// Update the meta value
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'meta_new_value'));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals('meta_new_value', $meta->meta_value);
// Update the meta value
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'meta_new_value', 'meta_new_key'));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals('meta_new_key', $meta->meta_key);
// Update the key and value
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'meta_value', 'meta_key'));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals('meta_key', $meta->meta_key);
$this->assertEquals('meta_value', $meta->meta_value);
// Update the value that has to be serialized
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, array('first', 'second')));
$meta = get_metadata_by_mid('user', $this->meta_id);
$this->assertEquals(array('first', 'second'), $meta->meta_value);
// Let's try some invalid meta data
$this->assertFalse(update_metadata_by_mid('user', 0, 'meta_value'));
$this->assertFalse(update_metadata_by_mid('user', $this->meta_id, 'meta_value', array('invalid', 'key')));
// Let's see if caches get cleared after updates.
$meta = get_metadata_by_mid('user', $this->meta_id);
$first = get_user_meta($meta->user_id, $meta->meta_key);
$this->assertTrue(update_metadata_by_mid('user', $this->meta_id, 'other_meta_value'));
$second = get_user_meta($meta->user_id, $meta->meta_key);
$this->assertFalse($first === $second);
}
示例4: process
/**
* Process the request
* @todo Setting for reassigning user's posts
*/
public function process()
{
// Verify the security nonce and die if it fails
if (!isset($_POST['wp_delete_user_accounts_nonce']) || !wp_verify_nonce($_POST['wp_delete_user_accounts_nonce'], 'wp_delete_user_accounts_nonce')) {
wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Request failed security check.', 'wp-delete-user-accounts')));
}
// Don't permit admins to delete their own accounts
if (current_user_can('manage_options')) {
wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Administrators cannot delete their own accounts.', 'wp-delete-user-accounts')));
}
// Get the current user
$user_id = get_current_user_id();
// Get user meta
$meta = get_user_meta($user_id);
// Delete user's meta
foreach ($meta as $key => $val) {
delete_user_meta($user_id, $key);
}
// Destroy user's session
wp_logout();
// Delete the user's account
$deleted = wp_delete_user($user_id);
if ($deleted) {
// Send success message
wp_send_json(array('status' => 'success', 'title' => __('Success!', 'wp-delete-user-accounts'), 'message' => __('Your account was successfully deleted. Fair well.', 'wp-delete-user-accounts')));
} else {
wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Request failed.', 'wp-delete-user-accounts')));
}
}
示例5: ti_profile_fields
function ti_profile_fields($user)
{
$is_approved = get_user_meta($user->ID, 'ti_is_approved', true);
?>
<h3>Approve User to view products</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Approve as patient</label></th>
<td>
<select name="ti_is_approved">
<option value="">No</option>
<option <?php
echo $is_approved == 1 ? 'selected' : '';
?>
value="1">Yes</option>
</select>
</td>
</tr>
</table>
<?php
}
示例6: __construct
/**
* Class constructor
*
* Sets definitions
* Adds methods to appropriate hooks
*
* @author Ronald Huereca <ronalfy@gmail.com>
* @since 1.0.0
* @access public
* @param array $args If not set, then uses $defaults instead
*/
public function __construct($args)
{
// Get posts per page
$user_id = get_current_user_id();
$posts_per_page = get_user_meta($user_id, 'reorder_items_per_page', true);
if (!is_numeric($posts_per_page)) {
$posts_per_page = 50;
}
$offset = absint($posts_per_page - 2);
// Parse arguments
$defaults = array('post_type' => '', 'posts_per_page' => $posts_per_page, 'offset' => $offset);
$args = wp_parse_args($args, $defaults);
// Set variables
$this->post_type = $args['post_type'];
//Get offset and posts_per_page
$this->posts_per_page = absint($args['posts_per_page']);
//todo - filterable?
$this->offset = absint($args['offset']);
//todo - filterable?
if ($this->offset > $this->posts_per_page) {
$this->offset = $this->posts_per_page;
}
//Add-on actions/filters
add_action('metronet_reorder_menu_url_' . $this->post_type, array($this, 'set_reorder_url'));
add_action('reorder_by_terms_interface_' . $this->post_type, array($this, 'output_interface'));
add_action('metronet_reorder_posts_add_menu_' . $this->post_type, array($this, 'script_init'));
add_filter('metronet_reorder_posts_tabs_' . $this->post_type, array($this, 'add_tab'));
//Ajax actions
add_action('wp_ajax_reorder_terms_only_sort', array($this, 'ajax_term_sort'));
}
示例7: rcl_ajax_delete_post
function rcl_ajax_delete_post()
{
global $user_ID;
if (!$user_ID) {
return false;
}
$post = get_post(intval($_POST['post_id']));
$res = wp_delete_post($post->ID);
if ($res) {
$temp_gal = get_user_meta($user_ID, 'tempgallery', 1);
if ($temp_gal) {
$cnt = count($temp_gal);
foreach ((array) $temp_gal as $key => $gal) {
if ($gal['ID'] == $_POST['post_id']) {
unset($temp_gal[$key]);
}
}
foreach ((array) $temp_gal as $t) {
$new_temp[] = $t;
}
if ($new_temp) {
update_user_meta($user_ID, 'tempgallery', $new_temp);
} else {
delete_user_meta($user_ID, 'tempgallery');
}
}
$log['result'] = 100;
$log['post_type'] = $post->post_type;
} else {
$log['result'] = 1;
}
echo json_encode($log);
exit;
}
示例8: WeddingGuest
function WeddingGuest($id = null)
{
parent::__construct($id);
$this->attending_wedding = (bool) get_user_meta($this->ID, '_attending_wedding', true);
$this->attending_dinner = (bool) get_user_meta($this->ID, '_attending_dinner', true);
$this->has_responded = (bool) ($this->_attending_wedding == '1' || $this->_attending_wedding == '0' || $this->_attending_dinner == '1' || $this->_attending_dinner == '0');
}
示例9: book_confirmed_responsable_template
function book_confirmed_responsable_template($user, $event, $email)
{
$event_start_date = new DateTime(get_post_meta($event->ID, '_EventStartDate', true));
$date = date_i18n("l d F Y", $event_start_date->getTimestamp());
$user_meta = get_user_meta($user->ID);
$full_name = $user_meta["first_name"][0] . " " . $user_meta["last_name"][0];
ob_start();
?>
<p>
Bonjour, merci d’avoir validé la participation au stage « Communication en situation d’urgence médiatique | Communication de crise » du <strong><?php
echo $date;
?>
</strong> de M/Mme <?php
echo $full_name;
?>
.
</p>
<p>
<?php
echo es_mail_sign();
?>
</p>
<?php
$mail = ob_get_contents();
ob_clean();
return $mail;
}
示例10: init
public function init(&$existing_meta_keys = array())
{
if (!self::$is_active) {
return;
}
if (!empty(XmlExportEngine::$exportQuery->results)) {
foreach (XmlExportEngine::$exportQuery->results as $user) {
$record_meta = get_user_meta($user->ID, '');
if (!empty($record_meta)) {
foreach ($record_meta as $record_meta_key => $record_meta_value) {
if (!in_array($record_meta_key, $existing_meta_keys)) {
$to_add = true;
foreach ($this->default_fields as $default_value) {
if ($record_meta_key == $default_value['name'] || $record_meta_key == $default_value['type']) {
$to_add = false;
break;
}
}
if ($to_add) {
foreach ($this->advanced_fields as $advanced_value) {
if ($record_meta_key == $advanced_value['name'] || $record_meta_key == $advanced_value['type']) {
$to_add = false;
break;
}
}
}
if ($to_add) {
$existing_meta_keys[] = $record_meta_key;
}
}
}
}
}
}
}
示例11: getSocialUsername
/**
* Get a username value stored for the given WordPress user identifier
*
* @since 1.3.0
*
* @param int|string $user_id WordPress user identifier. may be WP_User->ID or a separate identifier used by an extending system
* @param string $key user attribute or meta key storing the username of interest
*
* @return string stored username. empty string if no user_id provided or no username found
*/
public static function getSocialUsername($user_id, $key)
{
// basic test for invalid passed parameter
if (!$user_id) {
return '';
}
if (!is_string($key) || !$key) {
return '';
}
if (function_exists('get_user_attribute')) {
$username = get_user_attribute($user_id, $key);
} else {
$username = get_user_meta($user_id, $key, true);
}
if (!is_string($username)) {
$username = '';
}
// pass a username through a filter if not explicitly defined through user meta
if (!$username) {
/**
* Allow sites to provide a WordPress user's Twitter username through a filter
*
* @since 1.0.0
*
* @param string $username Twitter username associated with a WordPress user ID
* @param int|string $user_id WordPress user identifier. may be WP_User->ID or a separate identifier used by an extending system
*/
$username = apply_filters($key . '_username', $username, $user_id);
}
return $username;
}
示例12: notice
/**
* Output the message
*
* @since 0.1.0
*
* @param string $message The text of the message.
* @param bool $error Optional. Whether to show as error or update. Default is error.
* @param string $cap_check Optional. Minimum user capability to show nag to. Default is "activate_plugins"
* @param string|bool $ignore_key Optional. The user meta key to use for storing if this message has been dismissed by current user or not. If false, it will be generated.
*
* @return string|void Admin notice if is_admin() and not dismissed.
*/
public static function notice($message, $error = true, $cap_check = 'activate_plugins', $ignore_key = false)
{
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
if (current_user_can($cap_check)) {
$user_id = get_current_user_id();
if (!is_string($ignore_key)) {
// cal_wd_ig_3911b2583433f696e5813a503bbb2e65
$ignore_key = 'cal_wd_ig_' . substr(md5($ignore_key), 0, 40);
}
self::$ignore_key = sanitize_key($ignore_key);
$dissmised = get_user_meta($user_id, self::$ignore_key, true);
if (!$dissmised) {
if ($error) {
$class = 'error';
} else {
$class = 'updated';
}
self::$nonce_field = wp_nonce_field(self::$nonce_action);
$out[] = sprintf('<div id="%1s" data-key="%2s" class="%3s notice is-dismissible"><p>', self::$ignore_key, self::$ignore_key, $class);
$out[] = $message;
$out[] = self::$nonce_field;
$out[] = '</p></div>';
add_action('admin_enqueue_scripts', array(__CLASS__, 'js_css'));
add_action('wp_ajax_caldera_warnings_dismissible_notice', array(__CLASS__, 'ajax_cb'));
return implode('', $out);
}
}
}
}
示例13: memberful_private_rss_feed_link
/**
* @param string $success_message - '', if present, will return an clickable link
* @param string $error_message - "You don’t have access to this RSS feed."
* @param bool $return
* @return string
*/
function memberful_private_rss_feed_link($success_message = '', $error_message = "You don’t have access to this RSS feed.", $return = false)
{
$error_message = apply_filters('memberful_private_rss_feed_error_message', $error_message);
if (!is_user_logged_in()) {
return memberful_private_rss_feed_link_response_helper($error_message, $return);
}
$requiredPlan = memberful_private_user_feed_settings_get_required_plan();
// We want to allow the private user feed only if the admin has configured it.
if ($requiredPlan == false) {
return memberful_private_rss_feed_link_response_helper($error_message, $return);
}
$current_user_id = get_current_user_id();
if (!is_subscribed_to_memberful_plan($requiredPlan, $current_user_id)) {
return memberful_private_rss_feed_link_response_helper($error_message, $return);
}
$feedToken = get_user_meta($current_user_id, 'memberful_private_user_feed_token', true);
if ($feedToken == false || $feedToken == '') {
$feedToken = substr(md5(uniqid(rand(1, 10000))), 2, 30);
update_user_meta($current_user_id, 'memberful_private_user_feed_token', $feedToken);
}
$link = get_home_url() . '/' . memberful_private_user_feed_get_url_identifier($feedToken);
if ($success_message != '') {
$link = '<a href="' . $link . '">' . do_shortcode($success_message) . '</a>';
}
return memberful_private_rss_feed_link_response_helper($link, $return);
}
示例14: userFistLastName
function userFistLastName($user_id){
$firstname=get_user_meta($user_id, 'first_name', true);
if($firstname == ""){
update_user_meta($user_id, 'first_name', 'Jhony');
update_user_meta($user_id, 'last_name', 'Waker');
}
}
示例15: enqueue_scripts
public static function enqueue_scripts($hook_suffix)
{
self::$pointers = apply_filters('hackrepair_plugin_archiver_pointers', self::$pointers);
// Check if screen related pointer is registered
if (empty(self::$pointers[$hook_suffix])) {
return;
}
$pointers = (array) self::$pointers[$hook_suffix];
// Get dismissed pointers
$dismissed = explode(',', (string) get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true));
$got_pointers = false;
foreach ($pointers as $key => $pointer) {
if (in_array($key, $dismissed)) {
continue;
}
if (isset($pointer['caps'])) {
foreach ($pointer['caps'] as $cap) {
if (!current_user_can($cap)) {
continue 2;
}
}
}
$callback = is_callable($pointer['callback']) ? $pointer['callback'] : array('HackRepair_Plugin_Archiver_Pointer', $pointer['callback']);
add_action('admin_print_footer_scripts', $callback);
$got_pointers = true;
}
if (!$got_pointers) {
return;
}
// Add pointers script and style to queue
wp_enqueue_style('wp-pointer');
wp_enqueue_script('wp-pointer');
}