PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 1.0.4
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v1.0.4
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
better-payment / includes / Traits / ElementorHelper.php

ElementorHelper.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 1.0.4, at includes/Traits/ElementorHelper.php

126 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Traits;
4
5 if (!defined('ABSPATH')) {
6 exit();
7 } // Exit if accessed directly
8
9 trait ElementorHelper {
10
11 public function select2_ajax_posts_filter_autocomplete() {
12 $post_type = 'post';
13 $source_name = 'post_type';
14
15 if ( !empty( $_GET[ 'post_type' ] ) ) {
16 $post_type = sanitize_text_field( $_GET[ 'post_type' ] );
17 }
18
19 if ( !empty( $_GET[ 'source_name' ] ) ) {
20 $source_name = sanitize_text_field( $_GET[ 'source_name' ] );
21 }
22
23 $search = !empty( $_GET[ 'term' ] ) ? sanitize_text_field( $_GET[ 'term' ] ) : '';
24 $results = $post_list = [];
25 switch($source_name){
26 case 'taxonomy':
27 $args = [
28 'hide_empty' => false,
29 'orderby' => 'name',
30 'order' => 'ASC',
31 'search' => $search,
32 'number' => '5',
33 ];
34
35 if ( $post_type !== 'all' ) {
36 $args['taxonomy'] = $post_type;
37 }
38
39 $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
40 break;
41 case 'user':
42 if ( ! current_user_can( 'list_users' ) ) {
43 $post_list = [];
44 break;
45 }
46
47 $users = [];
48
49 foreach ( get_users( [ 'search' => "*{$search}*" ] ) as $user ) {
50 $user_id = $user->ID;
51 $user_name = $user->display_name;
52 $users[ $user_id ] = $user_name;
53 }
54
55 $post_list = $users;
56 break;
57 default:
58 $post_list = $this->get_query_post_list( $post_type, 10, $search );
59 }
60
61 if ( !empty( $post_list ) ) {
62 foreach ( $post_list as $key => $item ) {
63 $results[] = [ 'text' => $item, 'id' => $key ];
64 }
65 }
66 wp_send_json( [ 'results' => $results ] );
67 }
68
69 /**
70 * Select2 Ajax Get Posts Value Titles
71 * get selected value to show elementor editor panel in select2 ajax search box
72 *
73 * @access public
74 * @return void
75 * @since 1.0.0
76 */
77 public function select2_ajax_get_posts_value_titles() {
78
79 if ( empty( $_POST['id'] ) ) {
80 wp_send_json_error( [] );
81 }
82
83 if ( empty( array_filter($_POST['id']) ) ) {
84 wp_send_json_error( [] );
85 }
86 $ids = array_map('intval', $_POST['id']);
87 $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : '';
88
89 switch ( $source_name ) {
90 case 'taxonomy':
91 $args = [
92 'hide_empty' => false,
93 'orderby' => 'name',
94 'order' => 'ASC',
95 'include' => implode( ',', $ids ),
96 ];
97
98 if ( $_POST['post_type'] !== 'all' ) {
99 $args['taxonomy'] = sanitize_text_field( $_POST[ 'post_type' ] );
100 }
101
102 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
103 break;
104 case 'user':
105 $users = [];
106
107 foreach ( get_users( [ 'include' => $ids ] ) as $user ) {
108 $user_id = $user->ID;
109 $user_name = $user->display_name;
110 $users[ $user_id ] = $user_name;
111 }
112
113 $response = $users;
114 break;
115 default:
116 $post_info = get_posts( [ 'post_type' => sanitize_text_field( $_POST['post_type'] ), 'include' => implode( ',', $ids ) ] );
117 $response = wp_list_pluck( $post_info, 'post_title', 'ID' );
118 }
119
120 if ( ! empty( $response ) ) {
121 wp_send_json_success( [ 'results' => $response ] );
122 } else {
123 wp_send_json_error( [] );
124 }
125 }
126 }