PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.3.3
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.3.3
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 1.0.5 1.0.6 All 66 releases
better-payment / includes / Traits / WordPressHelper.php

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

62 lines 1.7 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 WordPressHelper {
10
11 /**
12 * Get all types of post.
13 *
14 * @param string $post_type
15 *
16 * @return array
17 */
18 public function get_post_list($post_type = 'any')
19 {
20 return $this->get_query_post_list($post_type);
21 }
22
23 public function get_query_post_list($post_type = 'any', $limit = -1, $search = '')
24 {
25 global $wpdb;
26 $where = '';
27 $data = [];
28
29 if (-1 == $limit) {
30 $limit = '';
31 } elseif (0 == $limit) {
32 $limit = "limit 0,1";
33 } else {
34 $limit = $wpdb->prepare(" limit 0,%d", esc_sql($limit));
35 }
36
37 if ('any' === $post_type) {
38 $in_search_post_types = get_post_types(['exclude_from_search' => false]);
39 if (empty($in_search_post_types)) {
40 $where .= ' AND 1=0 ';
41 } else {
42 $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '",
43 array_map('esc_sql', $in_search_post_types)) . "')";
44 }
45 } elseif (!empty($post_type)) {
46 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_type = %s", esc_sql($post_type));
47 }
48
49 if (!empty($search)) {
50 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql($search) . '%');
51 }
52
53 $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' $where $limit";
54 $results = $wpdb->get_results($query);
55 if (!empty($results)) {
56 foreach ($results as $row) {
57 $data[$row->ID] = $row->post_title;
58 }
59 }
60 return $data;
61 }
62 }