| 1 |
<?php |
| 2 |
/** |
| 3 |
* GoogleAnalytics Controller Core. |
| 4 |
* |
| 5 |
* @package GoogleAnalytics |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Core Controller. |
| 10 |
*/ |
| 11 |
class Ga_Controller_Core { |
| 12 |
|
| 13 |
const GA_NONCE_FIELD_NAME = '_gawpnonce'; |
| 14 |
const ACTION_PARAM_NAME = 'ga_action'; |
| 15 |
|
| 16 |
/** |
| 17 |
* Runs particular action. |
| 18 |
*/ |
| 19 |
public function handle_actions() { |
| 20 |
if ( false === current_user_can( 'manage_options' ) ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
// Nonce verification happens in verify_nonce function. |
| 25 |
$action = false === empty( $_REQUEST[ self::ACTION_PARAM_NAME ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ self::ACTION_PARAM_NAME ] ) ) : null; // phpcs:ignore |
| 26 |
|
| 27 |
if ( $action ) { |
| 28 |
$class = get_class( $this ); |
| 29 |
if ( is_callable( |
| 30 |
array( |
| 31 |
$class, |
| 32 |
$action, |
| 33 |
) |
| 34 |
) ) { |
| 35 |
call_user_func( $class . '::' . $action ); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Verifies nonce for given action. |
| 42 |
* |
| 43 |
* @param string $action Action. |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
public static function verify_nonce( $action ) { |
| 47 |
$nonce = filter_input( INPUT_POST, self::GA_NONCE_FIELD_NAME, FILTER_SANITIZE_STRING ); |
| 48 |
|
| 49 |
return false !== wp_verify_nonce( $nonce, $action ); |
| 50 |
} |
| 51 |
} |
| 52 |
|