lightspeeddevelopment /
lsx
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 4 | exit; |
||
| 5 | } |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Holds functions for rest api specific actions. |
||
| 9 | * |
||
| 10 | * @author LightSpeed |
||
| 11 | * @category Widgets |
||
| 12 | * @package LSX |
||
| 13 | * @return LSX_Rest_Helper |
||
| 14 | */ |
||
| 15 | class LSX_Rest_Helper { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Holds class instance |
||
| 19 | * |
||
| 20 | * @since 1.0.0 |
||
| 21 | * @var object |
||
| 22 | */ |
||
| 23 | protected static $instance = null; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Holds the conditional. |
||
| 27 | * |
||
| 28 | * @var boolean |
||
| 29 | */ |
||
| 30 | protected $is_rest_request = false; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Constructor. |
||
| 34 | */ |
||
| 35 | public function __construct() { |
||
|
0 ignored issues
–
show
|
|||
| 36 | add_filter( 'tribe_events_views_v2_rest_params', array( $this, 'check_event_request' ), 10, 2 ); |
||
| 37 | } |
||
|
0 ignored issues
–
show
|
|||
| 38 | /** |
||
| 39 | * Return an instance of this class. |
||
| 40 | * |
||
| 41 | * @since 1.0.0 |
||
| 42 | * @return object A single instance of this class. |
||
| 43 | */ |
||
| 44 | public static function get_instance() { |
||
| 45 | // If the single instance hasn't been set, set it now. |
||
| 46 | if ( null === self::$instance ) { |
||
|
0 ignored issues
–
show
|
|||
| 47 | self::$instance = new self; |
||
|
0 ignored issues
–
show
|
|||
| 48 | } |
||
|
0 ignored issues
–
show
|
|||
| 49 | return self::$instance; |
||
| 50 | } |
||
|
0 ignored issues
–
show
|
|||
| 51 | |||
| 52 | /** |
||
| 53 | * This will set the 'is_rest_request' variable as true if it runs. Tribe has already done the checkes for us. |
||
| 54 | * |
||
| 55 | * @param array $params |
||
|
0 ignored issues
–
show
|
|||
| 56 | * @param array $request |
||
|
0 ignored issues
–
show
|
|||
| 57 | * @return void |
||
|
0 ignored issues
–
show
|
|||
| 58 | */ |
||
| 59 | public function check_event_request( $params, $request ) { |
||
| 60 | $this->is_rest_request = true; |
||
| 61 | return $params; |
||
| 62 | } |
||
|
0 ignored issues
–
show
|
|||
| 63 | |||
| 64 | /** |
||
| 65 | * Determines if the request is an REST API request. |
||
| 66 | * |
||
| 67 | * @return bool True if it's a REST API request, false otherwise. |
||
| 68 | */ |
||
| 69 | public function is_rest_api_request() { |
||
| 70 | if ( true === $this->is_rest_request ) { |
||
|
0 ignored issues
–
show
|
|||
| 71 | return $this->is_rest_request; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ( empty( $_SERVER['REQUEST_URI'] ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 75 | return false; |
||
| 76 | } |
||
|
0 ignored issues
–
show
|
|||
| 77 | $rest_prefix = trailingslashit( rest_get_url_prefix() ); |
||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 9 spaces
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||
| 78 | $this->is_rest_request = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix ) ); |
||
|
0 ignored issues
–
show
|
|||
| 79 | return $this->is_rest_request; |
||
| 80 | } |
||
|
0 ignored issues
–
show
|
|||
| 81 | } |
||
| 82 | $rest_helper = LSX_Rest_Helper::get_instance(); |
||
| 83 |