'650', 'version' => $sldr_plugin_info['Version'] ); } /* Add slider to global $bws_shortcode_list */ $bws_shortcode_list['sldr'] = array( 'name' => 'Slider', 'js_function' => 'sldr_shortcode_init' ); } } /** * Add localization. */ if ( ! function_exists( 'sldr_plugins_loaded' ) ) { function sldr_plugins_loaded() { /* Internationalization */ load_plugin_textdomain( 'slider-bws', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } } /** * Register settings. */ if ( ! function_exists( 'sldr_settings' ) ) { function sldr_settings() { global $sldr_options, $sldr_plugin_info; $plugin_db_version = '0.1'; /* Install the option defaults. */ if ( ! get_option( 'sldr_options' ) ) { $option_defaults = sldr_get_options_default(); add_option( 'sldr_options', $option_defaults ); } /* Get options from the database. */ $sldr_options = get_option( 'sldr_options' ); if ( ! isset( $sldr_options['plugin_option_version'] ) || $sldr_options['plugin_option_version'] != $sldr_plugin_info['Version'] ) { $option_defaults = sldr_get_options_default(); $sldr_options = array_merge( $option_defaults, $sldr_options ); $sldr_options['plugin_option_version'] = $sldr_plugin_info['Version']; $update_option = true; } /** * Update pugin database and options */ if ( ! isset( $sldr_options['plugin_db_version'] ) || $sldr_options['plugin_db_version'] != $plugin_db_version ) { sldr_create_table(); $sldr_options['plugin_db_version'] = $plugin_db_version; $update_option = true; } if ( isset( $update_option ) ) { update_option( 'sldr_options', $sldr_options ); } } } /** * Get Plugin default options */ if ( ! function_exists( 'sldr_get_options_default' ) ) { function sldr_get_options_default() { global $sldr_plugin_info; $option_defaults = array( /* internal general */ 'plugin_option_version' => $sldr_plugin_info["Version"], 'first_install' => strtotime( "now" ), 'suggest_feature_banner' => 1, 'display_settings_notice' => 1, /* general */ 'loop' => false, 'nav' => false, 'dots' => false, 'items' => '1', 'autoplay' => false, 'autoplay_timeout' => '2000', 'autoplay_hover_pause' => false, 'lazy_load' => false, 'auto_height' => '1', 'order_by' => 'meta_value_num', 'order' => 'ASC', 'bws_booking' => 0, 'display_in_front_page' => 0 ); return $option_defaults; } } /** * Function for plugin activation. */ if ( ! function_exists( 'sldr_plugin_activate' ) ) { function sldr_plugin_activate() { global $wpdb; if ( function_exists( 'is_multisite' ) && is_multisite() ) { $old_blog = $wpdb->blogid; /* Get all blog ids */ $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); foreach ( $blogids as $blog_id ) { switch_to_blog( $blog_id ); register_uninstall_hook( __FILE__, 'sldr_plugin_uninstall' ); restore_current_blog(); } switch_to_blog( $old_blog ); return; } register_uninstall_hook( __FILE__, 'sldr_plugin_uninstall' ); } } /** * Function to create a new tables in database. */ if ( ! function_exists( 'sldr_create_table' ) ) { function sldr_create_table() { global $wpdb; /* Require db Delta */ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); /* Create table for sliders */ $sql = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "sldr_slider` ( `slider_id` INT NOT NULL AUTO_INCREMENT, `datetime` DATE NOT NULL, `title` VARCHAR( 255 ) NOT NULL, `settings` BLOB NOT NULL, PRIMARY KEY (slider_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; /* Call dbDelta */ dbDelta( $sql ); /* Create table for sliders category */ $sql = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "sldr_category` ( `category_id` INT NOT NULL AUTO_INCREMENT, `title` VARCHAR( 255 ) NOT NULL, PRIMARY KEY (category_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; /* Call dbDelta */ dbDelta( $sql ); /* Create table for slides */ $sql = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "sldr_slide` ( `slide_id` INT NOT NULL AUTO_INCREMENT, `attachment_id` INT NOT NULL, `title` VARCHAR( 255 ) NOT NULL, `description` VARCHAR( 255 ) NOT NULL, `url` VARCHAR( 255 ) NOT NULL, `button` VARCHAR( 255 ) NOT NULL, `order` INT NOT NULL, PRIMARY KEY (slide_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; /* Call dbDelta */ dbDelta( $sql ); /* create table for sliders meta */ $sql = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "sldr_relation` ( `id` INT NOT NULL AUTO_INCREMENT, `slider_id` INT NOT NULL, `attachment_id` INT, `category_id` INT, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; /* Call dbDelta */ dbDelta( $sql ); } } /* Function create filter for custom slides sorting */ if ( ! function_exists( 'sldr_edit_attachment_join' ) ) { function sldr_edit_attachment_join( $join_paged_statement ) { global $wpdb; $join_paged_statement = "LEFT JOIN `" . $wpdb->prefix . "sldr_slide` ON `" . $wpdb->prefix . "sldr_slide`.`attachment_id` = `" . $wpdb->prefix . "posts`.`ID`"; return $join_paged_statement; } } /* Function create filter for custom slides sorting */ if ( ! function_exists( 'sldr_edit_attachment_orderby' ) ) { function sldr_edit_attachment_orderby( $orderby_statement ) { global $wpdb; $orderby_statement = "( `" . $wpdb->prefix . "sldr_slide`.order ) ASC"; return $orderby_statement; } } /** * Extends WP_List_Table and WP_Media_List_Table classes. */ if ( ! class_exists( 'WP_List_Table' ) ) { require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); } if ( ! class_exists( 'WP_Media_List_Table' ) ) { require_once( ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php' ); } if ( ! class_exists( 'Sldr_List_Table' ) ) { /* WP_List_Table extends for render of slider table */ class Sldr_List_Table extends WP_List_Table { /* Declare constructor */ function __construct() { parent::__construct( array( 'singular' => __( 'slider', 'slider-bws' ), 'plural' => __( 'sliders', 'slider-bws' ), ) ); } /** * Declare column renderer * * @param $item - row (key, value array) * @param $column_name - string (key) * @return HTML */ function column_default( $item, $column_name ) { global $wpdb; /* Get array of sliders image */ $slider_attachment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `attachment_id` FROM `" . $wpdb->prefix . "sldr_relation` WHERE `attachment_id` IS NOT NULL AND `slider_id` = %d", $item['slider_id'] ) ); $slider_attachment_ids = array_map( 'esc_attr', $slider_attachment_ids ); switch ( $column_name ) { case 'thumbnail': /* Thumbnail is first sliders picture */ $thumbnail = wp_get_attachment_image( array_shift( $slider_attachment_ids ), array( 100, 100 ) ) ; if ( ! empty( $thumbnail ) ) { echo '' . $thumbnail . ''; } break; case 'shortcode': bws_shortcode_output( '[print_sldr id=' . $item['slider_id'] . ']' ); break; case 'images_count': if ( ! empty( $slider_attachment_ids ) ) { echo count( $slider_attachment_ids ); } else { echo '0'; } break; case 'category': /* Get category list for slider with current ID in table. */ $slider_current_categories_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `category_id` FROM `" . $wpdb->prefix . "sldr_relation` WHERE `slider_id` = %d", $item['slider_id'] ) ); $slider_current_categories_ids = array_map( 'esc_attr', $slider_current_categories_ids ); /* Get category title for selected category ID. */ $slider_category_title_array = array(); foreach ( $slider_current_categories_ids as $slider_current_categories_id ) { if ( ! empty( $slider_current_categories_id ) ) { $slider_category_title = $wpdb->get_var( $wpdb->prepare( "SELECT `title` FROM `" . $wpdb->prefix . "sldr_category` WHERE `category_id` = %d", $slider_current_categories_id ) ); $slider_category_title_array[] = array ( 'id' => $slider_current_categories_id, 'title' => $slider_category_title ); } } unset( $slider_current_categories_id ); if ( ! empty( $slider_category_title_array ) ) { /* Display category with comma. */ foreach ( $slider_category_title_array as $slider_category ) { echo '' . $slider_category['title'] . '
'; } } else { echo '

'; } break; case 'datetime': echo str_replace ('-', '/' , $item[ $column_name ]); break; case 'title': return $item[ $column_name ]; break; default: return print_r( $item, true ) ; } } /** * Render column with actions * * @param $item - row (key, value array) * @return HTML */ function column_title( $item ) { $actions = array( 'edit' => sprintf( '%s', $item['slider_id'], __( 'Edit', 'slider-bws' ) ), 'delete' => sprintf( '%s', esc_html( $_REQUEST['page'] ), $item['slider_id'], __( 'Delete', 'slider-bws' ) ), ); $title = empty( $item['title'] ) ? '(' . __( 'no title', 'slider-bws' ) . ')' : $item['title']; return sprintf( '%s%s', $item['slider_id'], $title, $this->row_actions( $actions ) ); } /** * Checkbox column renders * * @param $item - row (key, value array) * @return HTML */ function column_cb( $item ) { return sprintf( '', $item['slider_id'] ); } /** * Return columns to display in table * * @return array */ function get_columns() { $columns = array( 'cb' => '', 'thumbnail' => __( 'Thumbnail', 'slider-bws' ), 'title' => __( 'Title', 'slider-bws' ), 'images_count' => __( 'Images', 'slider-bws' ), 'category' => __( 'Category', 'slider-bws' ), 'shortcode' => __( 'Shortcode', 'slider-bws' ), 'datetime' => __( 'Date', 'slider-bws' ) ); return $columns; } function no_items() { _e( 'No Sliders Found', 'slider-bws' ); } /* Generate the table navigation above or below the table */ function display_tablenav( $which ) { ?>
bulk_actions( $which ); ?>
extra_tablenav( $which ); $this->pagination( $which ); ?>
get_results( "SELECT `category_id`, `title` FROM `" . $wpdb->prefix . "sldr_category`", ARRAY_A ); /* Get selected category for current slider */ $slider_category_selected = isset( $_POST['sldr_cat_select'] ) ? intval( $_POST['sldr_cat_select'] ) : ''; ?>
__( 'Delete', 'slider-bws' ) ); return $actions; } /** * Processes bulk actions * */ function process_bulk_action() { global $wpdb; $slider_deleted_id = isset( $_REQUEST['sldr_id'] ) ? (array) $_REQUEST['sldr_id'] : array(); $slider_deleted_id = array_map( 'esc_attr', $slider_deleted_id ); if ( 'delete' === $this->current_action() ) { /* If deleted some slider */ if ( ! empty( $slider_deleted_id ) && is_array( $slider_deleted_id ) ) { /* If delete more 1 slider */ foreach ( $slider_deleted_id as $slider_id ) { $wpdb->delete( $wpdb->prefix . 'sldr_slider', array( 'slider_id' => $slider_id ) ); $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'slider_id' => $slider_id ) ); } } elseif ( ! empty( $slider_deleted_id ) ) { $wpdb->delete( $wpdb->prefix . 'sldr_slider', array( 'slider_id' => $slider_deleted_id ) ); $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'slider_id' => $slider_deleted_id ) ); } } } /** * Get rows from database and prepare them to be showed in table */ function prepare_items() { global $wpdb; $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); /* Configure table headers, defined in this methods */ $this->_column_headers = array( $columns, $hidden, $sortable, 'title' ); /* Process bulk action if any */ $this->process_bulk_action(); $per_page_option = get_current_screen()->get_option( 'per_page' ); $current_page = $this->get_pagenum(); /* Display selected category */ $search = ( isset( $_POST['s'] ) ) ? '%' . stripslashes( esc_html( $_POST['s'] ) ) . '%' : '%%'; if ( ! empty( $_POST['sldr_cat_select'] ) ) { /* Show sliders by selected category */ $slider_category = intval( $_POST['sldr_cat_select'] ); $per_page = $per_page_option['default']; /* Prepare query params, as usual current page, order by and order direction */ $paged = 0; /* Show selected slider categories */ $this->items = $wpdb->get_results( $wpdb->prepare( "SELECT `" . $wpdb->prefix . "sldr_slider`.`slider_id`, `" . $wpdb->prefix . "sldr_slider`.`title`, `" . $wpdb->prefix . "sldr_slider`.`datetime` FROM `" . $wpdb->prefix . "sldr_slider` INNER JOIN `" . $wpdb->prefix . "sldr_relation` WHERE `" . $wpdb->prefix . "sldr_slider`.`slider_id` = `" . $wpdb->prefix . "sldr_relation`.`slider_id` AND `" . $wpdb->prefix . "sldr_relation`.`category_id` = %d AND `" . $wpdb->prefix . "sldr_relation`.`attachment_id` IS NULL AND `" . $wpdb->prefix . "sldr_slider`.`title` LIKE %s LIMIT %d OFFSET %d", $slider_category, $search, $per_page, $paged ), ARRAY_A ); /* Will be used in pagination settings */ $total_items = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( `" . $wpdb->prefix . "sldr_slider`.`slider_id` ) FROM `" . $wpdb->prefix . "sldr_slider` INNER JOIN `" . $wpdb->prefix . "sldr_relation` WHERE `" . $wpdb->prefix . "sldr_slider`.`slider_id` = `" . $wpdb->prefix . "sldr_relation`.`slider_id` AND `" . $wpdb->prefix . "sldr_relation`.`category_id` = %d AND `" . $wpdb->prefix . "sldr_relation`.`attachment_id` IS NULL AND `" . $wpdb->prefix . "sldr_slider`.`title` LIKE %s", $slider_category, $search ) ); /* If no category selected, display all */ } else { /* Show all categories */ $per_page_query = get_user_meta( get_current_user_id(), $per_page_option['option'] ); $per_page_value = intval( implode( ',', $per_page_query ) ); $per_page = ! empty( $per_page_value ) ? $per_page_value : $per_page_option['default']; /* Prepare query params, as usual current page, order by and order direction */ $paged = isset( $_REQUEST['paged'] ) ? max( 0, intval( $_REQUEST['paged'] * $per_page ) - $per_page ) : 0; /* Will be used in pagination settings */ $total_items = $wpdb->get_var( "SELECT COUNT( slider_id ) FROM `" . $wpdb->prefix . "sldr_slider`" ); /* Show all slider categories */ $this->items = $wpdb->get_results( $wpdb->prepare( "SELECT `slider_id`, `title`, `datetime` FROM `" . $wpdb->prefix . "sldr_slider` WHERE `title` LIKE %s LIMIT %d OFFSET %d", $search, $per_page, $paged ), ARRAY_A ); } /* Сonfigure pagination */ $this->set_pagination_args( array( 'total_items' => intval( $total_items ), /* total items defined above */ 'per_page' => $per_page, /* per page constant defined at top of method */ 'total_pages' => ceil( $total_items / $per_page ) /* calculate pages count */ ) ); } } } if ( ! class_exists( 'Sldr_Category_List_Table' ) ) { /* WP_List_Table extends for render of slider categories */ class Sldr_Category_List_Table extends WP_List_Table { /** * Declare constructor */ function __construct() { parent::__construct( array( 'singular' => 'category', 'plural' => 'categories', ) ); } /** * Declare column renderer * * @param $item - row (key, value array) * @param $column_name - string (key) * @return HTML */ function column_default( $item, $column_name ) { global $wpdb; switch ( $column_name ) { case 'count': /* Count items with current category */ $sliders_with_current_category_count = intval( $wpdb->get_var( "SELECT COUNT( category_id ) FROM `" . $wpdb->prefix . "sldr_relation` WHERE `category_id` = '" . $item['category_id'] . "'" ) ); echo $sliders_with_current_category_count; break; case 'shortcode': bws_shortcode_output( '[print_sldr cat_id=' . $item['category_id'] . ']' ); break; case 'name': return $item['title']; default: return print_r( $item, true ) ; } } /** * Render column with actions, * when you hover row "Edit | Delete" links showed * * @param $item - row (key, value array) * @return HTML */ function column_name( $item ) { $actions = array( 'edit' => sprintf( '%s', $item['category_id'], __( 'Edit', 'slider-bws' ) ), 'delete' => sprintf( '%s', $item['category_id'], __( 'Delete', 'slider-bws' ) ), ); return sprintf( '%s%s', $item['category_id'], $item['title'], $this->row_actions( $actions ) ); } /** * Checkbox column renders * * @param $item - row (key, value array) * @return HTML */ function column_cb( $item ) { return sprintf( '', $item['category_id'] ); } /** * Return columns to display in table * * @return array */ function get_columns() { $columns = array( 'cb' => '', 'name' => __( 'Name', 'slider-bws' ), 'count' => __( 'Count', 'slider-bws' ), 'shortcode' => __( 'Shortcode', 'slider-bws' ), ); return $columns; } function no_items() { _e( 'No Categories Found', 'slider-bws' ); } /** * Return columns that may be used to sort table * * @return array */ function get_sortable_columns() { $sortable_columns = array( 'name' => array( 'name', true ), /* default sort */ ); return $sortable_columns; } /** * Return array of bulk actions if has any * * @return array */ function get_bulk_actions() { $actions = array( 'delete' => __( 'Delete', 'slider-bws') ); return $actions; } /** * Processes bulk actions * */ function process_bulk_action() { global $wpdb; $slider_category_deleted_id = isset( $_REQUEST['sldr_category_id'] ) ? (array) $_REQUEST['sldr_category_id'] : array(); $slider_category_deleted_id = array_map( 'esc_attr', $slider_category_deleted_id ); if ( 'delete' === $this->current_action() ) { /* If deleted more one category */ if ( ! empty( $slider_category_deleted_id ) && is_array( $slider_category_deleted_id ) ) { foreach ( $slider_category_deleted_id as $slider_deleted_id ) { $wpdb->delete( $wpdb->prefix . 'sldr_category', array( 'category_id' => $slider_deleted_id ) ); $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'category_id' => $slider_deleted_id ) ); } unset( $slider_deleted_id ); /* If deleted one category */ } elseif ( ! empty( $slider_category_deleted_id ) ) { $wpdb->delete( $wpdb->prefix . 'sldr_category', array( 'category_id' => $slider_category_deleted_id ) ); $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'category_id' => $slider_category_deleted_id ) ); } } } /** * Get rows from database and prepare them to be showed in table * */ function prepare_items() { global $wpdb; $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); /* Configure table headers, defined in this methods */ $this->_column_headers = array( $columns, $hidden, $sortable ); /* Process bulk action if any */ $this->process_bulk_action(); /* Pagination */ $per_page_option = get_current_screen()->get_option('per_page'); $current_page = $this->get_pagenum(); /* Prepare query params, as usual current page, order by and order direction */ $order = isset( $_REQUEST['order'] ) ? esc_html( $_REQUEST['order'] ) : 'asc'; /* Pagination */ $per_page_query = get_user_meta( get_current_user_id(), $per_page_option['option'] ); $per_page_value = intval( implode( ',', $per_page_query ) ); $per_page = ! empty( $per_page_value ) ? $per_page_value : $per_page_option['default']; $paged = isset( $_REQUEST['paged'] ) ? max( 0, intval( $_REQUEST['paged'] * $per_page ) - $per_page ) : 0; /* Search result for categories */ if ( isset( $_REQUEST['s'] ) ) { /* Get search query */ $cat_search_title = '%' . stripslashes( esc_html( $_REQUEST['s'] ) ) . '%'; /* Display total items for search results */ $total_items = count( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . $wpdb->prefix . "sldr_category` WHERE `title` LIKE %s", $cat_search_title ), ARRAY_A ) ); } else { /* If search query is empty, display all table content */ $cat_search_title = '%%'; /* Will be used in pagination settings */ $total_items = $wpdb->get_var( "SELECT COUNT( category_id ) FROM `" . $wpdb->prefix . "sldr_category`" ); } /* Define $items array */ /* notice that last argument is ARRAY_A, so we will retrieve array */ $this->items = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . $wpdb->prefix . "sldr_category` WHERE `title` LIKE %s ORDER BY `title` " . $order . " LIMIT %d OFFSET %d", $cat_search_title, $per_page, $paged ), ARRAY_A ); /* Сonfigure pagination */ $this->set_pagination_args( array( 'total_items' => intval( $total_items ), /* total items defined above */ 'per_page' => $per_page, /* per page constant defined at top of method */ ) ); } } } if ( ! class_exists( 'Sldr_Media_Table' ) ) { if ( ! class_exists( 'WP_List_Table' ) ) require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); if ( ! class_exists( 'WP_Media_List_Table' ) ) require_once( ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php' ); class Sldr_Media_Table extends WP_Media_List_Table { public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'media', 'screen' => isset( $args['screen'] ) ? $args['screen'] : '', ) ); } function no_items() { _e( 'No images found.', 'slider-bws' ); } function display_tablenav( $which ) { ?>
extra_tablenav( $which ); ?>
get_col( $wpdb->prepare( "SELECT `attachment_id` FROM `" . $wpdb->prefix . "sldr_relation` WHERE `attachment_id` IS NOT NULL AND `slider_id` = %d", $sldr_id ) ); if ( ! empty( $slider_attachment_ids ) ) { add_filter( 'posts_orderby', 'sldr_edit_attachment_orderby' ); add_filter( 'posts_join','sldr_edit_attachment_join' ); /* Loop for media items */ query_posts( array( 'order' => 'asc', 'post__in' => $slider_attachment_ids, 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'inherit' ) ); while ( have_posts() ) { the_post(); $this->single_row( $post ); } wp_reset_postdata(); wp_reset_query(); remove_filter( 'posts_orderby', 'sldr_edit_attachment_orderby' ); remove_filter( 'posts_join','sldr_edit_attachment_join' ); } } function get_views() { return false; } public function views() { ?>
get_row( $wpdb->prepare( "SELECT * FROM `" . $wpdb->prefix . "sldr_slide` WHERE `attachment_id` = %d", $post->ID ), ARRAY_A ); $attachment_metadata = wp_get_attachment_metadata( $post->ID ); $image_attributes_medium = wp_get_attachment_image_src( $post->ID, 'medium' ); $image_attributes_large = wp_get_attachment_image_src( $post->ID, 'large' ); ?>
  • post_title; ?>
    <?php echo $post->post_title; ?>
    : post_title; ?>
    : ID ); ?>
    : ×
    |
  • prepare_items(); $message = ''; ?>
    current_action() ) { $message = __( 'Slider deleted.', 'slider-bws' ); } ?>
    %s %s', esc_html__( 'Sliders', 'slider-bws' ), esc_url( admin_url( 'admin.php?page=slider-new.php' ) ), esc_html__( 'Add New', 'slider-bws' ) ); ?>
    >

    search_box( __( 'Search Sliders', 'slider-bws' ), 'sldr_slider' ); $slider_table->display(); ?>
    update( $wpdb->prefix . 'sldr_slider', array( 'title' => $slider_title, 'settings' => $sldr_options ), array( 'slider_id' => $sldr_id ) ); } else { $wpdb->insert( $wpdb->prefix . 'sldr_slider', array( 'title' => $slider_title, 'datetime' => date( 'Y-m-d' ), 'settings' => $sldr_options ) ); /* Get slider ID for new slider. */ $sldr_id = $wpdb->insert_id; } /* Slider category from category metabox. */ /* Get all categories list from hidden input */ $slider_all_category_ids = isset( $_POST['sldr_category_unchecked_id'] ) ? $_POST['sldr_category_unchecked_id'] : ""; /* Save slider category for current slider. */ if ( isset( $_POST['sldr_category_id'] ) ) { $slider_category_id = $_POST['sldr_category_id']; /* Add selected category to DB. */ foreach ( (array)$slider_all_category_ids as $slider_all_category_id ) { if ( ! in_array( $slider_all_category_id, $slider_category_id ) ) { $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'category_id' => $slider_all_category_id , 'slider_id' => $sldr_id ) ); } else { $wpdb->query( $wpdb->prepare( "INSERT INTO `" . $wpdb->prefix . "sldr_relation` ( `slider_id`, `category_id` ) SELECT * FROM (SELECT %d as `slider_id` , %d as `category_id` ) AS tmp WHERE NOT EXISTS ( SELECT `category_id` FROM `" . $wpdb->prefix . "sldr_relation` WHERE slider_id = %d AND category_id = %d ) LIMIT 1", $sldr_id, $slider_all_category_id, $sldr_id, $slider_all_category_id ) ); } } /* Delete selected category from DB. */ } elseif ( ! empty( $slider_all_category_ids ) ) { foreach ( (array)$slider_all_category_ids as $slider_all_category_id ) { $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'category_id' => $slider_all_category_id, 'slider_id' => $sldr_id ) ); } } /* Save adding image to DB. */ if ( isset( $_POST['sldr_new_image'] ) ) { $slider_new_attachments = $_POST['sldr_new_image']; /* Get added images. */ /* Add new image to slider images array. */ foreach ( $slider_new_attachments as $slider_new_attachment ) { /* If slide already exist in DB, don't insert slide */ $wpdb->query( $wpdb->prepare( "INSERT INTO `" . $wpdb->prefix . "sldr_relation` ( `slider_id`, `attachment_id` ) SELECT * FROM ( SELECT %d as `slider_id` , %d as `attachment_id` ) AS tmp WHERE NOT EXISTS ( SELECT `attachment_id` FROM `" . $wpdb->prefix . "sldr_relation` WHERE slider_id = %d AND attachment_id = %d ) LIMIT 1", $sldr_id, $slider_new_attachment, $sldr_id, $slider_new_attachment ) ); } } /* Slide title\description\URL */ if ( ! empty( $_POST['sldr_image_title'] ) ) { foreach ( $_POST['sldr_image_title' ] as $slider_attachment_id => $slider_attachment_title ) { /* Prepare data to save in DB */ $slider_attachment_title = htmlspecialchars( trim( wp_unslash( $slider_attachment_title ) ) ); $slider_attachment_description = esc_html( trim( wp_unslash( $_POST['sldr_image_description'][ $slider_attachment_id ] ) ) ); $slider_attachment_url = esc_url( trim( $_POST['sldr_link_url'][ $slider_attachment_id ] ) ); if ( filter_var( $slider_attachment_url, FILTER_VALIDATE_URL ) === FALSE ) { $slider_attachment_url = ''; } $slider_attachment_button_text = esc_html( trim( wp_unslash( $_POST['sldr_button_text'][ $slider_attachment_id ] ) ) ); /* Check: if data exist in DB, then update the data. If not exist, then insert the data */ $slide_id = $wpdb->get_var( $wpdb->prepare( "SELECT `slide_id` FROM `" . $wpdb->prefix . "sldr_slide` WHERE `attachment_id` = %d", $slider_attachment_id ) ); if ( ! empty( $slide_id ) ) { $wpdb->update( $wpdb->prefix . 'sldr_slide', array( 'title' => $slider_attachment_title, 'description' => $slider_attachment_description, 'url' => $slider_attachment_url, 'button' => $slider_attachment_button_text ), array( 'attachment_id' => $slider_attachment_id ) ); } else { $wpdb->insert( $wpdb->prefix . 'sldr_slide', array( 'title' => $slider_attachment_title, 'description' => $slider_attachment_description, 'url' => $slider_attachment_url, 'button' => $slider_attachment_button_text, 'attachment_id' => $slider_attachment_id ) ); } } } /* Slide order */ if ( isset( $_POST['_sldr_order'] ) ) { /* Set counter for slide order */ $i = 1; foreach ( $_POST['_sldr_order'] as $slider_attachment_order_id => $order_id ) { $wpdb->update( $wpdb->prefix . 'sldr_slide', array( 'order' => $i ), array( 'attachment_id' => $slider_attachment_order_id ) ); $i++; } } } return $sldr_id; } } /** * Function will render new slider page. */ if ( ! function_exists( 'sldr_add_new_render' ) ) { function sldr_add_new_render( $item ) { global $sldr_id, $wpdb, $post; $sldr_id = sldr_form_handler(); $plugin_basename = plugin_basename( __FILE__ ); $message = $error = ""; /* Add admin notice to slider menu. */ if ( isset( $_REQUEST['sldr_publish'] ) && check_admin_referer( $plugin_basename, 'sldr_nonce_form_name' ) ) { $message = __( 'Slider updated.', 'slider-bws' ); } ?>
    '. __( 'Edit Slider', 'slider-bws' ) . '' . __( 'Add New', 'slider-bws' ) . ''; } else { echo '

    '. __( 'Add New Slider', 'slider-bws' ) . '

    '; } ?>
    >

    prefix . "sldr_slider` WHERE `slider_id` = %d", $sldr_id ) ) ); ?>" id="title" spellcheck="true" autocomplete="off" type="text" placeholder="" />
    display_tabs(); ?>
    get_var( $wpdb->prepare( "SELECT `category_id` FROM `" . $wpdb->prefix . "sldr_category` WHERE `category_id` = %d", $id ) ); } /* Send data to DB */ if ( ! empty( $slider_get_category_id ) ) { $wpdb->update( $wpdb->prefix . 'sldr_category', array( 'title' => $slider_category_title ), array( 'category_id' => $id ) ); } else { $wpdb->insert( $wpdb->prefix . 'sldr_category', array( 'title' => $slider_category_title ) ); } } $message = __( 'Category updated.', 'slider-bws' ); } ?>
    get_var( $wpdb->prepare( "SELECT `title` FROM `" . $wpdb->prefix . "sldr_category` WHERE `category_id` = %d", $id ) ); ?>

    >

    >

    prepare_items(); $slider_categories_table->search_box( __( 'Search Slider Categories', 'slider-bws' ), 'sldr_categories' ); $slider_categories_table->display(); ?>

    get_results( "SELECT `category_id`, `title` FROM `" . $wpdb->prefix . "sldr_category`", ARRAY_A ); ?>
    +
    add_request_feature(); ?>

    display_content(); ?>
    '; $script = "( function ($) { $( '#tmpl-attachment-details' ).html( $( '#tmpl-attachment-details' ).html().replace( '
    post_mime_type ) || preg_match( '!^video/mp4!', $atachment_detail->post_mime_type ) || preg_match( '!^video/ogg!', $atachment_detail->post_mime_type ) || preg_match( '!^video/webm!', $atachment_detail->post_mime_type ) ) ) { $notice_attach = "
    " . __( 'Warning', 'slider-bws' ) . ": " . __( 'You can add only images or video (in format: MP4, WebM or Ogg) to the slider.', 'slider-bws' ) . "
    "; wp_send_json_success( $notice_attach ); } } } die(); } } /** * Delete slide by click on "Delete" button. */ if ( ! function_exists( 'sldr_delete_image' ) ) { function sldr_delete_image() { global $wpdb; check_ajax_referer( plugin_basename( __FILE__ ), 'sldr_ajax_nonce_field' ); $action = isset( $_POST['action'] ) ? esc_attr( $_POST['action'] ) : ""; $delete_id_array = isset( $_POST['delete_id_array'] ) ? $_POST['delete_id_array'] : ""; $slider_id = isset( $_POST['slider_id'] ) ? $_POST['slider_id'] : ""; if ( 'sldr_delete_image' == $action && ! empty( $delete_id_array ) && ! empty( $slider_id ) ) { $delete_ids = explode( ',', trim( $delete_id_array, ',' ) ); foreach ( $delete_ids as $delete_id ) { $wpdb->delete( $wpdb->prefix . 'sldr_relation', array( 'slider_id' => $slider_id, 'attachment_id' => $delete_id ) ); } echo 'updated'; }; die(); } } /** * Add new media in slider from AJAX. */ if ( ! function_exists( 'sldr_add_from_media' ) ) { function sldr_add_from_media() { check_ajax_referer( plugin_basename( __FILE__ ), 'sldr_ajax_add_nonce' ); $action = isset( $_POST['action'] ) ? $_POST['action'] : ""; $add_id = isset( $_POST['add_id'] ) ? intval( $_POST['add_id'] ) : ""; if ( 'sldr_add_from_media' == $action && ! empty( $add_id ) ) { $post = get_post( $add_id ); if ( ! empty( $post ) ) { if ( preg_match( '!^image/!', $post->post_mime_type ) || preg_match( '!^video/mp4!', $post->post_mime_type ) || preg_match( '!^video/ogg!', $post->post_mime_type ) || preg_match( '!^video/webm!', $post->post_mime_type ) ) { $GLOBALS['hook_suffix'] = 'slider'; $wp_slider_media_table = new Sldr_Media_Table(); $wp_slider_media_table->prepare_items(); $wp_slider_media_table->single_row( $post ); } } } die(); } } /** * Add slider shortcode to BWS plugin shortcode menu. */ if ( ! function_exists( 'sldr_shortcode_button_content' ) ) { function sldr_shortcode_button_content( $content ) { global $wpdb; ?> '', 'cat_id' => '' ), $attr ); extract( $shortcode_attributes ); ob_start(); if ( empty( $sldr_options ) ) { $sldr_options = get_option( 'sldr_options' ); } /* Get slider ID by categories*/ /* Check: if this category exists in DB */ $slider_category_id = $wpdb->get_var( $wpdb->prepare( "SELECT `category_id` FROM `" . $wpdb->prefix . "sldr_category` WHERE `category_id` = %d", $cat_id ) ); if ( ! empty( $cat_id ) && isset( $slider_category_id ) ) { $slider_categories_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `slider_id` FROM `" . $wpdb->prefix . "sldr_relation` WHERE `category_id` = %d", $cat_id ) ); } /* Get media ID for slider shortcode */ if ( ! empty( $id ) ) { $slider_attachment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `" . $wpdb->prefix . "sldr_slide`.`attachment_id` FROM `" . $wpdb->prefix . "sldr_relation` INNER JOIN `" . $wpdb->prefix . "sldr_slide` WHERE `" . $wpdb->prefix . "sldr_slide`.`attachment_id` = `" . $wpdb->prefix . "sldr_relation`.`attachment_id` AND `" . $wpdb->prefix . "sldr_relation`.`attachment_id` IS NOT NULL AND `" . $wpdb->prefix . "sldr_relation`.`slider_id` = %d ORDER BY `" . $wpdb->prefix . "sldr_slide`.`order` ASC", $id ) ); } /* Get slider settings */ $slider_single_setting = $wpdb->get_var( $wpdb->prepare( "SELECT `settings` FROM `" . $wpdb->prefix . "sldr_slider` WHERE `slider_id` = %d", $id ) ); $slider_single_settings = unserialize( $slider_single_setting ); /* Wrapper for the Booking search form */ if ( is_plugin_active( 'car-rental/car-rental.php' ) || is_plugin_active( 'car-rental-pro/car-rental-pro.php' ) ) { echo '
    '; } /* If this shortcode with slider ID */ if ( ! empty( $slider_attachment_ids ) ) { $script = "( function($) { $( document ).ready( function() { var slider_single_settings = '" . json_encode( $slider_single_settings ) . "'; slider_single_settings = JSON.parse( slider_single_settings ); var slider_options = '" . json_encode( $sldr_options ) . "'; slider_options = JSON.parse( slider_options ); var id = " . json_encode( $id ) . "; if ( $( 'body' ).hasClass( 'rtl' ) ) { $( '.sldr_carousel_' + id ).owlCarousel( { loop: slider_single_settings.loop, nav: slider_single_settings.nav, dots: slider_single_settings.dots, items: slider_single_settings.items, smartSpeed: 450, autoplay: slider_single_settings.autoplay, autoplayTimeout: slider_single_settings.autoplay_timeout, autoplayHoverPause: slider_single_settings.autoplay_hover_pause, center: true, lazyLoad: slider_options.lazy_load, autoHeight: slider_options.auto_height, navText:[ \"\", \"\" ], rtl: true } ); } else { $( '.sldr_carousel_' + id ).owlCarousel({ loop: slider_single_settings.loop, nav: slider_single_settings.nav, dots: slider_single_settings.dots, items: slider_single_settings.items, smartSpeed: 450, autoplay: slider_single_settings.autoplay, autoplayTimeout: slider_single_settings.autoplay_timeout, autoplayHoverPause: slider_single_settings.autoplay_hover_pause, center: true, lazyLoad: slider_options.lazy_load, autoHeight: slider_options.auto_height, navText:[ \"\", \"\" ] }); } }); }) (jQuery);"; wp_register_script( 'sldr_slider_settings_' . $id, '' ); wp_enqueue_script( 'sldr_slider_settings_' . $id ); wp_add_inline_script( 'sldr_slider_settings_' . $id, sprintf( $script ) ); /* Display images and images attributes from slider. */ echo '
    '; /* If this shortcode with slider category ID */ } elseif ( ! empty( $slider_categories_ids ) ) { /* Get slider settings */ $slider_category_setting = $wpdb->get_var( $wpdb->prepare( "SELECT `settings` FROM `" . $wpdb->prefix . "sldr_slider` WHERE `slider_id` = %d", $slider_categories_ids[0] ) ); /* Get options of first slider */ $slider_category_settings = unserialize( $slider_category_setting ); $script = "( function( $ ) { $( document ).ready( function() { var slider_options = '" . json_encode( $sldr_options ) . "'; slider_options = JSON.parse( slider_options ); var slider_category_settings = '" . json_encode( $slider_category_settings ) . "'; slider_category_settings = JSON.parse( slider_category_settings ); var cat_id = " . json_encode( $cat_id ) . "; $( '.sldr_cat_carousel_'+ cat_id ).find( '.owl-item' ); if ( $( 'body' ).hasClass( 'rtl' ) ) { $( '.sldr_cat_carousel_' + cat_id ).owlCarousel( { loop: slider_category_settings.loop, nav: slider_category_settings.nav, dots: slider_category_settings.dots, items: slider_category_settings.items, autoplay: slider_category_settings.autoplay, autoplayTimeout: slider_category_settings.autoplay_timeout, autoplayHoverPause: slider_category_settings.autoplay_hover_pause, center: true, smartSpeed: 450, lazyLoad: slider_options.lazy_load, autoHeight: slider_options.auto_height, navText:[ \"\", \"\" ], rtl: true } ); } else { $( '.sldr_cat_carousel_' + cat_id ).owlCarousel( { loop: slider_category_settings.loop, nav: slider_category_settings.nav, dots: slider_category_settings.dots, items: slider_category_settings.items, autoplay: slider_category_settings.autoplay, autoplayTimeout: slider_category_settings.autoplay_timeout, autoplayHoverPause: slider_category_settings.autoplay_hover_pause, center: true, smartSpeed: 450, lazyLoad: slider_options.lazy_load, autoHeight: slider_options.auto_height, navText:[ \"\", \"\" ] } ); } } ); } ) (jQuery);"; wp_register_script( 'sldr_slider_settings_category_' . $cat_id, '' ); wp_enqueue_script( 'sldr_slider_settings_category_' . $cat_id ); wp_add_inline_script( 'sldr_slider_settings_category_' . $cat_id, sprintf( $script ) ); echo '
    '; /* If nothing found. */ } else { echo '

    ' . __( 'Sorry, nothing found.', 'slider-bws' ) . '

    '; } $settings = ! empty( $slider_single_settings ) ? $slider_single_settings : ( ! empty( $slider_category_setting ) ? $slider_category_setting : false ); do_action( 'sldr_after_content', $shortcode_attributes, maybe_unserialize( $settings ) ); echo '
    '; if ( is_plugin_active( 'car-rental/car-rental.php' ) || is_plugin_active( 'car-rental-pro/car-rental-pro.php' ) ) { echo '
    '; /* end of .sldr_bkng_wrapper */ } $slider_output = ob_get_clean(); return $slider_output; } } /** * Add style to dashboard */ if ( ! function_exists ( 'sldr_admin_head' ) ) { function sldr_admin_head() { wp_enqueue_style( 'sldr_stylesheet_icon', plugins_url( '/css/style-icon.css', __FILE__ ) ); if ( isset( $_GET['page'] ) && $_GET['page'] == 'slider.php' ) { wp_enqueue_style( 'sldr_stylesheet', plugins_url( '/css/style.css', __FILE__ ) ); } else if ( isset( $_GET['page'] ) && $_GET['page'] == 'slider-new.php' ) { wp_enqueue_style( 'editor-buttons' ); wp_enqueue_style( 'sldr_stylesheet', plugins_url( '/css/style.css', __FILE__ ) ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_media(); add_thickbox(); wp_enqueue_script( 'sldr_script', plugins_url( 'js/admin-script.js', __FILE__ ), array( 'jquery' ) ); /* Plugin script */ wp_localize_script( 'sldr_script', 'sldr_vars', array( 'sldr_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'sldr_ajax_nonce_field' ), 'sldr_add_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'sldr_ajax_add_nonce' ), 'warnBulkDelete' => __( "You are about to remove these items from this slider.\n 'Cancel' to stop, 'OK' to delete.", 'slider-bws' ), 'warnSingleDelete' => __( "You are about to remove this item from the slider.\n 'Cancel' to stop, 'OK' to delete.", 'slider-bws' ), 'wp_media_title' => __( 'Insert Media', 'slider-bws' ), 'wp_media_button' => __( 'Insert', 'slider-bws' ), 'no_items' => __( 'No images found', 'slider-bws' ) ) ); bws_enqueue_settings_scripts(); } elseif ( isset( $_GET['page'] ) && $_GET['page'] == 'slider-settings.php' ) { bws_enqueue_settings_scripts(); bws_plugins_include_codemirror(); } } } /** * List of JavaScript / CSS files * @return void */ if ( ! function_exists( 'sldr_register_scripts' ) ) { function sldr_register_scripts() { /* Owl carousel style */ wp_enqueue_style( 'owl.carousel.css', plugins_url( '/css/owl.carousel.css', __FILE__ ) ); wp_enqueue_style( 'owl.theme.default.css', plugins_url( '/css/owl.theme.default.css', __FILE__ ) ); /* Include dashicons */ wp_enqueue_style( 'dashicons' ); /* Plugin style */ wp_enqueue_style( 'sldr_stylesheet', plugins_url( '/css/frontend_style.css', __FILE__ ) ); /* Include jquery */ wp_enqueue_script( 'jquery' ); /* Slider script */ wp_enqueue_script( 'owl.carousel.js', plugins_url( '/js/owl.carousel/owl.carousel.js', __FILE__ ) ); wp_enqueue_script( 'owl.animate.js', plugins_url( '/js/owl.carousel/owl.animate.js', __FILE__ ) ); wp_enqueue_script( 'owl.autoheight.js', plugins_url( '/js/owl.carousel/owl.autoheight.js', __FILE__ ) ); wp_enqueue_script( 'owl.autoplay.js', plugins_url( '/js/owl.carousel/owl.autoplay.js', __FILE__ ) ); wp_enqueue_script( 'owl.autorefresh.js', plugins_url( '/js/owl.carousel/owl.autorefresh.js', __FILE__ ) ); wp_enqueue_script( 'owl.hash.js', plugins_url( '/js/owl.carousel/owl.hash.js', __FILE__ ) ); wp_enqueue_script( 'owl.lazyload.js', plugins_url( '/js/owl.carousel/owl.lazyload.js', __FILE__ ) ); wp_enqueue_script( 'owl.navigation.js', plugins_url( '/js/owl.carousel/owl.navigation.js', __FILE__ ) ); wp_enqueue_script( 'owl.support.js', plugins_url( '/js/owl.carousel/owl.support.js', __FILE__ ) ); wp_enqueue_script( 'owl.video.js', plugins_url( '/js/owl.carousel/owl.video.js', __FILE__ ) ); /* Frontend script */ wp_enqueue_script( 'sldr_front_script', plugins_url( 'js/script.js', __FILE__ ) ); } } /** * Function to display table screen options. */ if ( ! function_exists ( 'sldr_cat_screen_options' ) ) { function sldr_cat_screen_options() { sldr_add_tabs(); $args = array( 'label' => __( 'Category per page', 'slider-bws' ), 'default' => 10, 'option' => 'sldr_cat_per_page', ); add_screen_option( 'per_page', $args ); } } if ( ! function_exists ( 'sldr_screen_options' ) ) { function sldr_screen_options() { sldr_add_tabs(); $args = array( 'label' => __( 'Sliders per page', 'slider-bws' ), 'default' => 10, 'option' => 'sldr_per_page', ); add_screen_option( 'per_page', $args ); } } /** * Function to set up table screen options. */ if ( ! function_exists ( 'sldr_set_screen_options' ) ) { function sldr_set_screen_options( $status, $option, $value ) { if ( 'sldr_cat_per_page' == $option || 'sldr_per_page' == $option ) { return $value; } return $status; } } /** * Add links to plugin. */ if ( ! function_exists( 'sldr_register_plugin_links' ) ) { function sldr_register_plugin_links( $links, $file ) { $base = plugin_basename( __FILE__ ); if ( $file == $base ) { $links[] = '' . __( 'Settings', 'slider-bws' ) . ''; $links[] = '' . __( 'FAQ', 'slider-bws' ) . ''; $links[] = '' . __( 'Support', 'slider-bws' ) . ''; } return $links; } } /** * Add links to plugin. */ if ( ! function_exists( 'sldr_plugin_action_links' ) ) { function sldr_plugin_action_links( $links, $file ) { /* Static so we don't call plugin_basename on every plugin row. */ static $this_plugin; if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ ); if ( $file == $this_plugin ) { $settings_link = '' . __( 'Settings', 'slider-bws' ) . ''; array_unshift( $links, $settings_link ); } return $links; } } /** * Add BWS notice to plugin page. */ if ( ! function_exists ( 'sldr_admin_notices' ) ) { function sldr_admin_notices() { global $hook_suffix, $sldr_plugin_info, $sldr_options; if ( 'plugins.php' == $hook_suffix || ( isset( $_GET['page'] ) && $_GET['page'] == 'slider-settings.php' ) ) { if ( 'plugins.php' == $hook_suffix ) { if ( isset( $sldr_options['first_install'] ) && strtotime( '-1 week' ) > $sldr_options['first_install'] ) { bws_plugin_banner_to_settings( $sldr_plugin_info, 'sldr_options', 'slider-bws', 'admin.php?page=slider-settings.php', 'admin.php?page=slider-new.php' ); } } else { bws_plugin_suggest_feature_banner( $sldr_plugin_info, 'sldr_options', 'slider' ); } } } } /** * Add help tab to plugins page. */ if ( ! function_exists( 'sldr_add_tabs' ) ) { function sldr_add_tabs() { $screen = get_current_screen(); $args = array( 'id' => 'sldr', 'section' => '115000726446' ); bws_help_tab( $screen, $args ); } } /** * Perform at uninstall */ if ( ! function_exists( 'sldr_plugin_uninstall' ) ) { function sldr_plugin_uninstall() { global $wpdb; if ( function_exists( 'is_multisite' ) && is_multisite() ) { $old_blog = $wpdb->blogid; /* Get all blog ids */ $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); foreach ( $blogids as $blog_id ) { switch_to_blog( $blog_id ); $wpdb->query( "DROP TABLE IF EXISTS `" . $wpdb->prefix . "sldr_slider`, `" . $wpdb->prefix . "sldr_slide`, `" . $wpdb->prefix . "sldr_relation`, `" . $wpdb->prefix . "sldr_category` " ); delete_option( 'sldr_options' ); } switch_to_blog( $old_blog ); } else { $wpdb->query( "DROP TABLE IF EXISTS `" . $wpdb->prefix . "sldr_slider`, `" . $wpdb->prefix . "sldr_slide`, `" . $wpdb->prefix . "sldr_relation`, `" . $wpdb->prefix . "sldr_category` " ); delete_option( 'sldr_options' ); } require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); bws_include_init( plugin_basename( __FILE__ ) ); bws_delete_plugin( plugin_basename( __FILE__ ) ); } } if ( ! function_exists( 'crrntl_homepage_slider' ) ) { function sldr_homepage_slider() { if ( is_home() || is_front_page() || is_page_template( 'page-homev1.php' ) || is_page_template( 'page-homev2.php' ) || is_page_template( 'page-homev3.php' ) ) { sldr_display_slider_before_content(); } } } /** * Display slider on home page * @return void */ if ( ! function_exists( 'sldr_display_slider_before_content' ) ) { function sldr_display_slider_before_content() { global $sldr_options; /* Find single slider which need to display in the front page of the Renty theme */ $id = $sldr_options['display_in_front_page']; if ( 0 != $id ) { echo do_shortcode( "[print_sldr id=" . $id . "]" ); } } } /** * Display slider on home page * @return void */ if ( ! function_exists( 'sldr_homepage_slider_renty' ) ) { function sldr_homepage_slider_renty( $slider_activ ) { global $sldr_options, $wpdb; $slider_activ = false; $id = $sldr_options['display_in_front_page']; /* Find single slider which need to display in the front page of the Renty theme */ if ( 0 != $id ) { wp_enqueue_style( 'sldr_stylesheet_home', plugins_url( '/css/home_search_form.css', __FILE__ ) ); echo do_shortcode( "[print_sldr id=" . $id . "]" ); $slider_activ = true; } return $slider_activ; } } /* Get Slider data objects */ if ( ! function_exists( 'sldr_get_slider_data' ) ) { function sldr_get_slider_data( $number = '', $categories = '', $id = '' ) { global $sldr_options, $wpdb; if ( empty( $sldr_options ) ) { sldr_settings(); } // get sliders array from db $sliders = $wpdb->get_results( " SELECT * FROM {$wpdb->prefix}sldr_slider ", ARRAY_A ); if ( '' != $id ) { foreach ( $sliders as $item ) { foreach ( $item as $key => $val ) { if ( 'title' == $key && $id != $val ) { unset( $sliders[ $key ] ); } } } } if ( '' != $number ) { $sliders = array_splice( $sliders, $number ); } // get sliders categories from db if ( '' == $categories ) { $slider_categories = $wpdb->get_results( " SELECT {$wpdb->prefix}sldr_relation.category_id, {$wpdb->prefix}sldr_category.title, {$wpdb->prefix}sldr_relation.slider_id FROM {$wpdb->prefix}sldr_relation LEFT JOIN {$wpdb->prefix}sldr_category ON {$wpdb->prefix}sldr_relation.category_id = {$wpdb->prefix}sldr_category.category_id WHERE {$wpdb->prefix}sldr_relation.category_id <> '' ", ARRAY_A ); } else { if ( is_array( $categories ) ) { foreach ( $categories as $val ) { $categories = implode( ',', $val ); } } $slider_categories = $wpdb->get_results( " SELECT {$wpdb->prefix}sldr_relation.category_id, {$wpdb->prefix}sldr_category.title, {$wpdb->prefix}sldr_relation.slider_id FROM {$wpdb->prefix}sldr_relation LEFT JOIN {$wpdb->prefix}sldr_category ON {$wpdb->prefix}sldr_relation.category_id = {$wpdb->prefix}sldr_category.category_id WHERE {$wpdb->prefix}sldr_relation.category_id <> '' AND {$wpdb->prefix}sldr_category.title IN '$categories' ", ARRAY_A ); } // get slides from db $slides = $wpdb->get_results( " SELECT {$wpdb->prefix}sldr_slide.slide_id, {$wpdb->prefix}sldr_slide.attachment_id, {$wpdb->prefix}sldr_slide.title, {$wpdb->prefix}sldr_slide.description, {$wpdb->prefix}sldr_slide.url, {$wpdb->prefix}sldr_slide.button, {$wpdb->prefix}sldr_slide.order, {$wpdb->prefix}sldr_relation.slider_id FROM {$wpdb->prefix}sldr_slide LEFT JOIN {$wpdb->prefix}sldr_relation ON {$wpdb->prefix}sldr_relation.attachment_id = {$wpdb->prefix}sldr_slide.attachment_id ", ARRAY_A ); // loop sliders, add sliders settigns to the array foreach ( $sliders as $item => $arr ) { foreach ( $arr as $key => $val ) { if ( 'settings' == $key ) { $sliders[ $item ][ $key ] = maybe_unserialize( $val ); } } } // loop categories if exists, add to the main array foreach ( ( array ) $slider_categories as $sldr_ctgr_arr ) { foreach ( $sldr_ctgr_arr as $sldr_ctgr_key => $sldr_ctgr_val ) { foreach ( $sliders as $sliders_arr => $slider_arr ) { foreach ( $slider_arr as $slider_key => $slider_val ) { if ( $sldr_ctgr_key == $slider_key && $sldr_ctgr_val == $slider_val ) { $sliders[ $sliders_arr ]['categories'][] = $sldr_ctgr_arr; } } } } } // loop sliders and slides, add slides to the main array foreach ( $sliders as $sliders_arr => $slider_arr ) { foreach ( $slider_arr as $slider_key => $slider_val ) { foreach ( $slides as $slide_arr ) { foreach ( $slide_arr as $slide_key => $slide_val ) { if ( $slide_key == $slider_key && $slide_val == $slider_val ) { $sliders[ $sliders_arr ]['slides'][] = $slide_arr; } } } } } return $sliders; } } register_activation_hook( __FILE__, 'sldr_plugin_activate' ); add_action( 'admin_menu', 'sldr_add_admin_menu' ); add_action( 'init', 'sldr_init' ); add_action( 'admin_init', 'sldr_admin_init' ); add_action( 'plugins_loaded', 'sldr_plugins_loaded' ); add_action( 'admin_enqueue_scripts', 'sldr_admin_head' ); add_action( 'wp_enqueue_scripts', 'sldr_register_scripts' ); /* Additional links on the plugin page */ add_filter( 'plugin_row_meta', 'sldr_register_plugin_links', 10, 2 ); add_filter( 'plugin_action_links', 'sldr_plugin_action_links', 10, 2 ); add_action( 'admin_notices', 'sldr_admin_notices' ); add_filter( 'set-screen-option', 'sldr_set_screen_options', 10, 3 ); /* Add place for notice in media upoader for portfolio */ add_action( 'print_media_templates', 'sldr_print_media_notice', 11 ); /* Add notises in media upoader for slider */ add_action( 'wp_ajax_sldr_media_check', 'sldr_media_check_ajax_action' ); add_action( 'wp_ajax_sldr_delete_image', 'sldr_delete_image' ); add_action( 'wp_ajax_sldr_add_from_media', 'sldr_add_from_media' ); add_filter( 'bws_shortcode_button_content', 'sldr_shortcode_button_content' ); add_shortcode( 'print_sldr', 'sldr_shortcode' ); add_filter( 'widget_text', 'do_shortcode' ); /* Display slider on home page of the Renty theme */ add_action( 'sldr_display_slider', 'sldr_homepage_slider' ); add_filter( 'template_homepage_slider', 'sldr_homepage_slider_renty' );