PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.9.4
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.9.4
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / includes / class-polylang.php
folders / includes Last commit date
class-affiliate.php 3 years ago class-polylang.php 2 years ago class-review-box.php 2 years ago class-upgrade-box.php 3 years ago class-wpml.php 3 years ago folders.class.php 2 years ago form.class.php 3 years ago media.replace.php 2 years ago plugins.class.php 3 years ago tree.class.php 2 years ago
class-polylang.php
231 lines
1 <?php
2 /**
3 * Class Folders PolyLang
4 *
5 * @author : Premio <contact@premio.io>
6 * @license : GPL2
7 * */
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 class WCP_Folder_PolyLang
14 {
15
16 /**
17 * The Name of this plugin.
18 *
19 * @var string $active Checking for Plugin is active or not
20 * @since 1.0.0
21 * @access public
22 */
23 private $active;
24
25 /**
26 * The Name of this plugin.
27 *
28 * @var string $poly_lang_term_taxonomy_id Poly Lang taxonomy id
29 * @since 1.0.0
30 * @access public
31 */
32 private $poly_lang_term_taxonomy_id;
33
34 /**
35 * The Name of this plugin.
36 *
37 * @var string $total total posts in taxonomy
38 * @since 1.0.0
39 * @access public
40 */
41 private $total;
42
43
44 /**
45 * Define the core functionality of the plugin.
46 *
47 * Set the plugin name and the plugin version that can be used throughout the plugin.
48 * Load the dependencies, define the locale, and set the hooks for the admin area and
49 * the public-facing side of the site.
50 *
51 * @since 1.0.0
52 */
53 public function __construct()
54 {
55 $this->active = false;
56 $this->total = 0;
57 add_action("admin_init", [$this, 'init']);
58
59 }//end __construct()
60
61
62 /**
63 * Filters the taxonomy data
64 *
65 * @since 1.0.0
66 * @access public
67 * @return
68 */
69 public function init()
70 {
71 global $wpdb, $polylang, $typenow;
72 $this->active = function_exists("pll_get_post_translations") && function_exists("pll_is_translated_post_type");
73
74 if ($this->active) {
75 if (isset($polylang->curlang) && is_object($polylang->curlang)) {
76 $this->poly_lang_term_taxonomy_id = $polylang->curlang->term_taxonomy_id;
77
78 add_filter('premio_folder_item_in_taxonomy', [$this, 'items_in_taxonomy'], 10, 2);
79 add_filter('premio_folder_un_categorized_items', [$this, 'un_categorized_items'], 10, 2);
80 add_filter('premio_folder_all_categorized_items', [$this, 'all_categorized_items'], 10, 2);
81 }
82 }
83
84 }//end init()
85
86
87 /**
88 * Get total number on taxonomies used in Polylang
89 *
90 * @since 1.0.0
91 * @access public
92 * @return $total
93 */
94 public function set_total($post_type)
95 {
96 if ($this->active) {
97 $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'";
98 if ($post_type != 'attachment') {
99 $where = "post_status != 'trash'";
100 }
101
102 global $wpdb;
103 $query = "SELECT COUNT(tmp.ID) FROM
104 (
105 SELECT posts.ID
106 FROM {$wpdb->posts} AS posts
107 LEFT JOIN {$wpdb->term_relationships} AS trs
108 ON posts.ID = trs.object_id
109 LEFT JOIN {$wpdb->postmeta} AS postmeta
110 ON (posts.ID = postmeta.post_id AND postmeta.meta_key = '_wp_attached_file')
111 WHERE posts.post_type = '%s'
112 AND trs.term_taxonomy_id IN (%s)
113 AND ({$where})
114 GROUP BY posts.ID
115 ) as tmp";
116 $query = $wpdb->prepare($query, [$post_type, $this->poly_lang_term_taxonomy_id]);
117 $this->total = (int) $wpdb->get_var($query);
118 }//end if
119
120 }//end set_total()
121
122
123 /**
124 * Check the items in taxonomies
125 *
126 * @since 1.0.0
127 * @access public
128 * @return $counter
129 */
130 public function items_in_taxonomy($term_id, $arg=[])
131 {
132 if ($this->active) {
133 $post_type = isset($arg['post_type']) ? $arg['post_type'] : "";
134 $taxonomy = isset($arg['taxonomy']) ? $arg['taxonomy'] : "";
135 $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'";
136 if ($post_type != 'attachment') {
137 $where = "post_status != 'trash'";
138 }
139
140 global $wpdb;
141 $term_taxonomy_id = get_term_by('id', (int) $term_id, $taxonomy, OBJECT)->term_taxonomy_id;
142 $query = "SELECT COUNT(tmp.ID) FROM
143 (
144 SELECT posts.ID FROM {$wpdb->posts} AS posts
145 LEFT JOIN {$wpdb->term_relationships} AS tr1
146 ON (posts.ID = tr1.object_id)
147 INNER JOIN {$wpdb->term_relationships} AS tr2
148 ON (posts.ID = tr2.object_id and tr2.term_taxonomy_id IN (%s))
149 LEFT JOIN {$wpdb->postmeta} AS postmeta ON ( posts.ID = postmeta.post_id AND postmeta.meta_key = '_wp_attached_file' )
150 WHERE (tr1.term_taxonomy_id IN (%s))
151 AND posts.post_type = '%s'
152 AND (({$where}))
153 GROUP BY posts.ID
154 ) as tmp";
155 $query = $wpdb->prepare($query, [$term_taxonomy_id, $this->poly_lang_term_taxonomy_id, $post_type]);
156 $counter = (int) $wpdb->get_var($query);
157 return $counter ? $counter : 0;
158 }//end if
159
160 return null;
161
162 }//end items_in_taxonomy()
163
164
165 /**
166 * Check the items in uncategorized taxonomies
167 *
168 * @since 1.0.0
169 * @access public
170 * @return $counter
171 */
172 public function un_categorized_items($post_type, $taxonomy)
173 {
174 if ($this->active) {
175 global $wpdb;
176 $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'";
177 if ($post_type != 'attachment') {
178 $where = "post_status != 'trash'";
179 }
180
181 $query = "SELECT COUNT(tmp.ID) FROM
182 (
183 SELECT posts.ID
184 FROM {$wpdb->posts} AS posts
185 INNER JOIN {$wpdb->term_relationships} AS tr1
186 ON posts.ID = tr1.object_id AND tr1.term_taxonomy_id IN (%s)
187 INNER JOIN {$wpdb->term_relationships} AS tr2
188 ON (tr2.object_id = posts.ID)
189 JOIN {$wpdb->term_taxonomy} as tx
190 ON tx.term_taxonomy_id = tr2.term_taxonomy_id AND tx.taxonomy = '%s'
191 WHERE posts.post_type = '%s'
192 AND ({$where})
193 GROUP BY posts.ID
194 ) as tmp";
195 $query = $wpdb->prepare($query, [$this->poly_lang_term_taxonomy_id, $taxonomy, $post_type]);
196 $fileInFolder = (int) $wpdb->get_var($query);
197 $fileInFolder = !($fileInFolder) ? 0 : $fileInFolder;
198 $this->set_total($post_type);
199 return ($this->total - $fileInFolder);
200 }//end if
201
202 return null;
203
204 }//end un_categorized_items()
205
206
207 /**
208 * Check the items in taxonomies
209 *
210 * @since 1.0.0
211 * @access public
212 * @return $counter
213 */
214 public function all_categorized_items($post_type)
215 {
216 if ($this->active) {
217 $this->set_total($post_type);
218 return $this->total;
219 }
220
221 return null;
222
223 }//end all_categorized_items()
224
225
226 }//end class
227
228 if (class_exists('WCP_Folder_PolyLang')) {
229 $WCP_Folder_PolyLang = new WCP_Folder_PolyLang();
230 }
231