/** * Delete shortlink function */ public function delete_yourls() { // only run on admin if (!is_admin()) { die; } // start our return $ret = array(); // verify our nonce $check = check_ajax_referer('yourls_editor_delete', 'nonce', false); // check to see if our nonce failed if (!$check) { $ret['success'] = false; $ret['errcode'] = 'NONCE_FAILED'; $ret['message'] = __('The nonce did not validate.', 'wpyourls'); echo json_encode($ret); die; } // bail if the API key or URL have not been entered if (false === ($api = YOURLSCreator_Helper::get_yourls_api_data())) { $ret['success'] = false; $ret['errcode'] = 'NO_API_DATA'; $ret['message'] = __('No API data has been entered.', 'wpyourls'); echo json_encode($ret); die; } // bail without a post ID if (empty($_POST['post_id'])) { $ret['success'] = false; $ret['errcode'] = 'NO_POST_ID'; $ret['message'] = __('No post ID was present.', 'wpyourls'); echo json_encode($ret); die; } // now cast the post ID $post_id = absint($_POST['post_id']); // do a quick check for a URL if (false === ($link = YOURLSCreator_Helper::get_yourls_meta($post_id, '_yourls_url'))) { $ret['success'] = false; $ret['errcode'] = 'NO_URL_EXISTS'; $ret['message'] = __('There is no URL to delete.', 'wpyourls'); echo json_encode($ret); die; } // passed it all. go forward delete_post_meta($post_id, '_yourls_url'); delete_post_meta($post_id, '_yourls_clicks'); // and do the API return $ret['success'] = true; $ret['message'] = __('You have removed your YOURLS link.', 'wpyourls'); $ret['linkbox'] = YOURLSCreator_Helper::get_yourls_subbox($post_id); echo json_encode($ret); die; }
/** * Display YOURLS shortlink if present * * @param [type] $post [description] * @return [type] [description] */ public static function yourls_post_display($post) { // cast our post ID $post_id = absint($post->ID); // check for a link and click counts $link = YOURLSCreator_Helper::get_yourls_meta($post_id, '_yourls_url'); // if we have no link, display our box if (empty($link)) { // display the box echo YOURLSCreator_Helper::get_yourls_subbox($post_id); // and return return; } // we have a shortlink. show it along with the count if (!empty($link)) { // get my count $count = YOURLSCreator_Helper::get_yourls_meta($post_id, '_yourls_clicks', '0'); // and echo the box echo YOURLSCreator_Helper::get_yourls_linkbox($link, $post_id, $count); } }