Exemplo n.º 1
0
/**
 * Deletes user's custom avatar image.
 *
 * @uses get_user_meta() For retrieving user meta fields.
 * @uses do_action() For calling the functions added to an action hook.
 * @uses avatar_manager_delete_avatar() For deleting an avatar image based on
 * user ID.
 *
 * @since Avatar Manager 1.3.0
 *
 * @param array $args An associative array with username and passowrd.
 * @return bool Operation status.
 */
function avatar_manager_deleteCustomAvatar($args)
{
    global $wp_xmlrpc_server;
    if (count($args) < 2) {
        return new IXR_Error(400, __('Insufficient arguments passed to this XML-RPC method.', 'avatar-manager'));
    }
    // Sanitizes the string or array of strings from user input.
    $wp_xmlrpc_server->escape($args);
    $username = $args[0];
    $password = $args[1];
    if (!($user = $wp_xmlrpc_server->login($username, $password))) {
        return $wp_xmlrpc_server->error;
    }
    // Retrieves user meta field based on user ID.
    $attachment_id = get_user_meta($user->ID, 'avatar_manager_custom_avatar', true);
    // Returns if no attachment ID was retrieved.
    if (empty($attachment_id)) {
        return new IXR_Error(404, __('Sorry, you don\'t have a custom avatar.', 'avatar-manager'));
    }
    // Calls the functions added to xmlrpc_call action hook.
    do_action('xmlrpc_call', 'avatarManager.deleteCustomAvatar');
    // Deletes an avatar image based on user ID.
    return avatar_manager_delete_avatar($user->ID);
}
Exemplo n.º 2
0
<?php

/**
 * @package Avatar_Manager
 * @subpackage Uninstaller
 */
// Exits if uninstall is not called from WordPress.
if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}
if (!function_exists('avatar_manager_delete_avatar')) {
    include_once 'avatar-manager.php';
}
// Deletes plugin options.
delete_option('avatar_manager');
// An associative array with criteria to match.
$args = array('meta_key' => 'avatar_manager_custom_avatar');
// Retrieves an array of users matching the criteria given in $args.
$users = get_users($args);
foreach ($users as $user) {
    // Deletes an avatar image based on user ID.
    avatar_manager_delete_avatar($user->ID);
}