xmlrpc_async_call() public static method

Helper method for multicall XMLRPC.
public static xmlrpc_async_call ( )
コード例 #1
0
 /**
  * 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..?
         }
     }
 }
コード例 #2
0
 /**
  * Set up all the data and queue it for the outgoing XML-RPC request
  */
 function sync()
 {
     if (!$this->sync) {
         return false;
     }
     $sync_data = $this->get_common_sync_data();
     $wp_importing = defined('WP_IMPORTING') && WP_IMPORTING;
     foreach ($this->sync as $sync_operation_type => $sync_operations) {
         switch ($sync_operation_type) {
             case 'post':
                 if ($wp_importing) {
                     break;
                 }
                 $global_post = isset($GLOBALS['post']) ? $GLOBALS['post'] : null;
                 $GLOBALS['post'] = null;
                 foreach ($sync_operations as $post_id => $settings) {
                     $sync_data['post'][$post_id] = $this->get_post($post_id);
                     if (isset($this->post_transitions[$post_id])) {
                         $sync_data['post'][$post_id]['transitions'] = $this->post_transitions[$post_id];
                     } else {
                         $sync_data['post'][$post_id]['transitions'] = array(false, false);
                     }
                     $sync_data['post'][$post_id]['on_behalf_of'] = $settings['on_behalf_of'];
                 }
                 $GLOBALS['post'] = $global_post;
                 unset($global_post);
                 break;
             case 'comment':
                 if ($wp_importing) {
                     break;
                 }
                 $global_comment = isset($GLOBALS['comment']) ? $GLOBALS['comment'] : null;
                 unset($GLOBALS['comment']);
                 foreach ($sync_operations as $comment_id => $settings) {
                     $sync_data['comment'][$comment_id] = $this->get_comment($comment_id);
                     if (isset($this->comment_transitions[$comment_id])) {
                         $sync_data['comment'][$comment_id]['transitions'] = $this->comment_transitions[$comment_id];
                     } else {
                         $sync_data['comment'][$comment_id]['transitions'] = array(false, false);
                     }
                     $sync_data['comment'][$comment_id]['on_behalf_of'] = $settings['on_behalf_of'];
                 }
                 $GLOBALS['comment'] = $global_comment;
                 unset($global_comment);
                 break;
             case 'option':
                 foreach ($sync_operations as $option => $settings) {
                     $sync_data['option'][$option] = array('value' => get_option($option));
                 }
                 break;
             case 'delete_post':
             case 'delete_comment':
                 foreach ($sync_operations as $object_id => $settings) {
                     $sync_data[$sync_operation_type][$object_id] = array('on_behalf_of' => $settings['on_behalf_of']);
                 }
                 break;
             case 'delete_option':
                 foreach ($sync_operations as $object_id => $settings) {
                     $sync_data[$sync_operation_type][$object_id] = true;
                 }
                 break;
         }
     }
     Jetpack::xmlrpc_async_call('jetpack.syncContent', $sync_data);
 }
コード例 #3
0
 /**
  * Set up all the data and queue it for the outgoing XML-RPC request
  */
 function sync()
 {
     global $wpdb;
     $jetpack = Jetpack::init();
     $sync_data = array('firehose' => apply_filters('jetpack_firehose_toggle', false));
     if (count($this->sync)) {
         foreach ($this->sync as $obj => $data) {
             switch ($obj) {
                 case 'post':
                     $global_post = isset($GLOBALS['post']) ? $GLOBALS['post'] : null;
                     $GLOBALS['post'] = null;
                     foreach ($data as $post => $columns) {
                         $sync_data['post'][$post] = $jetpack->get_post($post, $columns);
                         if (isset($this->post_transitions[$post])) {
                             $sync_data['post'][$post]['transitions'] = $this->post_transitions[$post];
                         } else {
                             $sync_data['post'][$post]['transitions'] = array(false, false);
                         }
                     }
                     $GLOBALS['post'] = $global_post;
                     unset($global_post);
                     break;
                 case 'delete_post':
                     foreach ($data as $post => $true) {
                         $sync_data['delete_post'][$post] = true;
                     }
                     break;
                 case 'comment':
                     $global_comment = isset($GLOBALS['comment']) ? $GLOBALS['comment'] : null;
                     unset($GLOBALS['comment']);
                     foreach ($data as $comment => $columns) {
                         $sync_data['comment'][$comment] = $jetpack->get_comment($comment, $columns);
                     }
                     $GLOBALS['comment'] = $global_comment;
                     unset($global_comment);
                     break;
                 case 'delete_comment':
                     foreach ($data as $comment => $true) {
                         $sync_data['delete_comment'][$comment] = true;
                     }
                     break;
             }
         }
         Jetpack::xmlrpc_async_call('jetpack.syncContent', $sync_data);
     }
 }
