Ejemplo n.º 1
0
 /**
  * Toggles page security on or off - removes all groups from post if toggled off
  *
  * @global wpdb $wpdb
  */
 public static function update_security()
 {
     global $wpdb;
     $response = array();
     //Added in 1.1 - ensures current user is an admin before processing, else returns an error (probably not necessary - but just in case...)
     if (!current_user_can('edit_others_posts')) {
         //ERROR! - membership not found.
         $response = new WP_Ajax_Response(array('what' => 'update_sec', 'action' => 'update_security', 'id' => new WP_Error('error', __('User is not authorized.', 'contexture-page-security'))));
         $response->send();
     }
     //VALIDATE - ensure type and id are set
     if (empty($_REQUEST['object_type']) || empty($_REQUEST['object_id'])) {
         //ERROR! - membership not found.
         $response = new WP_Ajax_Response(array('what' => 'update_sec', 'action' => 'update_security', 'id' => new WP_Error('error', __('Object type or ID was not defined.', 'contexture-page-security'))));
         $response->send();
     }
     //PROCESS REQUEST....
     switch ($_REQUEST['setting']) {
         //TURNING SECURITY ON
         case 'on':
             $response = array('what' => 'update_sec', 'action' => 'update_security', 'id' => (int) add_metadata($_REQUEST['object_type'], $_REQUEST['object_id'], 'ctx_ps_security', '1', true), 'data' => __('Security enabled.', 'contexture-page-security'));
             break;
             //TURNING SECURITY OFF
         //TURNING SECURITY OFF
         case 'off':
             if (CTXPS_Queries::delete_security($_REQUEST['object_id'], '', $_REQUEST['object_type']) !== false) {
                 //Successfully deleted security
                 $response = array('what' => 'update_sec', 'action' => 'update_security', 'id' => delete_metadata($_REQUEST['object_type'], $_REQUEST['object_id'], 'ctx_ps_security'), 'data' => __('Security disabled.', 'contexture-page-security'));
                 //If we disabled a term, return supplemental table data
                 if ($_REQUEST['object_type'] == 'term') {
                     $response['supplemental'] = array('html' => new CTXPS_Table_Packages('taxonomy_term_groups', false, true));
                 }
             } else {
                 //Failed to delete security
                 $response = new WP_Ajax_Response(array('what' => 'update_sec', 'action' => 'update_security', 'id' => new WP_Error('error', __('Query failed.', 'contexture-page-security'))));
             }
             break;
             //ERROR: UNSPECIFIED SETTING CHANGE
         //ERROR: UNSPECIFIED SETTING CHANGE
         default:
             $response = new WP_Ajax_Response(array('what' => 'update_sec', 'action' => 'update_security', 'id' => new WP_Error('error', __('Unrecognized request.', 'contexture-page-security'))));
             break;
     }
     //SEND THE RESULT
     $response = new WP_Ajax_Response($response);
     $response->send();
 }