function et_fb_get_saved_templates() { if (!wp_verify_nonce($_POST['et_fb_retrieve_library_modules_nonce'], 'et_fb_retrieve_library_modules_nonce')) { die(-1); } if (!current_user_can('edit_posts')) { die(-1); } $layout_type = !empty($_POST['et_layout_type']) ? sanitize_text_field($_POST['et_layout_type']) : 'layout'; $module_width = !empty($_POST['et_module_width']) && 'module' === $layout_type ? sanitize_text_field($_POST['et_module_width']) : ''; $is_global = !empty($_POST['et_is_global']) ? sanitize_text_field($_POST['et_is_global']) : 'all'; $specialty_query = !empty($_POST['et_specialty_columns']) && 'row' === $layout_type ? sanitize_text_field($_POST['et_specialty_columns']) : '0'; $post_type = !empty($_POST['et_post_type']) ? sanitize_text_field($_POST['et_post_type']) : 'post'; $start_from = !empty($_POST['et_templates_start_page']) ? sanitize_text_field($_POST['et_templates_start_page']) : 0; if ('all' === $is_global) { $templates_data_regular = et_pb_retrieve_templates($layout_type, $module_width, 'not_global', $specialty_query, $post_type, '', array($start_from, 25)); $templates_data_global = et_pb_retrieve_templates($layout_type, $module_width, 'global', $specialty_query, $post_type, '', array($start_from, 25)); $templates_data = array_merge($templates_data_regular, $templates_data_global); } else { $templates_data = et_pb_retrieve_templates($layout_type, $module_width, $is_global, $specialty_query, $post_type, array($start_from, 50)); } $templates_data_processed = $templates_data; $next_page = 'none'; if (0 !== $start_from && empty($templates_data)) { $templates_data_processed = array(); } else { if (empty($templates_data)) { $templates_data_processed = array('error' => esc_html__('You have not saved any items to your Divi Library yet. Once an item has been saved to your library, it will appear here for easy use.', 'et_builder')); } else { foreach ($templates_data as $index => $data) { $templates_data_processed[$index]['shortcode'] = et_fb_process_shortcode($data['shortcode']); } $next_page = 'all' === $is_global ? $start_from + 25 : $start_from + 50; } } $json_templates = json_encode(array('templates_data' => $templates_data_processed, 'next_page' => $next_page)); die($json_templates); }
/** * Retrieve and process saved Layouts. * It different than the function which retrieves saved Sections, Rows and Modules from library because layouts require different processing * * @return array */ function et_fb_get_saved_layouts() { if (!wp_verify_nonce($_POST['et_fb_retrieve_library_modules_nonce'], 'et_fb_retrieve_library_modules_nonce')) { die(-1); } if (!current_user_can('edit_posts')) { die(-1); } $post_type = !empty($_POST['et_post_type']) ? sanitize_text_field($_POST['et_post_type']) : 'post'; $layouts_type = !empty($_POST['et_load_layouts_type']) ? sanitize_text_field($_POST['et_load_layouts_type']) : 'all'; $start_from = !empty($_POST['et_templates_start_page']) ? sanitize_text_field($_POST['et_templates_start_page']) : 0; $post_type = apply_filters('et_pb_show_all_layouts_built_for_post_type', $post_type, $layouts_type); $all_layouts_data = et_pb_retrieve_templates('layout', '', 'false', '0', $post_type, $layouts_type, array($start_from, 50)); $all_layouts_data_processed = $all_layouts_data; $next_page = 'none'; if (0 !== $start_from && empty($all_layouts_data)) { $all_layouts_data_processed = array(); } else { if (empty($all_layouts_data)) { $all_layouts_data_processed = array('error' => esc_html__('You have not saved any items to your Divi Library yet. Once an item has been saved to your library, it will appear here for easy use.', 'et_builder')); } else { foreach ($all_layouts_data as $index => $data) { $all_layouts_data_processed[$index]['shortcode'] = et_fb_process_shortcode($data['shortcode']); } $next_page = $start_from + 50; } } $json_templates = json_encode(array('templates_data' => $all_layouts_data_processed, 'next_page' => $next_page)); die($json_templates); }