コード例 #4
0
ファイル: stats.php プロジェクト: iamtakashi/jetpack
function stats_update_blog()
{
    Jetpack::xmlrpc_async_call('jetpack.updateBlog', stats_get_blog());
}
コード例 #5
0
 /**
  * Jetpack_Subscriptions::subscribe()
  *
  * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.
  *
  * @param string $email
  * @param array  $post_ids (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts
  * @param bool   $async    (optional) Should the subscription be performed asynchronously?  Defaults to true.
  *
  * @return true|Jetpack_Error true on success
  *	invalid_email   : not a valid email address
  *	invalid_post_id : not a valid post ID
  *	unknown_post_id : unknown post
  *	not_subscribed  : strange error.  Jetpack servers at WordPress.com could subscribe the email.
  *	disabled        : Site owner has disabled subscriptions.
  *	active          : Already subscribed.
  *	unknown         : strange error.  Jetpack servers at WordPress.com returned something malformed.
  *	unknown_status  : strange error.  Jetpack servers at WordPress.com returned something I didn't understand.
  */
 function subscribe($email, $post_ids = 0, $async = true, $extra_data = array())
 {
     if (!is_email($email)) {
         return new Jetpack_Error('invalid_email');
     }
     if (!$async) {
         Jetpack::load_xml_rpc_client();
         $xml = new Jetpack_IXR_ClientMulticall();
     }
     foreach ((array) $post_ids as $post_id) {
         $post_id = (int) $post_id;
         if ($post_id < 0) {
             return new Jetpack_Error('invalid_post_id');
         } else {
             if ($post_id && !($post = get_post($post_id))) {
                 return new Jetpack_Error('unknown_post_id');
             }
         }
         if ($async) {
             Jetpack::xmlrpc_async_call('jetpack.subscribeToSite', $email, $post_id, serialize($extra_data));
         } else {
             $xml->addCall('jetpack.subscribeToSite', $email, $post_id, serialize($extra_data));
         }
     }
     if ($async) {
         return;
     }
     // Call
     $xml->query();
     if ($xml->isError()) {
         return $xml->get_jetpack_error();
     }
     $responses = $xml->getResponse();
     $r = array();
     foreach ((array) $responses as $response) {
         if (isset($response['faultCode']) || isset($response['faultString'])) {
             $r[] = $xml->get_jetpack_error($response['faultCode'], $response['faultString']);
             continue;
         }
         if (!is_array($response[0]) || empty($response[0]['status'])) {
             $r[] = new Jetpack_Error('unknown');
             continue;
         }
         switch ($response[0]['status']) {
             case 'error':
                 $r[] = new Jetpack_Error('not_subscribed');
                 continue 2;
             case 'disabled':
                 $r[] = new Jetpack_Error('disabled');
                 continue 2;
             case 'active':
                 $r[] = new Jetpack_Error('active');
                 continue 2;
             case 'pending':
                 $r[] = true;
                 continue 2;
             default:
                 $r[] = new Jetpack_Error('unknown_status', (string) $response[0]['status']);
                 continue 2;
         }
     }
     return $r;
 }
コード例 #6
0
 static function update_role_on_com($user_id)
 {
     $signed_role = self::get_signed_role($user_id);
     Jetpack::xmlrpc_async_call('jetpack.updateRole', $user_id, $signed_role);
 }
コード例 #7
0
ファイル: stats.php プロジェクト: sajidsan/sajidsan.github.io
function stats_update_post($post)
{
    $post = get_post($post);
    if (!in_array($post->post_type, array('post', 'page', 'attachment'))) {
        return;
    }
    if (in_array($post->post_status, array('auto-draft'))) {
        return;
    }
    Jetpack::xmlrpc_async_call('jetpack.updatePost', stats_get_post($post));
}
コード例 #8
0
ファイル: jetpack.php プロジェクト: jfitzsimmons/hoseb.com
 /**
  * Set up all the data and queue it for the outgoing XML-RPC request
  */
 function sync()
 {
     global $wpdb;
     $jetpack = Jetpack::init();
     $available_modules = Jetpack::get_available_modules();
     $active_modules = Jetpack::get_active_modules();
     $modules = array();
     foreach ($available_modules as $available_module) {
         $modules[$available_module] = in_array($available_module, $active_modules);
     }
     $modules['vaultpress'] = class_exists('VaultPress') || function_exists('vaultpress_contact_service');
     $sync_data = compact('modules');
     if (count($this->sync)) {
         foreach ($this->sync as $obj => $data) {
             switch ($obj) {
                 case 'post':
                     $global_post = isset($GLOBALS['post']) ? $GLOBALS['post'] : null;
                     $GLOBALS['post'] = null;
                     foreach ($data as $post => $columns) {
                         $sync_data['post'][$post] = $jetpack->get_post($post, $columns);
                         if (isset($this->post_transitions[$post])) {
                             $sync_data['post'][$post]['transitions'] = $this->post_transitions[$post];
                         } else {
                             $sync_data['post'][$post]['transitions'] = array(false, false);
                         }
                     }
                     $GLOBALS['post'] = $global_post;
                     unset($global_post);
                     break;
                 case 'delete_post':
                     foreach ($data as $post => $true) {
                         $sync_data['delete_post'][$post] = true;
                     }
                     break;
                 case 'comment':
                     $global_comment = isset($GLOBALS['comment']) ? $GLOBALS['comment'] : null;
                     unset($GLOBALS['comment']);
                     foreach ($data as $comment => $columns) {
                         $sync_data['comment'][$comment] = $jetpack->get_comment($comment, $columns);
                     }
                     $GLOBALS['comment'] = $global_comment;
                     unset($global_comment);
                     break;
                 case 'delete_comment':
                     foreach ($data as $comment => $true) {
                         $sync_data['delete_comment'][$comment] = true;
                     }
                     break;
                 case 'tag':
                     foreach ($data as $taxonomy => $columns) {
                         $sync_data['tag'][$taxonomy] = $jetpack->get_taxonomy($taxonomy, $columns, 'post_tag');
                     }
                     break;
                 case 'delete_tag':
                     foreach ($data as $taxonomy => $columns) {
                         $sync_data['delete_tag'][$taxonomy] = $columns;
                     }
                     break;
                 case 'category':
                     foreach ($data as $taxonomy => $columns) {
                         $sync_data['category'][$taxonomy] = $jetpack->get_taxonomy($taxonomy, $columns, 'category');
                     }
                     break;
                 case 'delete_category':
                     foreach ($data as $taxonomy => $columns) {
                         $sync_data['delete_category'][$taxonomy] = $columns;
                     }
                     break;
             }
         }
         Jetpack::xmlrpc_async_call('jetpack.syncContent', $sync_data);
     }
 }