* @author ThemePunch <info@themepunch.com>
* @link https://www.themepunch.com/
* @copyright 2024 ThemePunch
if(!defined('ABSPATH')) exit();
class RevSliderFolder extends RevSliderSlider {
* Initialize A slider as a Folder
public function init_folder_by_id($id){
$folder = $wpdb->get_row($wpdb->prepare("SELECT * FROM ". $wpdb->prefix . RevSliderFront::TABLE_SLIDER ." WHERE `id` = %s AND `type` = 'folder'", $id), ARRAY_A);
$this->id = $this->get_val($folder, 'id');
$this->title = $this->get_val($folder, 'title');
$this->alias = $this->get_val($folder, 'alias');
$this->settings = (array)json_decode($this->get_val($folder, 'settings', ''));
$this->params = (array)json_decode($this->get_val($folder, 'params', ''));
* Get all Folders from the Slider Table
public function get_folders(){
$entries = $wpdb->get_results("SELECT `id` FROM ". $wpdb->prefix . RevSliderFront::TABLE_SLIDER ." WHERE `type` = 'folder'", ARRAY_A);
foreach($entries as $folder){
$slider = new RevSliderFolder();
$folder_id = $this->get_val($folder, 'id');
$slider->init_folder_by_id($folder_id);
* Get all Folders from the Slider Table
public function get_folder_by_id($id){
$folder = $wpdb->get_row($wpdb->prepare("SELECT * FROM ". $wpdb->prefix . RevSliderFront::TABLE_SLIDER ." WHERE `type` = 'folder' AND `id` = %s", $id), ARRAY_A);
* Create a new Slider as a Folder
public function create_folder($alias = 'New Folder', $parent = 0){
$title = esc_html($alias);
$alias = sanitize_title($title);
while($this->alias_exists($alias)){ //set a new alias and title if its existing in database
$title = $temp . ' ' . $ti;
$alias = sanitize_title($title);
//check if Slider with title and/or alias exists, if yes change both to stay unique
$done = $wpdb->insert($wpdb->prefix . RevSliderFront::TABLE_SLIDER, array('title' => $title, 'alias' => $alias, 'type' => 'folder'));
$this->init_folder_by_id($wpdb->insert_id);
$slider = new RevSliderFolder();
$slider->init_folder_by_id($parent);
$children = $slider->get_children();
$children = (!is_array($children)) ? array() : $children;
$children[] = $this->get_id();
$slider->add_slider_to_folder($children, $parent);
* Add a Slider ID to a Folder
public function add_slider_to_folder($children, $folder_id, $replace_all = true){
$folder = $wpdb->get_row($wpdb->prepare("SELECT * FROM ". $wpdb->prefix . RevSliderFront::TABLE_SLIDER ." WHERE `id` = %s AND `type` = 'folder'", $folder_id), ARRAY_A);
$settings = json_decode($this->get_val($folder, 'settings'), true);
if(!isset($settings['children'])){
$settings['children'] = array();
$settings['children'] = $children;
$children = (array)$children;
foreach($children as $child){
if(!in_array($child, $settings['children'])){
$settings['children'][] = $child;
$response = $wpdb->update($wpdb->prefix . RevSliderFront::TABLE_SLIDER, array('settings' => json_encode($settings)), array('id' => $folder_id));
$response = ($response == false && empty($wpdb->last_error)) ? true : $response;
* Get the Children of the folder (if any exist)
public function get_children(){
return $this->get_val($this->settings, 'children', array());
* Get the Children of the folder (if any exist)
public function set_children($children){
return $this->set_val($this->settings, 'children', $children);