|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Main Algolia Verify Nonces class |
|
4
|
|
|
* Called from main plugin file class-algolia-woo-indexer.php |
|
5
|
|
|
* |
|
6
|
|
|
* @package algolia-woo-indexer |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Algowoo; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Abort if this file is called directly |
|
13
|
|
|
*/ |
|
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
15
|
|
|
exit; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
if ( ! class_exists( 'Algolia_Verify_Nonces' ) ) { |
|
19
|
|
|
/** |
|
20
|
|
|
* Verify submitted nonces |
|
21
|
|
|
*/ |
|
22
|
|
|
class Algolia_Verify_Nonces { |
|
23
|
|
|
/** |
|
24
|
|
|
* Verify nonces before we update options and settings * |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function verify_settings_nonce() { |
|
29
|
|
|
/** |
|
30
|
|
|
* Filter incoming nonces and values |
|
31
|
|
|
*/ |
|
32
|
|
|
$settings_nonce = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_nonce_name', FILTER_DEFAULT ); |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Return boolean depending on if the nonce has been set |
|
36
|
|
|
*/ |
|
37
|
|
|
if ( ! isset( $settings_nonce ) ) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Check if we are sending products to Algolia |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function verify_send_products_nonce() { |
|
48
|
|
|
/** |
|
49
|
|
|
* Filter incoming nonces and values |
|
50
|
|
|
*/ |
|
51
|
|
|
$send_products_nonce = filter_input( INPUT_POST, 'send_products_to_algolia_nonce_name', FILTER_DEFAULT ); |
|
52
|
|
|
$send_products_to_algolia = filter_input( INPUT_POST, 'send_products_to_algolia', FILTER_DEFAULT ); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Display error and die if nonce is not verified and does not pass security check |
|
56
|
|
|
* Also check if the hidden value field send_products_to_algolia is set |
|
57
|
|
|
*/ |
|
58
|
|
|
|
|
59
|
|
|
if ( ! wp_verify_nonce( $send_products_nonce, 'send_products_to_algolia_nonce_action' ) && isset( $send_products_to_algolia ) ) { |
|
60
|
|
|
wp_die( esc_html__( 'Action is not allowed.', 'algolia-woo-indexer' ), esc_html__( 'Error!', 'algolia-woo-indexer' ) ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* If we have verified the send_products_nonce and the send_products hidden field is set, return true |
|
65
|
|
|
*/ |
|
66
|
|
|
if ( wp_verify_nonce( $send_products_nonce, 'send_products_to_algolia_nonce_action' ) && isset( $send_products_to_algolia ) ) { |
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|