Ga_Controller_Core.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Created by PhpStorm. |
| 5 | * User: mdn |
| 6 | * Date: 2017-02-01 |
| 7 | * Time: 09:46 |
| 8 | */ |
| 9 | class Ga_Controller_Core { |
| 10 | |
| 11 | const GA_NONCE_FIELD_NAME = '_gawpnonce'; |
| 12 | const ACTION_PARAM_NAME = 'ga_action'; |
| 13 | |
| 14 | /** |
| 15 | * Runs particular action. |
| 16 | */ |
| 17 | public function handle_actions() { |
| 18 | $action = !empty( $_REQUEST[ self::ACTION_PARAM_NAME ] ) ? $_REQUEST[ self::ACTION_PARAM_NAME ] : null; |
| 19 | |
| 20 | if ( $action ) { |
| 21 | $class = get_class( $this ); |
| 22 | if ( is_callable( array( |
| 23 | $class, |
| 24 | $action |
| 25 | ) ) ) { |
| 26 | call_user_func( $class . '::' . $action ); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Verifies nonce for given acction. |
| 33 | * |
| 34 | * @param $action |
| 35 | * @return bool |
| 36 | */ |
| 37 | protected static function verify_nonce( $action ) { |
| 38 | return !isset( $_POST[ self::GA_NONCE_FIELD_NAME ] ) || !wp_verify_nonce( $_POST[ self::GA_NONCE_FIELD_NAME ], $action ); |
| 39 | } |
| 40 | } |
| 41 |