PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.9.15
Shortcodes and extra features for Phlox theme v2.9.15
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 4 years ago compatibility 4 years ago metaboxes 4 years ago admin-ajax.php 4 years ago admin-hooks.php 4 years ago admin-the-functions.php 4 years ago index.php 5 years ago
admin-the-functions.php
340 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 $template_ID = sanitize_text_field( trim( $template_ID ) );
176 $template_type = sanitize_text_field( trim( $template_type ) );
177
178 if ( empty( $template_ID ) || empty( $template_type ) )
179 return [
180 'success' => false,
181 'data' => [
182 'message' => __( 'Template ID or type is required.', 'auxin-elements')
183 ]
184 ];
185
186 $template_imported_id_key = false;
187 if ( is_numeric( $template_ID ) ) {
188 // Get All Templates data
189 $templates_data = Auxin_Welcome::get_instance()->get_demo_list('templates');
190
191 if ( empty( $templates_data ) ) {
192 return [
193 'success' => false,
194 'data' => [
195 'message' => __( "An error occurred while updating templates library.", 'auxin-elements' )
196 ]
197 ];
198 }
199
200 // Find data of selected template
201 $has_template = false;
202 foreach ( $templates_data['templates'] as $key => $template_info ) {
203 if ( $template_info['id'] == $template_ID && $template_info['type'] == $template_type ) {
204 $has_template = true;
205 $template = $template_info;
206 break;
207 }
208 }
209
210 if ( ! $has_template ){
211 return [
212 'success' => false,
213 'data' => [
214 'message' => __( 'Template Not Found.', 'auxin-elements' )
215 ]
216 ];
217 }
218
219 // Import Template
220 $template_data_key = sanitize_key( "auxin_template_kit_{$template_type}_data_for_origin_id_{$template_ID}" );
221 $template_imported_id_key = sanitize_key( "auxin_template_kit_new_id_for_origin_{$template_ID}" );
222
223 $template_imported_new_id = auxin_get_transient( $template_imported_id_key );
224
225 // Check if the template is already imported and was not deleted
226 if ( false !== $template_imported_new_id && ! in_array( get_post_status( $template_imported_new_id ), [ false, 'trash' ] ) ) {
227 return [
228 'success' => true,
229 'data' => [
230 'message' => __( 'Template is already imported.', 'auxin-elements' ),
231 'data' => false,
232 'isImported' => true,
233 ]
234 ];
235 }
236
237 if( false === $template_data = auxin_get_transient( $template_data_key ) ){
238
239 // Retrieve the template data
240 $template_data = Auxin_Demo_Importer::get_instance()->fetch_template_data( $template_ID );
241
242 if( ! $template_data ){
243 return [
244 'success' => false,
245 'data' => [
246 'message' => __( 'Connection error, please check your connection.', 'auxin-elements' )
247 ]
248 ];
249 }
250
251 // Set transient for 48h
252 auxin_set_transient( $template_data_key, $template_data, WEEK_IN_SECONDS );
253 }
254 } elseif ( file_exists( $template_ID ) ) {
255 $template_data = file_get_contents( $template_ID );
256 $template = [
257 'title' => basename( $template_ID, '.json' )
258 ];
259 } else {
260 return [
261 'success' => false,
262 'data' => [
263 'message' => __( 'Template ID must be numeric or valid filepath.', 'auxin-elements')
264 ]
265 ];
266 }
267
268
269 $post_type = "elementor_library";
270 $args = [
271 'post_title' => wp_strip_all_tags( $template['title'] ),
272 'post_status' => 'publish',
273 'post_type' => $post_type
274 ];
275
276 // Inserting template into database
277 $post_id = wp_insert_post( $args );
278
279 if( ! is_wp_error( $post_id ) ){
280
281 // update menu name to use menu created by user
282 if ( $action == 'update_menu' ) {
283 if ( has_nav_menu('header-primary') && $template_type == 'header'){
284 $location = 'header-primary';
285 } else if ( has_nav_menu('footer') && $template_type == 'footer' ){
286 $location = 'footer';
287 } else {
288 $location = '';
289 }
290
291 $header_menu = ( ! empty( $location ) ) ? get_term( get_nav_menu_locations()[$location], 'nav_menu' ) : '';
292 $template_data = ( ! empty( $header_menu ) ) ? preg_replace( '#"menu_slug":".+?(?=")"#', '"menu_slug":"'.$header_menu->name.'"', $template_data ) : $template_data;
293 }
294
295 $json_content = json_decode( $template_data , true );
296 $elementor_version = defined( 'ELEMENTOR_VERSION' ) ? ELEMENTOR_VERSION : '2.9.0';
297
298 update_post_meta( $post_id, '_elementor_edit_mode', 'builder' );
299 update_post_meta( $post_id, '_elementor_data', $json_content['content'] );
300 update_post_meta( $post_id, '_elementor_version', $elementor_version );
301
302 // Set page template
303 if( ! empty( $template['page_tmpl'] ) ){
304 update_post_meta( $post_id, '_wp_page_template', $template['page_tmpl'] );
305 }
306
307 // Set template type
308 if( $post_type === 'elementor_library' ) {
309 update_post_meta( $post_id, '_elementor_template_type', $template_type );
310 }
311
312 if ( $template_imported_id_key ) {
313 auxin_set_transient( $template_imported_id_key, $post_id, MONTH_IN_SECONDS );
314 }
315
316 // Force to generate CSS file for this template
317 Auxin_Demo_Importer::get_instance()->maybe_flush_post( $post_id );
318
319 // NOTE: Here we can set new header or footer template az main header or footer
320 return [
321 'success' => true,
322 'data' => [
323 'message' => __( 'Template Imported Successfully', 'auxin-elements'),
324 'postId' => $post_id,
325 'isImported' => false,
326 'postTitle' => get_the_title( $post_id )
327 ]
328 ];
329
330 } else {
331
332 return [
333 'success' => false,
334 'data' => [
335 'message' => __( 'Error while saving the template.', 'auxin-elements')
336 ]
337 ];
338 }
339 }
340 }