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