PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.16.2
Shortcodes and extra features for Phlox theme v2.16.2
2.17.22 2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / admin / includes / admin-the-functions.php
auxin-elements / admin / includes Last commit date
classes 2 years ago compatibility 2 years ago metaboxes 2 years ago admin-ajax.php 2 years ago admin-hooks.php 3 years ago admin-the-functions.php 2 years ago index.php 2 years ago
admin-the-functions.php
371 lines
1 <?php
2 // admin related functions
3
4 // Include advanced metabox tab
5 require_once( 'metaboxes/metabox-fields-general-advanced.php' );
6
7
8 /**
9 * Searchs and removes unexpected fields and sections from metabox hub models
10 *
11 * @param array $models The list of metabox models
12 * @param array $args The metabox field and sections which should be dropped
13 * @return List of models
14 */
15 function auxin_remove_from_metabox_hub( $models, $args = array() ){
16
17 if( empty( $models ) ){
18 return;
19 }
20
21 $defaults = array(
22 'model_ids' => array(), // the list of model IDs to be dropped
23 'field_ids' => array() // the list of field IDs to be dropped
24 );
25
26 $args = wp_parse_args( $args, $defaults );
27
28 $args['model_ids' ] = (array) $args['model_ids'];
29 $args['field_ids' ] = (array) $args['field_ids'];
30
31 foreach ( $models as $model_info_index => $model_info ) {
32 // if similar field id detected, drop it
33 if( in_array( $model_info['model']->id, $args['model_ids' ] ) ){
34 unset( $models[ $model_info_index ] );
35 continue;
36 }
37
38 $fields = $model_info['model']->fields;
39
40 if( ! empty( $fields ) ){
41 foreach ( $fields as $field_index => $field ) {
42 if( empty( $field["id"] ) ){
43 continue;
44 }
45 if( in_array( $field["id"], $args['field_ids' ] ) ){
46 unset( $fields[ $field_index ] );
47 $models[ $model_info_index ]['model']->fields = $fields;
48 }
49 }
50 }
51 }
52
53 return $models;
54 }
55
56
57
58 /*----------------------------------------------------------------------------*/
59 /* TGMPA plugin update functions
60 /*----------------------------------------------------------------------------*/
61
62 /**
63 * Count the number of bundled plugins having new updates
64 *
65 * @return int|bool The umber of plugins having update
66 */
67 function auxin_count_bundled_plugins_have_update(){
68 // Check transient
69 if ( false === ( $tgmpa_counter = auxin_get_transient( 'auxin_count_bundled_plugins_have_update' ) ) ) {
70 // Get instance
71 $tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
72 // Reset Counter
73 $tgmpa_counter = 0;
74 // Check plugins list
75 foreach ( $tgmpa_instance->plugins as $slug => $plugin ) {
76 if ( $plugin['source_type'] === 'bundled' && $tgmpa_instance->is_plugin_active( $slug ) && $tgmpa_instance->does_plugin_have_update( $slug ) ) {
77 $tgmpa_counter++;
78 }
79 }
80 auxin_set_transient( 'auxin_count_bundled_plugins_have_update', $tgmpa_counter, 12 * HOUR_IN_SECONDS );
81 }
82
83 return $tgmpa_counter;
84 }
85
86 /**
87 * Get tgmpa install plugins page
88 */
89 function auxin_get_tgmpa_plugins_page(){
90 // Get instance
91 $tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
92 return $tgmpa_instance->install_plugins_page();
93 }
94
95 /**
96 * Get our custom updates list
97 *
98 * @return array
99 */
100 function auxin_get_update_list(){
101 // General objects
102 $bulk_list = new stdClass;
103 $last_checked = new stdClass;
104
105 // Get plugin updates info
106 $bulk_list->plugins = new stdClass;
107 $last_checked->plugins_time = 0;
108 if ( current_user_can( 'update_plugins' ) ) {
109 $update_plugins = auxin_get_transient( 'auxin_update_plugins' );
110 if ( isset( $update_plugins->response ) && ! empty( $update_plugins->response ) ){
111 $bulk_list->plugins = $update_plugins->response;
112 }
113 if( isset( $update_plugins->last_checked ) ){
114 $last_checked->plugins_time = $update_plugins->last_checked;
115 }
116 }
117
118 // Get theme updates info
119 $bulk_list->themes = new stdClass;
120 $last_checked->themes_time = 0;
121 if ( current_user_can( 'update_themes' ) ) {
122 $update_themes = auxin_get_transient( 'auxin_update_themes' );
123 if ( isset( $update_themes->response ) && ! empty( $update_themes->response ) ){
124 $bulk_list->themes = $update_themes->response;
125 }
126 if( isset( $update_themes->last_checked ) ){
127 $last_checked->themes_time = $update_themes->last_checked;
128 }
129 }
130
131 // Set last checked in human diff time
132 $get_last_checked_item = $last_checked->themes_time >= $last_checked->plugins_time ? $last_checked->themes_time : $last_checked->plugins_time;
133 $bulk_list->last_checked = $get_last_checked_item !== 0 ? human_time_diff( $get_last_checked_item ) : __( 'a long time', 'auxin-elements' );
134 // Set total updates count
135 $bulk_list->total_updates = count( (array) $bulk_list->plugins ) + count( (array) $bulk_list ->themes );
136
137 return apply_filters( 'auxin_get_total_updates_list', $bulk_list );
138 }
139
140 /**
141 * Get total updates number
142 *
143 * @return integer
144 */
145 function auxin_get_total_updates(){
146 $last_update = auxin_get_update_list();
147 return isset( $last_update->total_updates ) ? $last_update->total_updates : 0;
148 }
149
150 /**
151 * Set The Default Category for post type
152 *
153 * @return integer
154 */
155 function auxin_set_uncategorized_term ( $post_id, $post ) {
156 $taxonomies = get_object_taxonomies( $post->post_type );
157 foreach ( $taxonomies as $taxonomy ) {
158 if ( $taxonomy == 'language' || $taxonomy == 'post_translations' ) {
159 continue;
160 }
161 $terms = wp_get_post_terms( $post_id, $taxonomy );
162 if ( empty( $terms ) ) {
163 wp_set_object_terms( $post_id, 'uncategorized', $taxonomy );
164 }
165 }
166 }
167
168 /**
169 * Import requested template from server
170 *
171 */
172 if ( ! function_exists('auxin_template_importer') ) {
173 function auxin_template_importer( $template_ID = '', $template_type = '', $action = '' ) {
174
175 if ( ! user_can( wp_get_current_user(), 'manage_options' ) ) {
176 return [
177 'success' => false,
178 'data' => [
179 'message' => __( 'Sorry. You don\'t have sufficient permission to import a template!', 'auxin-elements')
180 ]
181 ];
182 }
183
184 $template_ID = sanitize_text_field( trim( $template_ID ) );
185 $template_type = sanitize_text_field( trim( $template_type ) );
186
187 if ( empty( $template_ID ) || empty( $template_type ) )
188 return [
189 'success' => false,
190 'data' => [
191 'message' => __( 'Template ID or type is required.', 'auxin-elements')
192 ]
193 ];
194
195 $template_imported_id_key = false;
196 if ( is_numeric( $template_ID ) ) {
197 // Get All Templates data
198 $templates_data = Auxin_Welcome::get_instance()->get_demo_list('templates');
199
200 if ( empty( $templates_data ) ) {
201 return [
202 'success' => false,
203 'data' => [
204 'message' => __( "An error occurred while updating templates library.", 'auxin-elements' )
205 ]
206 ];
207 }
208
209 // Find data of selected template
210 $has_template = false;
211 foreach ( $templates_data['templates'] as $key => $template_info ) {
212 if ( $template_info['id'] == $template_ID && $template_info['type'] == $template_type ) {
213 $has_template = true;
214 $template = $template_info;
215 break;
216 }
217 }
218
219 if ( ! $has_template ){
220 return [
221 'success' => false,
222 'data' => [
223 'message' => __( 'Template Not Found.', 'auxin-elements' )
224 ]
225 ];
226 }
227
228 // Import Template
229 $template_data_key = sanitize_key( "auxin_template_kit_{$template_type}_data_for_origin_id_{$template_ID}" );
230 $template_imported_id_key = sanitize_key( "auxin_template_kit_new_id_for_origin_{$template_ID}" );
231
232 $template_imported_new_id = auxin_get_transient( $template_imported_id_key );
233
234 // Check if the template is already imported and was not deleted
235 if ( false !== $template_imported_new_id && ! in_array( get_post_status( $template_imported_new_id ), [ false, 'trash' ] ) ) {
236 return [
237 'success' => true,
238 'data' => [
239 'message' => __( 'Template is already imported.', 'auxin-elements' ),
240 'data' => false,
241 'isImported' => true,
242 ]
243 ];
244 }
245
246 if( false === $template_data = auxin_get_transient( $template_data_key ) ){
247
248 // Retrieve the template data
249 $template_data = Auxin_Demo_Importer::get_instance()->fetch_template_data( $template_ID );
250
251 if( ! $template_data ){
252 return [
253 'success' => false,
254 'data' => [
255 'message' => __( 'Connection error, please check your connection.', 'auxin-elements' )
256 ]
257 ];
258 }
259
260 // Set transient for 48h
261 auxin_set_transient( $template_data_key, $template_data, WEEK_IN_SECONDS );
262 }
263 } elseif ( file_exists( $template_ID ) ) {
264 // make sure uploaded file has json extension
265 if( pathinfo( $template_ID, PATHINFO_EXTENSION) !== 'json' ){
266 return [
267 'success' => false,
268 'data' => [
269 'message' => __( 'Not a valid template file extension.', 'auxin-elements' )
270 ]
271 ];
272 }
273
274 // make sure uploaded file is JSON
275 $template_data = file_get_contents( $template_ID );
276 if ( ! auxin_is_json( $template_data ) ) {
277 return [
278 'success' => false,
279 'data' => [
280 'message' => __( 'Not a valid template file type.', 'auxin-elements' )
281 ]
282 ];
283 }
284
285 $template = [
286 'title' => basename( $template_ID, '.json' )
287 ];
288
289 } else {
290 return [
291 'success' => false,
292 'data' => [
293 'message' => __( 'Template ID must be numeric or valid filepath.', 'auxin-elements')
294 ]
295 ];
296 }
297
298
299 $post_type = "elementor_library";
300 $args = [
301 'post_title' => wp_strip_all_tags( $template['title'] ),
302 'post_status' => 'publish',
303 'post_type' => $post_type
304 ];
305
306 // Inserting template into database
307 $post_id = wp_insert_post( $args );
308
309 if( ! is_wp_error( $post_id ) ){
310
311 // update menu name to use menu created by user
312 if ( $action == 'update_menu' ) {
313 if ( has_nav_menu('header-primary') && $template_type == 'header'){
314 $location = 'header-primary';
315 } else if ( has_nav_menu('footer') && $template_type == 'footer' ){
316 $location = 'footer';
317 } else {
318 $location = '';
319 }
320
321 $header_menu = ( ! empty( $location ) ) ? get_term( get_nav_menu_locations()[$location], 'nav_menu' ) : '';
322 $template_data = ( ! empty( $header_menu ) ) ? preg_replace( '#"menu_slug":".+?(?=")"#', '"menu_slug":"'.$header_menu->name.'"', $template_data ) : $template_data;
323 }
324
325 $json_content = json_decode( $template_data , true );
326 $elementor_version = defined( 'ELEMENTOR_VERSION' ) ? ELEMENTOR_VERSION : '2.9.0';
327
328 update_post_meta( $post_id, '_elementor_edit_mode', 'builder' );
329 update_post_meta( $post_id, '_elementor_data', $json_content['content'] );
330 update_post_meta( $post_id, '_elementor_version', $elementor_version );
331
332 // Set page template
333 if( ! empty( $template['page_tmpl'] ) ){
334 update_post_meta( $post_id, '_wp_page_template', $template['page_tmpl'] );
335 }
336
337 // Set template type
338 if( $post_type === 'elementor_library' ) {
339 update_post_meta( $post_id, '_elementor_template_type', $template_type );
340 }
341
342 if ( $template_imported_id_key ) {
343 auxin_set_transient( $template_imported_id_key, $post_id, MONTH_IN_SECONDS );
344 }
345
346 // Force to generate CSS file for this template
347 Auxin_Demo_Importer::get_instance()->maybe_flush_post( $post_id );
348
349 // NOTE: Here we can set new header or footer template az main header or footer
350 return [
351 'success' => true,
352 'data' => [
353 'message' => __( 'Template Imported Successfully', 'auxin-elements'),
354 'postId' => $post_id,
355 'isImported' => false,
356 'postTitle' => get_the_title( $post_id )
357 ]
358 ];
359
360 } else {
361
362 return [
363 'success' => false,
364 'data' => [
365 'message' => __( 'Error while saving the template.', 'auxin-elements')
366 ]
367 ];
368 }
369 }
370 }
371