public function ajax_response() { if (!check_ajax_referer($this->plugin_name . '_import', false, false) || !current_user_can('edit_theme_options')) { wp_send_json_error(array('msg' => '<p>Insufficient user rights.</p>')); } if (empty($_POST['dummy'])) { wp_send_json_error(array('msg' => '<p>Unable to find dummy content.</p>')); } $plugin_path = plugin_dir_path(dirname(__FILE__)) . '/includes/dummy-content/' . $this->theme_name . '/'; $dummy_content_obj = new DT_Dummy_Content($this->get_dummy_list(), $this->theme_name); $content_part_id = empty($_POST['content_part_id']) ? '0' : sanitize_key($_POST['content_part_id']); $dummy_content = array_merge($dummy_content_obj->get_main_content($content_part_id)->as_array(), $dummy_content_obj->get_wc_content($content_part_id)->as_array()); $msg = ''; foreach (explode(',', $_POST['dummy']) as $dummy_id) { $dummy_id = sanitize_key($dummy_id); if (!array_key_exists($dummy_id, $dummy_content)) { continue; } $import_options = array(); if (isset($dummy_content[$dummy_id]['replace_attachments'])) { $import_options['replace_attachments'] = $dummy_content[$dummy_id]['replace_attachments']; } $file_name = $plugin_path . $dummy_content[$dummy_id]['file_name']; ob_start(); $this->import_file($file_name, $import_options); $errors = ob_get_clean(); $msg .= '<p>' . $errors . dt_dummy_get_content_nice_name($dummy_id, $dummy_content[$dummy_id]) . ' ' . __('dummy content was imported.', $this->plugin_name) . '</p>'; } wp_send_json_success(array('msg' => $msg)); }
echo dt_dummy_get_content_nice_name($dummy_id, $dummy); ?> </label> <?php } ?> </div> <?php } ?> <?php $wc_content = $dummy_content->get_wc_content($content_part_id); ?> <?php if ($this->wc_is_enabled() && !$wc_content->is_empty()) { ?> <div class="dt-dummy-controls-block"> <h4><?php _e('Woocommerce content:', $this->plugin_name); ?> </h4> <?php foreach ($wc_content->as_array() as $dummy_id => $dummy) { ?>
public function ajax_response() { if (empty($_POST['dummy'])) { echo 'Unable to find dummy content.'; exit; } $plugin_path = plugin_dir_path(dirname(__FILE__)) . '/includes/dummy-content/' . $this->theme_name . '/'; $dummy_content_obj = new DT_Dummy_Content($this->get_dummy_list(), $this->theme_name); $content_part_id = empty($_POST['content_part_id']) ? '0' : sanitize_key($_POST['content_part_id']); $dummy_content = array_merge($dummy_content_obj->get_main_content($content_part_id)->as_array(), $dummy_content_obj->get_wc_content($content_part_id)->as_array()); foreach (explode(',', $_POST['dummy']) as $dummy_id) { $dummy_id = sanitize_key($dummy_id); if (!array_key_exists($dummy_id, $dummy_content)) { continue; } $import_options = array(); if (isset($dummy_content[$dummy_id]['replace_attachments'])) { $import_options['replace_attachments'] = $dummy_content[$dummy_id]['replace_attachments']; } $file_name = $plugin_path . $dummy_content[$dummy_id]['file_name']; $this->import_file($file_name, $import_options); echo '<p>' . dt_dummy_get_content_nice_name($dummy_id, $dummy_content[$dummy_id]) . ' ' . __('dummy content was imported.', $this->plugin_name) . '</p>'; } exit; }