コード例 #1
0
ファイル: xmlrpc.php プロジェクト: nxtclass/NXTClass-Plugin
 /**
  * Merges the specified tags
  *
  * @since 1.0
  * @return array|object The tag data when successfully merged or an IXR_Error object on failure
  * @param array $args Arguments passed by the XML-RPC call
  * @param string $args[0] The username for authentication
  * @param string $args[1] The password for authentication
  * @param string $args[2] The old tag name or slug to be destroyed
  * @param string $args[3] The new tag name or slug where the old tag will be merged to
  *
  * XML-RPC request to merge the tag "banana" into the tag "apple"
  * <methodCall>
  *     <methodName>bb.mergeTopicTags</methodName>
  *     <params>
  *         <param><value><string>joeblow</string></value></param>
  *         <param><value><string>123password</string></value></param>
  *         <param><value><string>banana</string></value></param>
  *         <param><value><string>apple</string></value></param>
  *     </params>
  * </methodCall>
  */
 function bb_mergeTopicTags($args)
 {
     do_action('bb_xmlrpc_call', 'bb.mergeTopicTags');
     // Escape args
     $this->escape($args);
     // Get the login credentials
     $username = $args[0];
     $password = (string) $args[1];
     // Check the user is valid
     $user = $this->authenticate($username, $password, 'manage_tags', __('You do not have permission to manage tags.'));
     do_action('bb_xmlrpc_call_authenticated', 'bb.mergeTopicTags');
     // If an error was raised by authentication or by an action then return it
     if ($this->error) {
         return $this->error;
     }
     // Can only be strings
     $old_tag_id = isset($args[2]) ? (string) $args[2] : false;
     $new_tag_id = isset($args[3]) ? (string) $args[3] : false;
     // Check for bad data
     if (!$old_tag_id) {
         $this->error = new IXR_Error(400, __('The old tag id is invalid.'));
         return $this->error;
     }
     if (!$new_tag_id) {
         $this->error = new IXR_Error(400, __('The new tag id is invalid.'));
         return $this->error;
     }
     // Check the requested tags exist
     if (!($old_tag = bb_get_tag($old_tag_id))) {
         $this->error = new IXR_Error(400, __('No old tag found.'));
         return $this->error;
     }
     if (!($new_tag = bb_get_tag($new_tag_id))) {
         $this->error = new IXR_Error(400, __('No new tag found.'));
         return $this->error;
     }
     // Get the numeric tag ids
     $old_tag_id = (int) $old_tag->tag_id;
     $new_tag_id = (int) $new_tag->tag_id;
     // Rename the tag
     if (!($result = bb_rename_tag($old_tag_id, $new_tag_id))) {
         $this->error = new IXR_Error(500, __('The tags could not be merged.'));
         return $this->error;
     }
     // Get the merged tag
     $new_tag = bb_get_tag($new_tag_id);
     // Only include "safe" data in the array
     $new_tag = $this->prepare_topic_tag($new_tag);
     do_action('bb_xmlrpc_call_return', 'bb.mergeTopicTags');
     // Return the tag
     return $new_tag;
 }
コード例 #2
0
<?php

require 'admin.php';
if (!bb_current_user_can('manage_tags')) {
    bb_die(__('You are not allowed to manage tags.'));
}
$tag_id = (int) $_POST['id'];
$tag = stripslashes($_POST['tag']);
bb_check_admin_referer('rename-tag_' . $tag_id);
if (!($old_tag = bb_get_tag($tag_id))) {
    bb_die(__('Tag not found.'));
}
if ($tag = bb_rename_tag($tag_id, $tag)) {
    wp_redirect(bb_get_tag_link());
} else {
    bb_die(printf(__('There already exists a tag by that name or the name is invalid. <a href="%s">Try Again</a>'), wp_get_referer()));
}
exit;
コード例 #3
0
function rename_tag($tag_id, $tag_name)
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_rename_tag');
    return bb_rename_tag($tag_id, $tag_name);
}