PluginProbe
Email Log / 2.1.0
Email Log v2.1.0
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / include / Core / Request / NonceChecker.php

NonceChecker.php in Email Log 2.1.0, at include/Core/Request/NonceChecker.php

80 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace EmailLog\Core\Request;
2
3 use EmailLog\Core\Loadie;
4 use EmailLog\Core\UI\Page\LogListPage;
5
6 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
7
8 /**
9 * Check nonce for all Email Log requests.
10 *
11 * @since 2.0.0
12 */
13 class NonceChecker implements Loadie {
14
15 /**
16 * Setup hooks.
17 *
18 * @inheritdoc
19 */
20 public function load() {
21 add_action( 'admin_init', array( $this, 'check_nonce' ) );
22 }
23
24 /**
25 * Check nonce for all Email Log Requests.
26 * All Email Log Requests will have the `el_` prefix and
27 * nonce would be available at `el_{action_name}_nonce`.
28 */
29 public function check_nonce() {
30 if ( ! isset( $_POST['el-action'] ) && ! isset( $_REQUEST['action'] ) ) {
31 return;
32 }
33
34 if ( isset( $_POST['el-action'] ) ) {
35 $action = sanitize_text_field( $_POST['el-action'] );
36
37 if ( ! isset( $_POST[ $action . '_nonce' ] ) ) {
38 return;
39 }
40
41 if ( ! wp_verify_nonce( $_POST[ $action . '_nonce' ], $action ) ) {
42 return;
43 }
44 }
45
46 if ( isset( $_REQUEST['action'] ) ) {
47 $action = sanitize_text_field( $_REQUEST['action'] );
48
49 if ( 'el-log-list-delete' !== substr( $action, 0, 18 ) ) {
50 return;
51 }
52
53 if ( ! wp_verify_nonce( $_REQUEST[ LogListPage::DELETE_LOG_NONCE_FIELD ], LogListPage::DELETE_LOG_ACTION ) ) {
54 return;
55 }
56 }
57
58 /**
59 * Perform `el` action.
60 * Nonce check has already happened at this point.
61 *
62 * @since 2.0.0
63 *
64 * @param string $action Action name.
65 * @param array $_REQUEST Request data.
66 */
67 do_action( 'el_action', $action, $_REQUEST );
68
69 /**
70 * Perform `el` action.
71 * Nonce check has already happened at this point.
72 *
73 * @since 2.0.0
74 *
75 * @param array $_REQUEST Request data.
76 */
77 do_action( $action, $_REQUEST );
78 }
79 }
80