PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.9
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.9
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 3 years ago class-review-box.php 3 years ago class-upgrade-box.php 3 years ago class-wpml.php 3 years ago folders.class.php 3 years ago form.class.php 3 years ago media.replace.php 3 years ago plugins.class.php 3 years ago tree.class.php 3 years ago
class-polylang.php
232 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 $this->delete_process_id = null;
58 add_action("admin_init", [$this, 'init']);
59
60 }//end __construct()
61
62
63 /**
64 * Filters the taxonomy data
65 *
66 * @since 1.0.0
67 * @access public
68 * @return
69 */
70 public function init()
71 {
72 global $wpdb, $polylang;
73 $this->active = function_exists("pll_get_post_translations");
74
75 if ($this->active) {
76 if (isset($polylang->curlang) && is_object($polylang->curlang)) {
77 $this->poly_lang_term_taxonomy_id = $polylang->curlang->term_taxonomy_id;
78
79 add_filter('premio_folder_item_in_taxonomy', [$this, 'items_in_taxonomy'], 10, 2);
80 add_filter('premio_folder_un_categorized_items', [$this, 'un_categorized_items'], 10, 2);
81 add_filter('premio_folder_all_categorized_items', [$this, 'all_categorized_items'], 10, 2);
82 }
83 }
84
85 }//end init()
86
87
88 /**
89 * Get total number on taxonomies used in Polylang
90 *
91 * @since 1.0.0
92 * @access public
93 * @return $total
94 */
95 public function set_total($post_type)
96 {
97 if ($this->active) {
98 $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'";
99 if ($post_type != 'attachment') {
100 $where = "post_status != 'trash'";
101 }
102
103 global $wpdb;
104 $query = "SELECT COUNT(tmp.ID) FROM
105 (
106 SELECT posts.ID
107 FROM {$wpdb->posts} AS posts
108 LEFT JOIN {$wpdb->term_relationships} AS trs
109 ON posts.ID = trs.object_id
110 LEFT JOIN {$wpdb->postmeta} AS postmeta
111 ON (posts.ID = postmeta.post_id AND postmeta.meta_key = '_wp_attached_file')
112 WHERE posts.post_type = '%s'
113 AND trs.term_taxonomy_id IN (%s)
114 AND ({$where})
115 GROUP BY posts.ID
116 ) as tmp";
117 $query = $wpdb->prepare($query, [$post_type, $this->poly_lang_term_taxonomy_id]);
118 $this->total = (int) $wpdb->get_var($query);
119 }//end if
120
121 }//end set_total()
122
123
124 /**
125 * Check the items in taxonomies
126 *
127 * @since 1.0.0
128 * @access public
129 * @return $counter
130 */
131 public function items_in_taxonomy($term_id, $arg=[])
132 {
133 if ($this->active) {
134 $post_type = isset($arg['post_type']) ? $arg['post_type'] : "";
135 $taxonomy = isset($arg['taxonomy']) ? $arg['taxonomy'] : "";
136 $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'";
137 if ($post_type != 'attachment') {
138 $where = "post_status != 'trash'";
139 }
140
141 global $wpdb;
142 $term_taxonomy_id = get_term_by('id', (int) $term_id, $taxonomy, OBJECT)->term_taxonomy_id;
143 $query = "SELECT COUNT(tmp.ID) FROM
144 (
145 SELECT posts.ID FROM {$wpdb->posts} AS posts
146 LEFT JOIN {$wpdb->term_relationships} AS tr1
147 ON (posts.ID = tr1.object_id)
148 INNER JOIN {$wpdb->term_relationships} AS tr2
149 ON (posts.ID = tr2.object_id and tr2.term_taxonomy_id IN (%s))
150 LEFT JOIN {$wpdb->postmeta} AS postmeta ON ( posts.ID = postmeta.post_id AND postmeta.meta_key = '_wp_attached_file' )
151 WHERE (tr1.term_taxonomy_id IN (%s))
152 AND posts.post_type = '%s'
153 AND (({$where}))
154 GROUP BY posts.ID
155 ) as tmp";
156 $query = $wpdb->prepare($query, [$term_taxonomy_id, $this->poly_lang_term_taxonomy_id, $post_type]);
157 $counter = (int) $wpdb->get_var($query);
158 return $counter ? $counter : 0;
159 }//end if
160
161 return null;
162
163 }//end items_in_taxonomy()
164
165
166 /**
167 * Check the items in uncategorized taxonomies
168 *
169 * @since 1.0.0
170 * @access public
171 * @return $counter
172 */
173 public function un_categorized_items($post_type, $taxonomy)
174 {
175 if ($this->active) {
176 global $wpdb;
177 $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'";
178 if ($post_type != 'attachment') {
179 $where = "post_status != 'trash'";
180 }
181
182 $query = "SELECT COUNT(tmp.ID) FROM
183 (
184 SELECT posts.ID
185 FROM {$wpdb->posts} AS posts
186 INNER JOIN {$wpdb->term_relationships} AS tr1
187 ON posts.ID = tr1.object_id AND tr1.term_taxonomy_id IN (%s)
188 INNER JOIN {$wpdb->term_relationships} AS tr2
189 ON (tr2.object_id = posts.ID)
190 JOIN {$wpdb->term_taxonomy} as tx
191 ON tx.term_taxonomy_id = tr2.term_taxonomy_id AND tx.taxonomy = '%s'
192 WHERE posts.post_type = '%s'
193 AND ({$where})
194 GROUP BY posts.ID
195 ) as tmp";
196 $query = $wpdb->prepare($query, [$this->poly_lang_term_taxonomy_id, $taxonomy, $post_type]);
197 $fileInFolder = (int) $wpdb->get_var($query);
198 $fileInFolder = !($fileInFolder) ? 0 : $fileInFolder;
199 $this->set_total($post_type);
200 return ($this->total - $fileInFolder);
201 }//end if
202
203 return null;
204
205 }//end un_categorized_items()
206
207
208 /**
209 * Check the items in taxonomies
210 *
211 * @since 1.0.0
212 * @access public
213 * @return $counter
214 */
215 public function all_categorized_items($post_type)
216 {
217 if ($this->active) {
218 $this->set_total($post_type);
219 return $this->total;
220 }
221
222 return null;
223
224 }//end all_categorized_items()
225
226
227 }//end class
228
229 if (class_exists('WCP_Folder_PolyLang')) {
230 $WCP_Folder_PolyLang = new WCP_Folder_PolyLang();
231 }
232