/** * Processes a bulk action * * @uses activate_snippet() To activate snippets * @uses deactivate_snippet() To deactivate snippets * @uses delete_snippet() To delete snippets * @uses export_snippets() To export selected snippets * @uses wp_redirect() To pass the results to the current page * @uses add_query_arg() To append the results to the current URI */ function process_bulk_actions() { $network = get_current_screen()->is_network; if (isset($_GET['action'], $_GET['id'])) { $id = absint($_GET['id']); $action = sanitize_key($_GET['action']); $_SERVER['REQUEST_URI'] = remove_query_arg(array('action', 'id')); if ('activate' === $action) { activate_snippet($id, $network); } elseif ('deactivate' === $action) { deactivate_snippet($id, $network); } elseif ('delete' === $action) { delete_snippet($id, $network); } elseif ('export' === $action) { export_snippets($id, $network); } elseif ('export-php' === $action) { export_snippets($id, $network, 'php'); } if (!in_array($action, array('export', 'export-php'))) { wp_redirect(apply_filters("code_snippets/{$action}_redirect", esc_url_raw(add_query_arg($action, true)))); } } if (!isset($_POST['ids'])) { return; } $ids = $_POST['ids']; $_SERVER['REQUEST_URI'] = remove_query_arg(array('activate', 'deactivate', 'delete', 'activate-multi', 'deactivate-multi', 'delete-multi')); switch ($this->current_action()) { case 'activate-selected': foreach ($ids as $id) { activate_snippet($id, $network); } wp_redirect(esc_url_raw(add_query_arg('activate-multi', true))); break; case 'deactivate-selected': foreach ($ids as $id) { deactivate_snippet($id, $network); } wp_redirect(esc_url_raw(add_query_arg('deactivate-multi', true))); break; case 'export-selected': export_snippets($ids, $network); break; case 'export-php-selected': export_snippets($ids, $network, 'php'); break; case 'delete-selected': foreach ($ids as $id) { delete_snippet($id, $network); } wp_redirect(esc_url_raw(add_query_arg('delete-multi', true))); break; case 'clear-recent-list': if ($network) { update_site_option('recently_activated_snippets', array()); } else { update_option('recently_activated_snippets', array()); } break; } }
/** * Processes a bulk action * * @uses activate_snippet() to activate snippets * @uses deactivate_snippet() to deactivate snippets * @uses delete_snippet() to delete snippets * @uses export_snippets() to export selected snippets * @uses wp_redirect() to pass the results to the current page * @uses add_query_arg() to append the results to the current URI */ public function process_bulk_actions() { if (isset($_GET['action'], $_GET['id'])) { $id = absint($_GET['id']); $action = sanitize_key($_GET['action']); $_SERVER['REQUEST_URI'] = remove_query_arg(array('action', 'id')); if ('activate' === $action) { activate_snippet($id, $this->is_network); $result = 'activated'; } elseif ('deactivate' === $action) { deactivate_snippet($id, $this->is_network); $result = 'deactivated'; } elseif ('activate-shared' === $action) { $active_shared_snippets = get_option('active_shared_network_snippets', array()); if (!in_array($id, $active_shared_snippets)) { $active_shared_snippets[] = $id; update_option('active_shared_network_snippets', $active_shared_snippets); } $result = 'activated'; } elseif ('deactivate-shared' === $action) { $active_shared_snippets = get_option('active_shared_network_snippets', array()); update_option('active_shared_network_snippets', array_diff($active_shared_snippets, array($id))); $result = 'deactivated'; } elseif ('delete' === $action) { delete_snippet($id, $this->is_network); $result = 'deleted'; } elseif ('export' === $action) { export_snippets(array($id), $this->is_network); } elseif ('export-php' === $action) { export_snippets(array($id), $this->is_network, 'php'); } if (isset($result)) { wp_redirect(esc_url_raw(add_query_arg('result', $result))); exit; } } if (!isset($_POST['ids']) && !isset($_POST['shared_ids'])) { return; } $ids = isset($_POST['ids']) ? $_POST['ids'] : array(); $_SERVER['REQUEST_URI'] = remove_query_arg('action'); switch ($this->current_action()) { case 'activate-selected': foreach ($ids as $id) { activate_snippet($id, $this->is_network); } /* Process the shared network snippets */ if (isset($_POST['shared_ids']) && is_multisite() && !$this->is_network) { $active_shared_snippets = get_option('active_shared_network_snippets', array()); foreach ($_POST['shared_ids'] as $id) { if (!in_array($id, $active_shared_snippets)) { $active_shared_snippets[] = $id; } } update_option('active_shared_network_snippets', $active_shared_snippets); } wp_redirect(esc_url_raw(add_query_arg('result', 'activated-multi'))); exit; case 'deactivate-selected': foreach ($ids as $id) { deactivate_snippet($id, $this->is_network); } /* Process the shared network snippets */ if (isset($_POST['shared_ids']) && is_multisite() && !$this->is_network) { $active_shared_snippets = get_option('active_shared_network_snippets', array()); $active_shared_snippets = array_diff($active_shared_snippets, $_POST['shared_ids']); update_option('active_shared_network_snippets', ${$active_shared_snippets}); } wp_redirect(esc_url_raw(add_query_arg('result', 'deactivated-multi'))); exit; case 'export-selected': export_snippets($ids, $this->is_network); break; case 'export-php-selected': export_snippets($ids, $this->is_network, 'php'); break; case 'delete-selected': foreach ($ids as $id) { delete_snippet($id, $this->is_network); } wp_redirect(esc_url_raw(add_query_arg('result', 'deleted-multi'))); exit; case 'clear-recent-list': if ($this->is_network) { update_site_option('recently_activated_snippets', array()); } else { update_option('recently_activated_snippets', array()); } break; } }