| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | * @access private |
| 41 | 41 | * |
| 42 | 42 | * @var Give_API_V2 |
| 43 | 43 | */ |
| 44 | - static private $instance; | |
| 44 | + private static $instance; | |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Singleton pattern. |
| 48 | 48 | * |
| @@ -78,11 +78,11 @@ | ||
| 78 | 78 | * @access private |
| 79 | 79 | */ |
| 80 | 80 | private function init() { |
| 81 | 81 | // Setup hooks. |
| 82 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); | |
| 83 | - add_action( 'wp_enqueue_scripts', array( $this, 'localize_script' ), 999 ); | |
| 84 | - add_action( 'admin_enqueue_scripts', array( $this, 'localize_script' ), 999 ); | |
| 82 | + add_action( 'rest_api_init', [ $this, 'register_routes' ] ); | |
| 83 | + add_action( 'wp_enqueue_scripts', [ $this, 'localize_script' ], 999 ); | |
| 84 | + add_action( 'admin_enqueue_scripts', [ $this, 'localize_script' ], 999 ); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | /** |
| @@ -87,8 +87,9 @@ | ||
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * Register API routes |
| 90 | 90 | * Note: only for internal purpose. |
| 91 | + * | |
| 91 | 92 | * @todo : prevent cross domain api request |
| 92 | 93 | * |
| 93 | 94 | * @since 2.1 |
| 94 | 95 | * @access private |
| @@ -93,22 +94,27 @@ | ||
| 93 | 94 | * @since 2.1 |
| 94 | 95 | * @access private |
| 95 | 96 | */ |
| 96 | 97 | public function register_routes() { |
| 97 | - register_rest_route( $this->rest_base, '/form/(?P<id>[\d]+)', array( | |
| 98 | - 'methods' => 'GET', | |
| 99 | - 'callback' => array( $this, 'get_forms_data' ), | |
| 100 | - ) ); | |
| 98 | + register_rest_route( | |
| 99 | + $this->rest_base, | |
| 100 | + '/form/(?P<id>[\d]+)', | |
| 101 | + [ | |
| 102 | + 'methods' => 'GET', | |
| 103 | + 'callback' => [ $this, 'get_forms_data' ], | |
| 104 | + 'permission_callback' => '__return_true', | |
| 105 | + ] | |
| 106 | + ); | |
| 101 | 107 | |
| 102 | - register_rest_route( $this->rest_base, '/form-grid', array( | |
| 103 | - 'methods' => 'GET', | |
| 104 | - 'callback' => array( $this, 'get_donation_grid' ), | |
| 105 | - ) ); | |
| 106 | - | |
| 107 | - register_rest_route( $this->rest_base, '/donor-wall', array( | |
| 108 | - 'methods' => 'GET', | |
| 109 | - 'callback' => array( $this, 'get_donor_wall' ), | |
| 110 | - ) ); | |
| 108 | + register_rest_route( | |
| 109 | + $this->rest_base, | |
| 110 | + '/form-grid', | |
| 111 | + [ | |
| 112 | + 'methods' => 'GET', | |
| 113 | + 'callback' => [ $this, 'get_donation_grid' ], | |
| 114 | + 'permission_callback' => '__return_true', | |
| 115 | + ] | |
| 116 | + ); | |
| 111 | 117 | } |
| 112 | 118 | |
| 113 | 119 | /** |
| 114 | 120 | * Add api localize data |
| @@ -116,12 +122,12 @@ | ||
| 116 | 122 | * @since 2.1 |
| 117 | 123 | * @access public |
| 118 | 124 | */ |
| 119 | 125 | public function localize_script() { |
| 120 | - $data = array( | |
| 121 | - 'root' => esc_url_raw( Give_API_V2::get_rest_api() ), | |
| 122 | - 'rest_base' => $this->rest_base | |
| 123 | - ); | |
| 126 | + $data = [ | |
| 127 | + 'root' => esc_url_raw( self::get_rest_api() ), | |
| 128 | + 'rest_base' => $this->rest_base, | |
| 129 | + ]; | |
| 124 | 130 | |
| 125 | 131 | if ( is_admin() ) { |
| 126 | 132 | wp_localize_script( 'give-admin-scripts', 'giveApiSettings', $data ); |
| 127 | 133 | } else { |
| @@ -141,9 +147,9 @@ | ||
| 141 | 147 | $parameters = $request->get_params(); |
| 142 | 148 | |
| 143 | 149 | // Bailout |
| 144 | 150 | if ( ! isset( $parameters['id'] ) || empty( $parameters['id'] ) ) { |
| 145 | - return array( 'error' => 'no_parameter_given' ); | |
| 151 | + return [ 'error' => 'no_parameter_given' ]; | |
| 146 | 152 | } |
| 147 | 153 | |
| 148 | 154 | return give_form_shortcode( $parameters ); |
| 149 | 155 | } |
| @@ -159,22 +165,8 @@ | ||
| 159 | 165 | public function get_donation_grid( $request ) { |
| 160 | 166 | $parameters = $request->get_params(); |
| 161 | 167 | |
| 162 | 168 | return give_form_grid_shortcode( $parameters ); |
| 163 | - } | |
| 164 | - | |
| 165 | - /** | |
| 166 | - * Rest fetch form data callback | |
| 167 | - * | |
| 168 | - * @param WP_REST_Request $request | |
| 169 | - * | |
| 170 | - * @access public | |
| 171 | - * @return array|mixed|object | |
| 172 | - */ | |
| 173 | - public function get_donor_wall( $request ) { | |
| 174 | - $parameters = $request->get_params(); | |
| 175 | - | |
| 176 | - return Give_Donor_Wall::get_instance()->render_shortcode( $parameters ); | |
| 177 | 169 | } |
| 178 | 170 | |
| 179 | 171 | /** |
| 180 | 172 | * Get api reset url |