function blc_unlink($params)
 {
     if ($this->_checkBLC()) {
         $link = new blcLink(intval($params['linkID']));
         if (!$link->valid()) {
             return "Oops, I can't find the link " . intval($params['linkID']);
         }
         $rez = $link->unlink();
         $rez['old_link_id'] = $params['linkID'];
         $rez['linkType'] = $params['linkType'];
         return $rez;
     } else {
         return array('error' => "Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_unlink');
     }
 }
Beispiel #2
0
 /**
  * AJAX hook for the "Unlink" action links in Tools -> Broken Links. 
  * Removes the specified link from all posts and other supported items.
  *
  * @return void
  */
 function ajax_unlink()
 {
     if (!current_user_can('edit_others_posts') || !check_ajax_referer('blc_unlink', false, false)) {
         die(json_encode(array('error' => __("You're not allowed to do that!", 'broken-link-checker'))));
     }
     if (isset($_POST['link_id'])) {
         //Load the link
         $link = new blcLink(intval($_POST['link_id']));
         if (!$link->valid()) {
             die(json_encode(array('error' => sprintf(__("Oops, I can't find the link %d", 'broken-link-checker'), intval($_POST['link_id'])))));
         }
         //Try and unlink it
         $rez = $link->unlink();
         if ($rez === false) {
             die(json_encode(array('error' => __("An unexpected error occured!", 'broken-link-checker'))));
         } else {
             $response = array('cnt_okay' => $rez['cnt_okay'], 'cnt_error' => $rez['cnt_error'], 'errors' => array());
             foreach ($rez['errors'] as $error) {
                 /** @var WP_Error $error */
                 array_push($response['errors'], implode(', ', $error->get_error_messages()));
             }
             die(json_encode($response));
         }
     } else {
         die(json_encode(array('error' => __("Error : link_id not specified", 'broken-link-checker'))));
     }
 }
 function unlink()
 {
     $information = array();
     if (!current_user_can('edit_others_posts')) {
         $information['error'] = 'NOTALLOW';
         return $information;
     }
     if (isset($_POST['link_id'])) {
         //Load the link
         $link = new blcLink(intval($_POST['link_id']));
         if (!$link->valid()) {
             $information['error'] = 'NOTFOUNDLINK';
             // Oops, I can't find the link
             return $information;
         }
         //Try and unlink it
         $rez = $link->unlink();
         if ($rez === false) {
             $information['error'] = 'UNDEFINEDERROR';
             // An unexpected error occured!
             return $information;
         } else {
             $response = array('cnt_okay' => $rez['cnt_okay'], 'cnt_error' => $rez['cnt_error'], 'errors' => array());
             foreach ($rez['errors'] as $error) {
                 /** @var WP_Error $error */
                 array_push($response['errors'], implode(', ', $error->get_error_messages()));
             }
             return $response;
         }
     } else {
         $information['error'] = __("Error : link_id not specified");
         return $information;
     }
 }