Exemple #1
0
function ls_sliders_bulk_action()
{
    // Remove
    if ($_POST['action'] === 'remove') {
        if (!empty($_POST['sliders']) && is_array($_POST['sliders'])) {
            foreach ($_POST['sliders'] as $item) {
                LS_Sliders::remove(intval($item));
            }
            header('Location: admin.php?page=layerslider&message=removeSuccess');
            die;
        } else {
            header('Location: admin.php?page=layerslider&message=removeSelectError&error=1');
            die;
        }
    }
    // Delete
    if ($_POST['action'] === 'delete') {
        if (!empty($_POST['sliders']) && is_array($_POST['sliders'])) {
            foreach ($_POST['sliders'] as $item) {
                LS_Sliders::delete(intval($item));
            }
            header('Location: admin.php?page=layerslider&message=deleteSuccess');
            die;
        } else {
            header('Location: admin.php?page=layerslider&message=deleteSelectError&error=1');
            die;
        }
    }
    // Restore
    if ($_POST['action'] === 'restore') {
        if (!empty($_POST['sliders']) && is_array($_POST['sliders'])) {
            foreach ($_POST['sliders'] as $item) {
                LS_Sliders::restore(intval($item));
            }
            header('Location: admin.php?page=layerslider&message=restoreSuccess');
            die;
        } else {
            header('Location: admin.php?page=layerslider&message=restoreSelectError&error=1');
            die;
        }
    }
    // Merge
    if ($_POST['action'] === 'merge') {
        // Error check
        if (!isset($_POST['sliders'][1]) || !is_array($_POST['sliders'])) {
            header('Location: admin.php?page=layerslider&error=1&message=mergeSelectError');
            die;
        }
        if ($sliders = LS_Sliders::find($_POST['sliders'])) {
            foreach ($sliders as $key => $item) {
                // Get IDs
                $ids[] = '#' . $item['id'];
                // Merge slides
                if ($key === 0) {
                    $data = $item['data'];
                } else {
                    $data['layers'] = array_merge($data['layers'], $item['data']['layers']);
                }
            }
            // Save as new
            $name = 'Merged sliders of ' . implode(', ', $ids);
            $data['properties']['title'] = $name;
            LS_Sliders::add($name, $data);
        }
        header('Location: admin.php?page=layerslider&message=mergeSuccess');
        die;
    }
}
Exemple #2
0
function ls_sliders_bulk_action()
{
    // Remove
    if ($_POST['action'] === 'remove') {
        if (is_array($_POST['sliders']) && !empty($_POST['sliders'])) {
            foreach ($_POST['sliders'] as $item) {
                layerslider_removeslider($item);
            }
        }
        header('Location: admin.php?page=layerslider&message=removeSuccess');
        die;
    }
    // Delete
    if ($_POST['action'] === 'delete') {
        if (is_array($_POST['sliders']) && !empty($_POST['sliders'])) {
            foreach ($_POST['sliders'] as $item) {
                LS_Sliders::delete($item);
            }
        }
        header('Location: admin.php?page=layerslider&message=removeSuccess');
        die;
    }
    // Restore
    if ($_POST['action'] === 'restore') {
        if (is_array($_POST['sliders']) && !empty($_POST['sliders'])) {
            foreach ($_POST['sliders'] as $item) {
                LS_Sliders::restore($item);
            }
        }
        header('Location: admin.php?page=layerslider&message=removeSuccess');
        die;
    }
    // Merge
    if ($_POST['action'] === 'merge') {
        // Error check
        if (!isset($_POST['sliders'][1]) || !is_array($_POST['sliders'])) {
            header('Location: admin.php?page=layerslider&error=1&message=mergeSelectError');
            die;
        }
        // Vars
        global $wpdb;
        $ids = array();
        $slider = array();
        // Iterate over the sliders
        foreach ($_POST['sliders'] as $key => $item) {
            $ids[] = '#' . $item;
            $data = lsSliderById($item);
            if ($key === 0) {
                $slider = $data['data'];
            } else {
                $slider['layers'] = array_merge($slider['layers'], $data['data']['layers']);
            }
        }
        // DB data
        $name = esc_sql($slider['properties']['title'] = 'Merged sliders of ' . implode(', ', $ids));
        $data = esc_sql(json_encode($slider));
        // Save as new slider
        $table_name = $wpdb->prefix . LS_DB_TABLE;
        $wpdb->query("INSERT INTO {$table_name} (name, data, date_c, date_m) VALUES ('{$name}', '{$data}', '" . time() . "', '" . time() . "')");
        header('Location: admin.php?page=layerslider&message=mergeSuccess');
        die;
    }
}