PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.5.0
Shortcodes and extra features for Phlox theme v2.5.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
311 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 // Find data of selected template
187 $has_template = false;
188 foreach ( $templates_data['templates'] as $key => $template_info ) {
189 if ( $template_info['id'] == $template_ID && $template_info['type'] == $template_type ) {
190 $has_template = true;
191 $template = $template_info;
192 break;
193 }
194 }
195
196 if ( ! $has_template ){
197 return [
198 'success' => false,
199 'data' => [
200 'message' => __( 'Template Not Found.', 'auxin-elements' )
201 ]
202 ];
203 }
204
205 // Import Template
206 $template_data_key = sanitize_key( "auxin_template_kit_{$template_type}_data_for_origin_id_{$template_ID}" );
207 $template_imported_id_key = sanitize_key( "auxin_template_kit_new_id_for_origin_{$template_ID}" );
208
209 $template_imported_new_id = auxin_get_transient( $template_imported_id_key );
210
211 // Check if the template is already imported and was not deleted
212 if ( false !== $template_imported_new_id && ! in_array( get_post_status( $template_imported_new_id ), [ false, 'trash' ] ) ) {
213 return [
214 'success' => true,
215 'data' => [
216 'message' => __( 'Template is already imported.', 'auxin-elements' ),
217 'data' => false,
218 'isImported' => true,
219 ]
220 ];
221 }
222
223 if( false === $template_data = auxin_get_transient( $template_data_key ) ){
224
225 // Retrieve the template data
226 $template_data = Auxin_Demo_Importer::get_instance()->fetch_template_data( $template_ID );
227
228 if( ! $template_data ){
229 return [
230 'success' => false,
231 'data' => [
232 'message' => __( 'Connection error, please check your connection.', 'auxin-elements' )
233 ]
234 ];
235 }
236
237 // Set transient for 48h
238 auxin_set_transient( $template_data_key, $template_data, WEEK_IN_SECONDS );
239 }
240
241
242 $post_type = "elementor_library";
243 $args = [
244 'post_title' => wp_strip_all_tags( $template['title'] ),
245 'post_status' => 'publish',
246 'post_type' => $post_type
247 ];
248
249 // Inserting template into database
250 $post_id = wp_insert_post( $args );
251
252 if( ! is_wp_error( $post_id ) ){
253
254 // update menu name to use menu created by user
255 if ( $action == 'update_menu' ) {
256 if ( has_nav_menu('header-primary') && $template_type == 'header'){
257 $location = 'header-primary';
258 } else if ( has_nav_menu('footer') && $template_type == 'footer' ){
259 $location = 'footer';
260 } else {
261 $location = '';
262 }
263
264 $header_menu = ( ! empty( $location ) ) ? get_term( get_nav_menu_locations()[$location], 'nav_menu' ) : '';
265 $template_data = ( ! empty( $header_menu ) ) ? preg_replace( '#"menu_slug":".+?(?=")"#', '"menu_slug":"'.$header_menu->name.'"', $template_data ) : $template_data;
266 }
267
268 $json_content = json_decode( $template_data , true );
269 $elementor_version = defined( 'ELEMENTOR_VERSION' ) ? ELEMENTOR_VERSION : '2.9.0';
270
271 update_post_meta( $post_id, '_elementor_edit_mode', 'builder' );
272 update_post_meta( $post_id, '_elementor_data', $json_content['content'] );
273 update_post_meta( $post_id, '_elementor_version', $elementor_version );
274
275 // Set page template
276 if( ! empty( $template['page_tmpl'] ) ){
277 update_post_meta( $post_id, '_wp_page_template', $template['page_tmpl'] );
278 }
279
280 // Set template type
281 if( $post_type === 'elementor_library' ) {
282 update_post_meta( $post_id, '_elementor_template_type', $template_type );
283 }
284
285 auxin_set_transient( $template_imported_id_key, $post_id, MONTH_IN_SECONDS );
286
287 // Force to generate CSS file for this template
288 Auxin_Demo_Importer::get_instance()->maybe_flush_post( $post_id );
289
290 // NOTE: Here we can set new header or footer template az main header or footer
291 return [
292 'success' => true,
293 'data' => [
294 'message' => __( 'Template Imported Successfully', 'auxin-elements'),
295 'postId' => $post_id,
296 'isImported' => false,
297 'postTitle' => get_the_title( $post_id )
298 ]
299 ];
300
301 } else {
302
303 return [
304 'success' => false,
305 'data' => [
306 'message' => __( 'Error while saving the template.', 'auxin-elements')
307 ]
308 ];
309 }
310 }
311 }