Jetpack_Options::update_option PHP 메소드

update_option() 공개 정적인 메소드

Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate.
public static update_option ( string $name, mixed $value, string $autoload = null ) : boolean
$name string Option name
$value mixed Option value
$autoload string If not compact option, allows specifying whether to autoload or not.
리턴 boolean Was the option successfully updated?
    public static function update_option($name, $value, $autoload = null)
    {
        /**
         * Fires before Jetpack updates a specific option.
         *
         * @since 3.0.0
         *
         * @param str $name The name of the option being updated.
         * @param mixed $value The new value of the option.
         */
        do_action('pre_update_jetpack_option_' . $name, $name, $value);
        if (self::is_valid($name, 'non_compact')) {
            return update_option("jetpack_{$name}", $value, $autoload);
        }
        foreach (array_keys(self::$grouped_options) as $group) {
            if (self::is_valid($name, $group)) {
                return self::update_grouped_option($group, $name, $value);
            }
        }
        trigger_error(sprintf('Invalid Jetpack option name: %s', $name), E_USER_WARNING);
        return false;
    }

Usage Example

 /**
  * Synchronize connected user role changes
  */
 static function user_role_change($user_id)
 {
     if (Jetpack::is_active() && Jetpack::is_user_connected($user_id)) {
         $current_user_id = get_current_user_id();
         wp_set_current_user($user_id);
         $role = Jetpack::translate_current_user_to_role();
         $signed_role = Jetpack::sign_role($role);
         wp_set_current_user($current_user_id);
         $master_token = Jetpack_Data::get_access_token(JETPACK_MASTER_USER);
         $master_user_id = absint($master_token->external_user_id);
         if (!$master_user_id) {
             return;
         }
         // this shouldn't happen
         Jetpack::xmlrpc_async_call('jetpack.updateRole', $user_id, $signed_role);
         //@todo retry on failure
         //try to choose a new master if we're demoting the current one
         if ($user_id == $master_user_id && 'administrator' != $role) {
             $query = new WP_User_Query(array('fields' => array('id'), 'role' => 'administrator', 'orderby' => 'id', 'exclude' => array($master_user_id)));
             $new_master = false;
             foreach ($query->results as $result) {
                 $uid = absint($result->id);
                 if ($uid && Jetpack::is_user_connected($uid)) {
                     $new_master = $uid;
                     break;
                 }
             }
             if ($new_master) {
                 Jetpack_Options::update_option('master_user', $new_master);
             }
             // else disconnect..?
         }
     }
 }
All Usage Examples Of Jetpack_Options::update_option