/** * Process the uploaded import file * * @uses import_snippets() to process the import file * @uses wp_redirect() to pass the import results to the page * @uses add_query_arg() to append the results to the current URI */ private function process_import_file() { /* Ensure the import file exists */ if (!isset($_FILES['code_snippets_import_file']['tmp_name'])) { return; } /* Import the snippets */ $result = import_snippets($_FILES['code_snippets_import_file']['tmp_name'], $network); /* Send the amount of imported snippets to the page */ $url = add_query_arg($result ? array('imported' => count($result)) : array('error' => true)); wp_redirect(esc_url_raw($url)); exit; }
/** * Processes import files and loads the help tabs for the Import Snippets page * * @since 1.3 * * @uses import_snippets() To process the import file * @uses wp_redirect() To pass the import results to the page * @uses add_query_arg() To append the results to the current URI */ function code_snippets_load_import_menu() { $network = get_current_screen()->is_network; /* Make sure the user has permission to be here */ if (!current_user_can(get_snippets_cap())) { wp_die(__('You are not access this page.', 'code-snippets')); } /* Create the snippet tables if they don't exist */ create_code_snippets_tables(); /* Process import files */ if (isset($_FILES['code_snippets_import_file']['tmp_name'])) { /* Import the snippets. The result is the number of snippets that were imported */ $result = import_snippets($_FILES['code_snippets_import_file']['tmp_name'], $network); /* Send the amount of imported snippets to the page */ $url = add_query_arg(false === $result ? array('error' => true) : array('imported' => $result)); wp_redirect(esc_url_raw($url)); } /* Load the screen help tabs */ require plugin_dir_path(__FILE__) . 'admin-help.php'; }