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