/**
 * Trash a reply
 *
 * @since 3.3
 *
 * @param $data
 *
 * @return void
 */
function wpas_admin_action_set_products_option($data)
{
    if (!is_admin()) {
        return;
    }
    if (!isset($data['products'])) {
        return;
    }
    $products = $data['products'];
    $redirect_to = remove_query_arg(array('wpas-do', 'wpas-do-nonce', 'products'), wpas_get_current_admin_url());
    // Delete the option that triggers the products setting notice
    delete_option('wpas_support_products');
    // If the user needs multiple products we need to update the plugin options
    if ('multiple' === $products) {
        $options = maybe_unserialize(get_option('wpas_options'));
        $options['support_products'] = '1';
        update_option('wpas_options', serialize($options));
        // We redirect to the products taxonomy screen
        $redirect_to = add_query_arg(array('taxonomy' => 'product', 'post_type' => 'ticket'), admin_url('edit-tags.php'));
    }
    wp_redirect(wp_sanitize_redirect($redirect_to));
    exit;
}
Esempio n. 2
0
 /**
  * Execute plugin custom actions.
  *
  * Any custom actions the plugin can trigger through a URL variable
  * will be executed here. It is all triggered by the var wpas-do.
  *
  * @since 3.0.0
  */
 public function custom_actions()
 {
     /* Make sure we have a trigger */
     if (!isset($_GET['wpas-do'])) {
         return;
     }
     /* Validate the nonce */
     if (!isset($_GET['wpas-nonce']) || !wp_verify_nonce($_GET['wpas-nonce'], 'wpas_custom_action')) {
         return;
     }
     $log = array();
     $action = sanitize_text_field($_GET['wpas-do']);
     switch ($action) {
         case 'close':
             if (isset($_GET['post']) && 'ticket' == get_post_type(intval($_GET['post']))) {
                 $url = add_query_arg(array('post' => $_GET['post'], 'action' => 'edit', 'wpas-message' => 'closed'), admin_url('post.php'));
                 wpas_close_ticket($_GET['post']);
             }
             break;
         case 'open':
             if (isset($_GET['post']) && 'ticket' == get_post_type(intval($_GET['post']))) {
                 $url = add_query_arg(array('post' => $_GET['post'], 'action' => 'edit', 'wpas-message' => 'opened'), admin_url('post.php'));
                 wpas_reopen_ticket($_GET['post']);
             }
             break;
         case 'trash_reply':
             if (isset($_GET['del_id']) && current_user_can('delete_reply')) {
                 $del_id = intval($_GET['del_id']);
                 /* Trash the post */
                 wp_trash_post($del_id, false);
                 /* Redirect with clean URL */
                 $url = wp_sanitize_redirect(add_query_arg(array('post' => $_GET['post'], 'action' => 'edit'), admin_url('post.php') . "#wpas-post-{$del_id}"));
                 wpas_redirect('trashed_reply', $url);
                 exit;
             }
             break;
         case 'multiple-products':
             $options = maybe_unserialize(get_option('wpas_options'));
             $options['support_products'] = '1';
             update_option('wpas_options', serialize($options));
             delete_option('wpas_support_products');
             wpas_redirect('enable_multiple_products', add_query_arg(array('taxonomy' => 'product', 'post_type' => 'ticket'), admin_url('edit-tags.php')));
             exit;
             break;
         case 'single-product':
             delete_option('wpas_support_products');
             wpas_redirect('enable_single_product', remove_query_arg(array('wpas-nonce', 'wpas-do'), wpas_get_current_admin_url()));
             exit;
             break;
     }
     /**
      * wpas_custom_actions hook
      *
      * Fired right after the action is executed. It is important to note that
      * some of the action are triggering a redirect after they're done and
      * that in this case this hook won't be triggered.
      *
      * @param string $action The action that's being executed
      */
     do_action('wpas_execute_custom_action', $action);
     /* Log the action */
     if (!empty($log)) {
         wpas_log($_GET['post'], $log);
     }
     /* Get URL vars */
     $args = $_GET;
     /* Remove custom action and nonce */
     unset($_GET['wpas-do']);
     unset($_GET['wpas-nonce']);
     /* Read-only redirect */
     wpas_redirect('read_only', $url);
     exit;
 }