PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.75
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.75
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / utils / class-queryparameters.php

class-queryparameters.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.75, at public/utils/class-queryparameters.php

72 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\utils;
4
5 /**
6 * Class containing utility functions for the sanitizing and getting query parameters.
7 */
8 class QueryParameters {
9
10 /**
11 * Return a text sanitized, unslashed query parameter by its key, validated with a nonce.
12 *
13 * @param String $key Key for the query parameter to return.
14 * @param String $nonce_action Name of the nonce action to verify the given nonce against.
15 * @param String $nonce_arg Query parmeter the nonce is in.
16 */
17 public static function get_param( $key, $nonce_action, $nonce_arg = '_wpnonce' ) {
18 if (
19 isset( $_GET[ $key ] ) &&
20 isset( $_GET[ $nonce_arg ] ) &&
21 wp_verify_nonce( sanitize_text_field( wp_unslash( ( $_GET[ $nonce_arg ] ) ) ), $nonce_action )
22 ) {
23 return sanitize_text_field( wp_unslash( ( $_GET[ $key ] ) ) );
24 }
25
26 return null;
27 }
28
29 /**
30 * Return an array sanitized, unslashed query parameter by its key, validated with a nonce.
31 *
32 * @param String $key Key for the query parameter to return.
33 * @param String $nonce_action Name of the nonce action to verify the given nonce against.
34 * @param String $nonce_arg Query parmeter the nonce is in.
35 */
36 public static function get_param_array( $key, $nonce_action, $nonce_arg = '_wpnonce' ) {
37 if (
38 isset( $_GET[ $key ] ) &&
39 isset( $_GET[ $nonce_arg ] ) &&
40 wp_verify_nonce( sanitize_text_field( wp_unslash( ( $_GET[ $nonce_arg ] ) ) ), $nonce_action )
41 ) {
42 return array_map( 'sanitize_text_field', wp_unslash( $_GET[ $key ] ) );
43 }
44
45 return array();
46 }
47
48 /**
49 * Return an associative array of query param keys and values given an array of keys
50 * that are sanitized and validated against a nonce
51 *
52 * @param String $keys Array of keys to fetch query parameter values for.
53 * @param String $nonce_action Name of the nonce action to verify the given nonce against.
54 * @param String $nonce_arg Query parmeter the nonce is in.
55 */
56 public static function get_parameters( $keys, $nonce_action, $nonce_arg = '_wpnonce' ) {
57 $query_params = array_reduce(
58 $keys,
59 function( $result, $key ) use ( $nonce_arg, $nonce_action ) {
60 $query_param = QueryParameters::get_param( $key, $nonce_action, $nonce_arg );
61
62 $result[ $key ] = $query_param;
63 return $result;
64 },
65 array()
66 );
67
68 return $query_params;
69 }
70 }
71
72