Skip to content

Commit 8d0450f

Browse files
* Changed some methods from normal to final.
* Made some methods public * `has_post` * `has_get` * `has_request` * `validate_request`
1 parent 59ad35c commit 8d0450f

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

src/Ajaxer.php

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function __construct() {
103103
*
104104
* @return string
105105
*/
106-
protected function ajax_slug( $action ) {
106+
final protected function ajax_slug( $action ) {
107107
$action = ( ! empty( $this->action_prefix ) ) ? $this->action_prefix . '_' . $action : $action;
108108
$action = ( ! empty( $this->action_surfix ) ) ? $action . '_' . $this->action_surfix : $action;
109109
return $action;
@@ -119,7 +119,7 @@ protected function ajax_slug( $action ) {
119119
* @hook ajax_{ajax_action}
120120
* ajax_action will be replaced with {$this->action}-action from url
121121
*/
122-
public function ajax_request_single() {
122+
final public function ajax_request_single() {
123123
$action = false;
124124
$action_key = ( true === $this->is_single ) ? $this->action : $this->is_single;
125125

@@ -149,7 +149,7 @@ public function ajax_request_single() {
149149
*
150150
* @return string
151151
*/
152-
protected function extract_action_slug( $action ) {
152+
final protected function extract_action_slug( $action ) {
153153
return trim( trim( str_replace( array(
154154
$this->action_prefix,
155155
$this->action_surfix,
@@ -181,7 +181,7 @@ protected function trigger_ajax_callback( $action ) {
181181
/**
182182
* Handles Multiple Ajax Requests.
183183
*/
184-
public function ajax_request() {
184+
final public function ajax_request() {
185185
$action = ( isset( $_REQUEST['action'] ) && ! empty( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : false;
186186
$_action = $this->extract_action_slug( $action );
187187

@@ -204,7 +204,7 @@ public function ajax_request() {
204204
*
205205
* @return string
206206
*/
207-
public function request_type( $type = null ) {
207+
protected function request_type( $type = null ) {
208208
$type = ( ! is_array( $type ) ) ? array( $type ) : $type;
209209
if ( ! is_null( $type ) && is_array( $type ) ) {
210210
return in_array( $_SERVER['REQUEST_METHOD'], array_map( 'strtoupper', $type ), true );
@@ -268,7 +268,7 @@ private function get_post_request( $key, $default, $type ) {
268268
*
269269
* @return bool
270270
*/
271-
public function has( $key = '', $type = 'GET' ) {
271+
protected function has( $key = '', $type = 'GET' ) {
272272
switch ( $type ) {
273273
case 'GET':
274274
$has = ( isset( $_GET[ $key ] ) ) ? $_GET[ $key ] : false;
@@ -283,6 +283,33 @@ public function has( $key = '', $type = 'GET' ) {
283283
return $has;
284284
}
285285

286+
/**
287+
* @param $key
288+
*
289+
* @return bool
290+
*/
291+
public function has_get( $key ) {
292+
return $this->has( $key, 'GET' );
293+
}
294+
295+
/**
296+
* @param $key
297+
*
298+
* @return bool
299+
*/
300+
public function has_post( $key ) {
301+
return $this->has( $key, 'POST' );
302+
}
303+
304+
/**
305+
* @param $key
306+
*
307+
* @return bool
308+
*/
309+
public function has_request( $key ) {
310+
return $this->has( $key, 'REQUEST' );
311+
}
312+
286313
/**
287314
* Returns give key's value from $_GET
288315
*
@@ -349,15 +376,15 @@ protected function success_message( $success_title = false, $success_message = f
349376
* @param mixed $data
350377
* @param null $status_code
351378
*/
352-
protected function json_error( $data = null, $status_code = null ) {
379+
public function json_error( $data = null, $status_code = null ) {
353380
wp_send_json_error( $data, $status_code );
354381
}
355382

356383
/**
357384
* @param mixed $data
358385
* @param null $status_code
359386
*/
360-
protected function json_success( $data = null, $status_code = null ) {
387+
public function json_success( $data = null, $status_code = null ) {
361388
wp_send_json_success( $data, $status_code );
362389
}
363390

@@ -384,7 +411,7 @@ protected function validate( $key, $error_title = false, $error_message = false,
384411
* @param string|bool $error_message
385412
* @param array $args
386413
*/
387-
protected function error( $error_title = false, $error_message = false, $args = array() ) {
414+
public function error( $error_title = false, $error_message = false, $args = array() ) {
388415
$this->json_error( wp_parse_args( $args, $this->error_message( $error_title, $error_message ) ) );
389416
}
390417

@@ -393,7 +420,7 @@ protected function error( $error_title = false, $error_message = false, $args =
393420
* @param bool|string $success_message
394421
* @param array $args
395422
*/
396-
protected function success( $success_title = false, $success_message = false, $args = array() ) {
423+
public function success( $success_title = false, $success_message = false, $args = array() ) {
397424
$this->json_success( wp_parse_args( $args, $this->success_message( $success_title, $success_message ) ) );
398425
}
399426

@@ -404,7 +431,7 @@ protected function success( $success_title = false, $success_message = false, $a
404431
*
405432
* @return bool|mixed
406433
*/
407-
protected function validate_post( $key, $error_title = false, $error_message = false ) {
434+
public function validate_post( $key, $error_title = false, $error_message = false ) {
408435
return $this->validate( $key, $error_title, $error_message, 'POST' );
409436
}
410437

@@ -415,8 +442,19 @@ protected function validate_post( $key, $error_title = false, $error_message = f
415442
*
416443
* @return bool|mixed
417444
*/
418-
protected function validate_get( $key, $error_title = false, $error_message = false ) {
445+
public function validate_get( $key, $error_title = false, $error_message = false ) {
419446
return $this->validate( $key, $error_title, $error_message, 'GET' );
420447
}
448+
449+
/**
450+
* @param string $key
451+
* @param string|bool $error_title
452+
* @param string|bool $error_message
453+
*
454+
* @return bool|mixed
455+
*/
456+
public function validate_request( $key, $error_title = false, $error_message = false ) {
457+
return $this->validate( $key, $error_title, $error_message, 'REQUEST' );
458+
}
421459
}
422460
}

0 commit comments

Comments
 (0)