PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | includes/api/class-give-api-v2.php +30 -37 2.3.04.16.9 View file →
@@ -3,9 +3,9 @@
3 3 * Give API V2
4 4 *
5 5 * @package Give
6 6 * @subpackage Classes/API
7 - * @copyright Copyright (c) 2018, WordImpress
7 + * @copyright Copyright (c) 2018, GiveWP
8 8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 9 * @since 2.1
10 10 */
11 11
@@ -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,16 +78,18 @@
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 /**
89 89 * Register API routes
90 + * Note: only for internal purpose.
91 + *
90 92 * @todo : prevent cross domain api request
91 93 *
92 94 * @since 2.1
93 95 * @access private
@@ -92,22 +94,27 @@
92 94 * @since 2.1
93 95 * @access private
94 96 */
95 97 public function register_routes() {
96 - register_rest_route( $this->rest_base, '/form/(?P<id>[\d]+)', array(
97 - 'methods' => 'GET',
98 - 'callback' => array( $this, 'get_forms_data' ),
99 - ) );
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 + );
100 107
101 - register_rest_route( $this->rest_base, '/form-grid', array(
102 - 'methods' => 'GET',
103 - 'callback' => array( $this, 'get_donation_grid' ),
104 - ) );
105 -
106 - register_rest_route( $this->rest_base, '/donor-wall', array(
107 - 'methods' => 'GET',
108 - 'callback' => array( $this, 'get_donor_wall' ),
109 - ) );
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 + );
110 117 }
111 118
112 119 /**
113 120 * Add api localize data
@@ -115,12 +122,12 @@
115 122 * @since 2.1
116 123 * @access public
117 124 */
118 125 public function localize_script() {
119 - $data = array(
120 - 'root' => esc_url_raw( Give_API_V2::get_rest_api() ),
121 - 'rest_base' => $this->rest_base
122 - );
126 + $data = [
127 + 'root' => esc_url_raw( self::get_rest_api() ),
128 + 'rest_base' => $this->rest_base,
129 + ];
123 130
124 131 if ( is_admin() ) {
125 132 wp_localize_script( 'give-admin-scripts', 'giveApiSettings', $data );
126 133 } else {
@@ -140,9 +147,9 @@
140 147 $parameters = $request->get_params();
141 148
142 149 // Bailout
143 150 if ( ! isset( $parameters['id'] ) || empty( $parameters['id'] ) ) {
144 - return array( 'error' => 'no_parameter_given' );
151 + return [ 'error' => 'no_parameter_given' ];
145 152 }
146 153
147 154 return give_form_shortcode( $parameters );
148 155 }
@@ -158,22 +165,8 @@
158 165 public function get_donation_grid( $request ) {
159 166 $parameters = $request->get_params();
160 167
161 168 return give_form_grid_shortcode( $parameters );
162 - }
163 -
164 - /**
165 - * Rest fetch form data callback
166 - *
167 - * @param WP_REST_Request $request
168 - *
169 - * @access public
170 - * @return array|mixed|object
171 - */
172 - public function get_donor_wall( $request ) {
173 - $parameters = $request->get_params();
174 -
175 - return Give_Donor_Wall::get_instance()->render_shortcode( $parameters );
176 169 }
177 170
178 171 /**
179 172 * Get api reset url