PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.1
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
← All changes | includes/Traits/ElementorHelper.php +83 -2 1.0.2 → 2.4.1 View file →
@@ -7,9 +7,29 @@
7 7 } // Exit if accessed directly
8 8
9 9 trait ElementorHelper {
10 10
11 + /**
12 + * Gate for the Elementor editor's select2 lookups.
13 + *
14 + * Both endpoints are registered for every logged-in user and carried neither a nonce nor
15 + * a capability check, so any subscriber — or a cross-site request riding an editor's
16 + * session — could list post titles and terms, unpublished ones included. They exist only
17 + * for the editor, so they require what the editor requires.
18 + *
19 + * @since 2.3.4
20 + *
21 + * @return void Ends the request when refused.
22 + */
23 + private function verify_select2_request() {
24 + if ( ! check_ajax_referer( 'better_payment_select2', 'security', false ) || ! current_user_can( 'edit_posts' ) ) {
25 + wp_send_json_error( [], 403 );
26 + }
27 + }
28 +
11 29 public function select2_ajax_posts_filter_autocomplete() {
30 + $this->verify_select2_request();
31 +
12 32 $post_type = 'post';
13 33 $source_name = 'post_type';
14 34
15 35 if ( !empty( $_GET[ 'post_type' ] ) ) {
@@ -54,9 +74,13 @@
54 74
55 75 $post_list = $users;
56 76 break;
57 77 default:
58 - $post_list = $this->get_query_post_list( $post_type, 10, $search );
78 + if ( $post_type === 'fluent-products' && function_exists('fluentCart') ) {
79 + $post_list = $this->get_fluentcart_products( $search );
80 + } else {
81 + $post_list = $this->get_query_post_list( $post_type, 10, $search );
82 + }
59 83 }
60 84
61 85 if ( !empty( $post_list ) ) {
62 86 foreach ( $post_list as $key => $item ) {
@@ -74,9 +98,10 @@
74 98 * @return void
75 99 * @since 1.0.0
76 100 */
77 101 public function select2_ajax_get_posts_value_titles() {
78 -
102 + $this->verify_select2_request();
103 +
79 104 if ( empty( $_POST['id'] ) ) {
80 105 wp_send_json_error( [] );
81 106 }
82 107
@@ -122,5 +147,61 @@
122 147 } else {
123 148 wp_send_json_error( [] );
124 149 }
125 150 }
151 +
152 + /**
153 + * Add elementor category
154 + *
155 + * @since v1.0.0
156 + */
157 + public function register_widget_categories( $elements_manager ) {
158 + $elements_manager->add_category(
159 + 'better-payment',
160 + [
161 + 'title' => __( 'Better Payment', 'better-payment' ),
162 + 'icon' => 'font',
163 + ], 1 );
164 + }
165 +
166 + /**
167 + * Get FluentCart products for select2 dropdown
168 + *
169 + * @param string $search Search term
170 + * @return array
171 + */
172 + private function get_fluentcart_products( $search = '' ) {
173 + if ( ! function_exists('fluentCart') || ! class_exists( '\FluentCart\App\Models\Product' ) ) {
174 + return [];
175 + }
176 +
177 + if ( ! is_user_logged_in() || ! current_user_can('edit_posts') ) {
178 + return [];
179 + }
180 +
181 + try {
182 + $product_model = new \FluentCart\App\Models\Product();
183 +
184 + $query = $product_model->newQuery()
185 + ->where('post_status', 'publish')
186 + ->limit(10);
187 +
188 +
189 + if ( ! empty( $search ) ) {
190 + $query->where('post_title', 'LIKE', '%' . sanitize_text_field( $search ) . '%');
191 + }
192 +
193 + $products = $query->get();
194 +
195 + $product_list = [];
196 + if ( ! empty( $products ) ) {
197 + foreach ( $products as $product ) {
198 + $product_list[ $product->ID ] = $product->post_title;
199 + }
200 + }
201 +
202 + return $product_list;
203 + } catch ( \Exception $e ) {
204 + return [];
205 + }
206 + }
126 207 }