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