/** * Add data for our newly-added custom columns. * @access public * @since 1.0.0 * @param string $column_name * @param int $id * @return void */ public function add_column_data($column_name, $id) { global $wpdb, $post; switch ($column_name) { case 'id': echo $id; break; case 'slide-page': $value = __('No Slide Groups Specified', 'wooslider'); $terms = get_the_terms($id, 'slide-page'); if ($terms && !is_wp_error($terms)) { $term_links = array(); foreach ($terms as $term) { $term_links[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => 'slide', 'tag_ID' => $term->term_id, 'taxonomy' => 'slide-page', 'action' => 'edit'), 'edit-tags.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, 'slide-page', 'display'))); } $value = join(', ', $term_links); } echo $value; break; case 'slide-thumbnail': echo '<a href="' . esc_url(admin_url(add_query_arg(array('post' => intval($id), 'action' => 'edit'), 'post.php'))) . '">' . "\n"; if (has_post_thumbnail($id)) { the_post_thumbnail(array(75, 75)); } else { echo '<img src="' . esc_url(WooSlider_Utils::get_placeholder_image()) . '" width="75" />' . "\n"; } echo '</a>' . "\n"; break; default: break; } }
/** * Get the slides for the "slides" slideshow type. * @since 1.0.0 * @param array $args Array of arguments to determine which slides to return. * @return array An array of slides to render for the slideshow. */ private function slideshow_type_slides($args = array()) { global $post; $slides = array(); $defaults = array('limit' => '5', 'slide_page' => '', 'thumbnails' => ''); $args = wp_parse_args($args, $defaults); $query_args = array('post_type' => 'slide', 'numberposts' => intval($args['limit'])); if ($args['slide_page'] != '') { $cats_split = explode(',', $args['slide_page']); $query_args['tax_query'] = array(); foreach ($cats_split as $k => $v) { $query_args['tax_query'][] = array('taxonomy' => 'slide-page', 'field' => 'slug', 'terms' => esc_attr(trim(rtrim($v)))); } } $posts = get_posts($query_args); if (!is_wp_error($posts) && count($posts) > 0) { foreach ($posts as $k => $post) { setup_postdata($post); $content = get_the_content(); $data = array('content' => '<div class="slide-content">' . "\n" . apply_filters('wooslider_slide_content_slides', $content, $args) . "\n" . '</div>' . "\n"); if ('true' == $args['thumbnails'] || 1 == $args['thumbnails']) { $thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium'); if (!is_bool($thumb_url) && isset($thumb_url[0])) { $data['attributes'] = array('data-thumb' => esc_url($thumb_url[0])); } else { $data['attributes'] = array('data-thumb' => esc_url(WooSlider_Utils::get_placeholder_image())); } } $slides[] = $data; } wp_reset_postdata(); } return $slides; }
/** * Generate conditional fields for the "posts" slideshow type. * @since 1.0.0 * @return array $fields An array of fields. */ public function generate_conditional_fields_posts() { global $wooslider; $images_url = $wooslider->plugin_url . '/assets/images/'; $fields = array(); // Categories. $terms = get_categories(); $terms_options = array(); if (!is_wp_error($terms)) { foreach ($terms as $k => $v) { $terms_options[$v->slug] = $v->name; } } $categories_args = array('key' => 'category', 'data' => array('options' => $terms_options)); // Tags. $terms = get_tags(); $terms_options = array(); if (!is_wp_error($terms)) { foreach ($terms as $k => $v) { $terms_options[$v->slug] = $v->name; } } $tags_args = array('key' => 'tag', 'data' => array('options' => $terms_options)); $thumbnails = WooSlider_Utils::get_thumbnail_options(); $thumbnails_options = array(); foreach ($thumbnails as $k => $v) { $thumbnails_options[$k] = $v['name']; } $thumbnails_args = array('key' => 'thumbnails', 'data' => array('options' => $thumbnails_options, 'default' => 'Default')); $layout_types = WooSlider_Utils::get_posts_layout_types(); $layout_options = array(); foreach ((array) $layout_types as $k => $v) { $layout_options[$k] = $v['name']; } $layout_images = array('text-left' => esc_url($images_url . 'text-left.png'), 'text-right' => esc_url($images_url . 'text-right.png'), 'text-top' => esc_url($images_url . 'text-top.png'), 'text-bottom' => esc_url($images_url . 'text-bottom.png')); $layouts_args = array('key' => 'layout', 'data' => array('options' => $layout_options, 'images' => $layout_images)); $overlay_images = array('none' => esc_url($images_url . 'default.png'), 'full' => esc_url($images_url . 'text-bottom.png'), 'natural' => esc_url($images_url . 'overlay-natural.png')); $overlay_options = array('none' => __('None', 'wooslider'), 'full' => __('Full', 'wooslider'), 'natural' => __('Natural', 'wooslider')); $overlay_args = array('key' => 'overlay', 'data' => array('options' => $overlay_options, 'images' => $overlay_images)); $limit_options = array(); for ($i = 1; $i <= 20; $i++) { $limit_options[$i] = $i; } $limit_args = array('key' => 'limit', 'data' => array('options' => $limit_options, 'default' => 5)); //$thumbnails_args = array( 'key' => 'thumbnails', 'data' => array() ); $sticky_posts_args = array('key' => 'sticky_posts', 'data' => array()); $link_title_args = array('key' => 'link_title', 'data' => array()); $display_excerpt_args = array('key' => 'display_excerpt', 'data' => array('default' => '1')); // Create final array. $fields['limit'] = array('name' => __('Number of Posts', 'wooslider'), 'type' => 'select', 'args' => $limit_args, 'description' => __('The maximum number of posts to display', 'wooslider')); $fields['sticky_posts'] = array('name' => __('Allow for Sticky Posts', 'wooslider'), 'type' => 'checkbox', 'args' => $sticky_posts_args, 'description' => __('Display sticky posts in the slider', 'wooslider')); $fields['thumbnails'] = array('name' => __('Use thumbnails for Pagination', 'wooslider'), 'type' => 'select', 'args' => $thumbnails_args, 'description' => __('Use thumbnails for pagination, instead of "dot" indicators (uses featured image)', 'wooslider')); $fields['link_title'] = array('name' => __('Link the post title to it\'s post', 'wooslider'), 'type' => 'checkbox', 'args' => $link_title_args, 'description' => __('Link the post title to it\'s single post screen', 'wooslider')); $fields['display_excerpt'] = array('name' => __('Display the post\'s excerpt', 'wooslider'), 'type' => 'checkbox', 'args' => $display_excerpt_args, 'description' => __('Display the post\'s excerpt on each slide', 'wooslider')); $fields['layout'] = array('name' => __('Layout', 'wooslider'), 'type' => 'images', 'args' => $layouts_args, 'description' => __('The layout to use when displaying posts', 'wooslider')); $fields['overlay'] = array('name' => __('Overlay', 'wooslider'), 'type' => 'images', 'args' => $overlay_args, 'description' => __('The type of overlay to use when displaying the post text', 'wooslider')); $fields['category'] = array('name' => __('Categories', 'wooslider'), 'type' => 'multicheck', 'args' => $categories_args, 'description' => __('The categories from which to display posts', 'wooslider')); $fields['tag'] = array('name' => __('Tags', 'wooslider'), 'type' => 'multicheck', 'args' => $tags_args, 'description' => __('The tags from which to display posts', 'wooslider')); return $fields; }
/** * Get data for a specified theme. * @since 1.0.4 * @param array $args Arguments for the current slideshow. * @return string The slug of the theme, or 'default'. */ public function get_theme_data($key) { $theme = array('name' => 'default', 'stylesheet' => ''); if (in_array($key, array_keys(WooSlider_Utils::get_slider_themes()))) { $themes = WooSlider_Utils::get_slider_themes(); $theme = $themes[esc_attr($key)]; } return $theme; }
/** * form function. * * @since 1.0.0 * @access public * @param array $instance * @uses global $wooslider object * @return void */ public function form($instance) { global $wooslider; /* Set up some default widget settings. */ /* Make sure all keys are added here, even with empty string values. */ $defaults = $this->defaults; // Allow child themes/plugins to filter here. $defaults = apply_filters($this->woo_widget_idbase . '_widget_defaults', $defaults, $this); $defaults['show_advanced_settings'] = 0; $defaults['theme'] = 'default'; $advanced_fields = array(); $wooslider->settings->init_fields(); $advanced_fields = $wooslider->settings->fields; if (is_array($advanced_fields) && count($advanced_fields) > 0) { foreach ($advanced_fields as $k => $v) { if (!isset($defaults[$k])) { $defaults[$k] = $v['default']; } } } $has_fields = false; if (isset($this->slider_type) && $this->slider_type != '') { $fields = $wooslider->admin->generate_default_conditional_fields(array($this->slider_type => $this->slider_type)); $has_fields = true; if (0 < count($fields)) { foreach ($fields[$this->slider_type] as $k => $v) { if (isset($v['args']['data']['default'])) { $defaults[$k] = $v['args']['data']['default']; } } } } // Get the supported themes. $themes = WooSlider_Utils::get_slider_themes(); $instance = wp_parse_args($instance, $defaults); ?> <!-- Widget Title: Text Input --> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title (optional):', 'wooslider'); ?> </label> <input type="text" name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo $instance['title']; ?> " class="widefat" id="<?php echo $this->get_field_id('title'); ?> " /> </p> <?php if (is_array($themes) && 1 < count($themes)) { ?> <!-- Widget Theme: Select Input --> <p> <label for="<?php echo $this->get_field_id('theme'); ?> "><?php _e('Slider Theme:', 'wooslider'); ?> </label> <select name="<?php echo $this->get_field_name('theme'); ?> " class="widefat" id="<?php echo $this->get_field_id('theme'); ?> "> <?php foreach ($themes as $k => $v) { ?> <option value="<?php echo esc_attr($k); ?> "<?php selected($instance['theme'], $k); ?> ><?php echo $v['name']; ?> </option> <?php } ?> </select> </p> <?php } else { echo '<input type="hidden" name="' . esc_attr($this->get_field_name('theme')) . '" id="' . esc_attr($this->get_field_id('theme')) . '" value="' . esc_attr($instance['theme']) . '" />' . "\n"; } ?> <?php if (isset($this->slider_type) && $this->slider_type != '') { foreach ($fields[$this->slider_type] as $k => $v) { ?> <p> <?php $field_label = '<label for="' . esc_attr($k) . '">' . $v['name'] . '</label>' . "\n"; if ($v['type'] != 'checkbox') { echo $field_label; } // Display the label first if the field isn't a checkbox. $this->generate_field_by_type($v['type'], $v['args'], $instance); if ($v['type'] == 'checkbox') { echo $field_label; } // Display the label last if the field is a checkbox. ?> </p> <?php } ?> <hr /> <!-- Widget Advanced Fields: Text Input --> <p> <input type="checkbox" name="<?php echo $this->get_field_name('show_advanced_settings'); ?> " value="1" id="<?php echo $this->get_field_id('show_advanced_settings'); ?> " <?php checked('1', $instance['show_advanced_settings']); ?> /> <label for="<?php echo $this->get_field_id('show_advanced_settings'); ?> "><?php _e('Customise Advanced Settings', 'wooslider'); ?> </label> </p> <p><small><?php _e('Save the widget settings with this checkbox checked to customise slider settings.', 'wooslider'); ?> </small></p> <?php if (isset($instance['show_advanced_settings']) && $instance['show_advanced_settings'] == 1) { if (is_array($advanced_fields) && count($advanced_fields) > 0) { foreach ($advanced_fields as $k => $v) { echo '<p>' . "\n"; $label = $v['name']; if ($label == '') { $label = $v['description']; } $field_label = '<label for="' . esc_attr($k) . '">' . $label . '</label>' . "\n"; if ($v['type'] != 'checkbox') { echo $field_label; } // Display the label first if the field isn't a checkbox. $this->generate_field_by_type($v['type'], array('key' => $k, 'data' => $v), $instance); if ($v['type'] == 'checkbox') { echo $field_label; } // Display the label last if the field is a checkbox. echo '</p>' . "\n"; } } } else { if (is_array($advanced_fields) && count($advanced_fields) > 0) { foreach ($advanced_fields as $k => $v) { echo '<input type="hidden" name="' . esc_attr($this->get_field_name($k)) . '" id="' . esc_attr($this->get_field_id($k)) . '" value="' . esc_attr($instance[$k]) . '" />' . "\n"; } } } } // Allow child themes/plugins to act here. do_action($this->woo_widget_idbase . '_widget_settings', $instance, $this); }
/** * Get the slides for the "slides" slideshow type. * @since 1.0.0 * @param array $args Array of arguments to determine which slides to return. * @return array An array of slides to render for the slideshow. */ private function slideshow_type_slides($args = array(), $settings = array()) { global $post; $slides = array(); $has_video = array('youtube' => false, 'vimeo' => false, 'wistia' => false); $defaults = array('limit' => '5', 'slide_page' => '', 'carousel' => '', 'thumbnails' => '', 'layout' => 'text-left', 'imageslide' => 'false', 'size' => 'large', 'display_title' => '', 'overlay' => 'none', 'display_content' => 'true', 'order' => 'DESC', 'order_by' => 'date', 'link_slide' => 'false'); $args = wp_parse_args($args, $defaults); $query_args = array('post_type' => 'slide', 'numberposts' => intval($args['limit']), 'orderby' => $args['order_by'], 'order' => $args['order']); if (true == $settings['randomize']) { $query_args['orderby'] = 'rand'; } if ('' != $args['slide_page']) { $cats_split = explode(',', $args['slide_page']); $query_args['tax_query'] = array(array('taxonomy' => 'slide-page', 'field' => 'slug', 'terms' => $cats_split)); } $posts = get_posts($query_args); if (!is_wp_error($posts) && count($posts) > 0) { foreach ($posts as $k => $post) { setup_postdata($post); $class = ''; if (isset($args['carousel']) && 'true' == $args['carousel']) { $image = get_the_post_thumbnail(get_the_ID()); $wooslider_url = get_post_meta(get_the_ID(), '_wooslider_url', true); if (('true' == $args['link_slide'] || 1 == $args['link_slide']) && '' != $wooslider_url) { $image = '<a href="' . esc_url($wooslider_url) . '">' . $image . '</a>'; } $data = array('content' => '<div class="slide-content">' . "\n" . apply_filters('wooslider_slide_carousel_slides', $image, $args) . "\n" . '</div>' . "\n"); } else { if ((isset($args['imageslide']) && 'true' == $args['imageslide'] || 1 == $args['imageslide']) && '' != get_the_post_thumbnail(get_the_ID())) { // Determine and validate the layout type. $supported_layouts = WooSlider_Utils::get_posts_layout_types(); if (!in_array($args['layout'], array_keys($supported_layouts))) { $args['layout'] = $defaults['layout']; } // Determine and validate the overlay setting. if (!in_array($args['overlay'], array('none', 'full', 'natural'))) { $args['overlay'] = $defaults['overlay']; } if ($args['display_content'] == 'true' || $args['display_content'] == 1 || ($args['display_title'] == 'true' || $args['display_title'] == 1)) { $class = 'layout-' . esc_attr($args['layout']) . ' overlay-' . esc_attr($args['overlay']); } $image = get_the_post_thumbnail(get_the_ID(), $args['size']); $wooslider_url = get_post_meta(get_the_ID(), '_wooslider_url', true); if (('true' == $args['link_slide'] || 1 == $args['link_slide']) && '' != $wooslider_url) { $image = '<a href="' . esc_url($wooslider_url) . '">' . $image . '</a>'; } $title = ''; if ('true' == $args['display_title'] || 1 == $args['display_title']) { $title = get_the_title(get_the_ID()); if (('true' == $args['link_slide'] || 1 == $args['link_slide']) && '' != $wooslider_url) { $title = '<a href="' . esc_url($wooslider_url) . '">' . $title . '</a>'; } $title = '<h2 class="slide-title">' . $title . '</h2>'; } $content = ''; if ('true' == $args['display_content'] || 1 == $args['display_content']) { $content = wpautop(apply_filters('wooslider_slides_excerpt', get_the_content())); } if ('true' == $args['display_content'] || 1 == $args['display_content'] || ('true' == $args['display_title'] || 1 == $args['display_title'])) { $content = '<div class="slide-excerpt">' . $title . $content . '</div>'; if ($args['layout'] == 'text-top') { $content = $content . $image; } else { $content = $image . $content; } } else { $content = $image; } $layed_out_content = apply_filters('wooslider_slides_layout_html', $content, $args, $post); // If there is an image, add "has-featured-image" class if ('' != $image) { $class .= ' has-featured-image'; } $content = '<div class="slide-content ' . esc_attr($class) . '">' . $layed_out_content . '</div>'; $data = array('content' => $content); } else { $content = apply_filters('wooslider_slides_content', get_the_content()); $data = array('content' => '<div class="slide-content">' . "\n" . apply_filters('wooslider_slide_content_slides', $content, $args) . "\n" . '</div>' . "\n"); } } if ('true' == $args['thumbnails'] || 1 == $args['thumbnails'] || 2 == $args['thumbnails'] || 'carousel' == $args['thumbnails'] || 'thumbnails' == $args['thumbnails']) { $thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium'); if (!is_bool($thumb_url) && isset($thumb_url[0])) { $data['attributes'] = array('data-thumb' => esc_url($thumb_url[0])); } else { $data['attributes'] = array('data-thumb' => esc_url(WooSlider_Utils::get_placeholder_image())); } } $post_meta = get_post_custom(get_the_ID()); foreach ($post_meta as $meta => $value) { if ('_oembed' == substr(trim($meta), 0, 7)) { if (preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $value[0], $match)) { $has_video['youtube'] = true; add_filter('wooslider_callback_start_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_youtube_start')); add_filter('wooslider_callback_before_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_youtube_before')); } if (preg_match('#(?:https?:\\/\\/(?:[\\w]+\\.)*vimeo\\.com(?:[\\/\\w]*\\/videos?)?\\/([0-9]+)[^\\s]*)#i', $value[0], $match)) { $has_video['vimeo'] = true; add_filter('wooslider_callback_start_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_vimeo_start')); add_filter('wooslider_callback_before_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_vimeo_before')); } if (preg_match('%(?:https?:\\/\\/(?:.+)?(?:wistia.com|wi.st|wistia.net)\\/(?:medias|embed)?\\/)(.*)%i', $value[0], $match)) { $has_video['wistia'] = true; add_filter('wooslider_callback_before_' . $settings['id'], array('WooSlider_Frontend', 'wooslider_wistia_before')); } } } $data['video'] = $has_video; // add the post id to the list the slide $data['ID'] = $post->ID; $slides[] = $data; } wp_reset_postdata(); } return $slides; }