| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 2 | +namespace MaxButtons; | |
| 3 | 3 | /** Buttons class - handles paging issues and sanity check for individual buttons |
| 4 | 4 | */ |
| 5 | 5 | class maxButtons |
| 6 | 6 | { |
| @@ -110,7 +110,52 @@ | ||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | + } | |
| 115 | + | |
| 116 | + public static function ajax_action() | |
| 117 | + { | |
| 118 | + $action = sanitize_text_field($_POST['button_action']); | |
| 119 | + $check = wp_verify_nonce($_POST['nonce'], 'button-' . $action); | |
| 120 | + $button_id = intval($_POST["button_id"]); | |
| 121 | + $button = new maxButton(); | |
| 122 | + | |
| 123 | + if (! $check) | |
| 124 | + exit('Invalid Nonce'); | |
| 125 | + | |
| 126 | + switch($action) | |
| 127 | + { | |
| 128 | + case "delete": | |
| 129 | + $button->delete($button_id); | |
| 130 | + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=1delete'; | |
| 131 | + break; | |
| 132 | + | |
| 133 | + case "trash": | |
| 134 | + $result = $button->set($button_id); | |
| 135 | + if ($result) | |
| 136 | + $button->setStatus('trash'); | |
| 137 | + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&message=1'; | |
| 138 | + break; | |
| 139 | + case "restore": | |
| 140 | + $set = $button->set($button_id,'','trash'); | |
| 141 | + $button->setStatus("publish"); | |
| 142 | + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=list&status=trash&message=1restore'; | |
| 143 | + break; | |
| 144 | + case "copy": | |
| 145 | + $button->set($button_id); | |
| 146 | + $new_id = $button->copy(); | |
| 147 | + $redirect_url = admin_url() . 'admin.php?page=maxbuttons-controller&action=button&id=' . $new_id; | |
| 148 | + break; | |
| 149 | + | |
| 150 | + } | |
| 151 | + | |
| 152 | + if (isset($redirect_url)) { | |
| 153 | + $response = array('redirection' => $redirect_url); | |
| 154 | + echo json_encode($response); | |
| 155 | + exit(); | |
| 156 | + } | |
| 157 | + | |
| 158 | + exit(true); | |
| 114 | 159 | } |
| 115 | 160 | |
| 116 | 161 | } // class |