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-wpml.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-wpml.php
280 lines
1 <?php
2 /**
3 * Class Folders WPML
4 *
5 * @author : Premio <contact@premio.io>
6 * @license : GPL2
7 * */
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 class WCP_Folder_WPML
14 {
15
16 /**
17 * The Name of this plugin.
18 *
19 * @var string $isWPMLActive The Name of this plugin.
20 * @since 1.0.0
21 * @access private
22 */
23 private $isWPMLActive;
24
25 /**
26 * The Name of this plugin.
27 *
28 * @var string $total Total number of taxonomies
29 * @since 1.0.0
30 * @access private
31 */
32 private $total;
33
34 /**
35 * The Name of this plugin.
36 *
37 * @var string $lang Current Selected language
38 * @since 1.0.0
39 * @access private
40 */
41 private $lang;
42
43 /**
44 * The Name of this plugin.
45 *
46 * @var string $tableIclTranslations WPML translation table
47 * @since 1.0.0
48 * @access private
49 */
50 private $tableIclTranslations;
51
52 /**
53 * The Name of this plugin.
54 *
55 * @var string $tableIclTranslations WPML translated post
56 * @since 1.0.0
57 * @access protected
58 */
59 protected $post_translations;
60
61 /**
62 * The Name of this plugin.
63 *
64 * @var string $sitepress sitepress
65 * @since 1.0.0
66 * @access protected
67 */
68 private $sitepress;
69
70 /**
71 * The Name of this plugin.
72 *
73 * @var string $sitepress WPML Settings
74 * @since 1.0.0
75 * @access protected
76 */
77 private $settings;
78
79
80 /**
81 * Define the core functionality of the plugin.
82 *
83 * Set the WPML installation status and settings.
84 * Load the dependencies, define the locale, and set the hooks for the admin area and
85 * the public-facing side of the site.
86 *
87 * @since 1.0.0
88 */
89 public function __construct()
90 {
91 $this->isWPMLActive = false;
92 $this->total = 0;
93 add_action("admin_init", [$this, 'init']);
94
95 }//end __construct()
96
97
98 /**
99 * Check for the WPML settings and status
100 *
101 * @since 1.0.0
102 * @access public
103 * @return $isWPMLActive
104 */
105 public function init()
106 {
107 global $sitepress, $wpdb;
108 $isWPMLActive = $sitepress !== null && get_class($sitepress) === "SitePress";
109
110 if ($isWPMLActive) {
111 $settings = $sitepress->get_setting('custom_posts_sync_option', []);
112 if ($sitepress->get_current_language() !== 'all') {
113 $this->isWPMLActive = true;
114 $this->settings = $settings;
115 $this->lang = $sitepress->get_current_language();
116 $this->tableIclTranslations = $wpdb->prefix.'icl_translations';
117 }
118
119 $this->sitepress = $sitepress;
120 $this->post_translations = $sitepress->post_translations();
121
122 $user_id = get_current_user_id();
123
124 $current = apply_filters('wpml_current_language', null);
125 $previous = get_user_meta($user_id, '_icl_admin_language_last', true);
126 $previous = $previous ? $previous : 'all';
127 $current = $current ? $current : 'all';
128
129 if ($previous !== $current) {
130 delete_transient("premio_folders_without_trash");
131 update_user_meta($user_id, '_icl_admin_language_last', $current);
132 }
133 }
134
135 if ($this->isWPMLActive) {
136 add_filter('premio_folder_item_in_taxonomy', [$this, 'items_in_taxonomy'], 10, 2);
137 add_filter('premio_folder_un_categorized_items', [$this, 'un_categorized_items'], 10, 2);
138 add_filter('premio_folder_all_categorized_items', [$this, 'all_categorized_items'], 10, 2);
139 }
140
141 }//end init()
142
143
144 /**
145 * Get the total taxonomies used in WPML
146 *
147 * @since 1.0.0
148 * @access public
149 * @return $total
150 */
151 public function set_total($post_type)
152 {
153 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
154 global $wpdb;
155 $select = "SELECT COUNT(DISTINCT(P.id))
156 FROM {$this->tableIclTranslations} AS wpmlt
157 INNER JOIN {$wpdb->posts} AS P ON P.id = wpmlt.element_id";
158 $where = ["wpmlt.element_type = 'post_".esc_attr($post_type)."'"];
159 $where[] = "wpmlt.language_code = '%s'";
160 if ($post_type == 'attachment') {
161 $where[] = " (P.post_status = 'inherit' OR P.post_status = 'private')";
162 } else {
163 $where[] = " P.post_status != 'trash'";
164 }
165
166 $join = apply_filters( 'folders_count_join_query', "" );
167 $where = apply_filters( 'folders_count_where_query', $where );
168
169 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
170
171 $query = $wpdb->prepare($query, [$this->lang]);
172 $this->total = (int) $wpdb->get_var($query);
173 }
174
175 }//end set_total()
176
177
178 /**
179 * To get the items in taxonomies
180 *
181 * @since 1.0.0
182 * @access public
183 * @return $total
184 */
185 public function items_in_taxonomy($term_id, $arg=[])
186 {
187 $post_type = isset($arg['post_type']) ? $arg['post_type'] : "";
188 $taxonomy = isset($arg['taxonomy']) ? $arg['taxonomy'] : "";
189 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
190 global $wpdb;
191 $term_taxonomy_id = get_term_by('id', (int) $term_id, $taxonomy, OBJECT)->term_taxonomy_id;
192 $query = "SELECT count(wpmlt.element_id) as total_records FROM {$this->tableIclTranslations} AS wpmlt
193 INNER JOIN {$wpdb->term_relationships} AS term_rela ON term_rela.object_id = wpmlt.element_id
194 WHERE wpmlt.element_type = 'post_".esc_attr($post_type)."'
195 AND term_rela.term_taxonomy_id = '%s'
196 AND wpmlt.language_code = '%s'";
197
198 $query = $wpdb->prepare($query, [$term_taxonomy_id, $this->lang]);
199 $all_ids = $wpdb->get_var($query);
200
201 return !empty($all_ids) ? $all_ids : 0;
202 }//end if
203
204 return null;
205
206 }//end items_in_taxonomy()
207
208
209 /**
210 * To get the items in taxonomies in uncategorized
211 *
212 * @since 1.0.0
213 * @access public
214 * @return $total
215 */
216 public function un_categorized_items($post_type, $taxonomy)
217 {
218
219 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
220 global $wpdb;
221 $subQuery = "SELECT * FROM {$this->tableIclTranslations} as wpmlt
222 INNER JOIN {$wpdb->posts} as p on p.id = wpmlt.element_id
223 WHERE wpmlt.element_type = 'post_".esc_attr($post_type)."'
224 and wpmlt.language_code = '%s'";
225 $select = "SELECT COUNT(DISTINCT(tmp_table.ID))
226 FROM ({$subQuery}) as tmp_table";
227 $join = " JOIN {$wpdb->term_relationships} as term_relationships on tmp_table.element_id = term_relationships.object_id ";
228 $join .= " JOIN {$wpdb->term_taxonomy} as term_taxonomy on term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id ";
229 $where = ["taxonomy = '%s'"];
230
231 if ( $this->sitepress->is_translated_taxonomy( $taxonomy ) ) {
232 $icl_taxonomies = "tax_" . $taxonomy;
233 $join .= " LEFT JOIN {$wpdb->prefix}icl_translations AS icl_t
234 ON icl_t.element_id = term_taxonomy.term_taxonomy_id
235 AND icl_t.element_type = '{$icl_taxonomies}'";
236
237 $where[] = " ( ( icl_t.element_type = '{$icl_taxonomies}' AND icl_t.language_code = '{$this->lang}' )
238 OR icl_t.element_type != '{$icl_taxonomies}' OR icl_t.element_type IS NULL ) ";
239 }
240
241 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
242
243 $query = $wpdb->prepare($query, [$this->lang, $taxonomy]);
244 $fileInFolder = (int) $wpdb->get_var($query);
245
246 $this->set_total($post_type);
247
248 return ($this->total - $fileInFolder);
249 }
250
251 return null;
252
253 }//end un_categorized_items()
254
255
256 /**
257 * To get the items in taxonomies in all categories
258 *
259 * @since 1.0.0
260 * @access public
261 * @return $total
262 */
263 public function all_categorized_items($post_type)
264 {
265 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
266 $this->set_total($post_type);
267 return $this->total;
268 }
269
270 return null;
271
272 }//end all_categorized_items()
273
274
275 }//end class
276
277 if (class_exists('WCP_Folder_WPML')) {
278 $folder_WPML = new WCP_Folder_WPML();
279 }
280