diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b972665 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +composer.json \ No newline at end of file diff --git a/README.md b/README.md index 1823e45..0a438a8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -wp-plugin-owlcarousel -===================== +# Owl Carousel + A plugin to use Owl Carousel in Wordpress + + +#### Contributers + +- [Jehan Pierre](https://github.com/pjehan) (Original author) +- [Rasmus Taarnby](https://github.com/rasmustaarnby) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..777b141 --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "pjehan/wp-plugin-owlcarousel", + "description": "A plugin to use Owl Carousel in Wordpress.", + "type": "wordpress-plugin", + "keywords": ["wordpress", "plugin"], + "homepage": "https://github.com/pjehan/wp-plugin-owlcarousel", + "authors": [ + { + "name": "Jehan Pierre", + "email": "pierre.jehan@gmail.com", + "homepage": "http://www.pierre-jehan.com" + }, + { + "name": "Rasmus Taarnby", + "email": "rt@peytz.dk", + "homepage": "http://peytz.dk/medarbejdere/rt" + } + ] +} diff --git a/owlcarousel.php b/owlcarousel.php index accbaca..2337fe8 100644 --- a/owlcarousel.php +++ b/owlcarousel.php @@ -8,356 +8,374 @@ Licence: GPL2 */ -add_theme_support('post-thumbnails'); - -add_action('init', 'owlcarousel_init'); -add_action('wp_print_scripts', 'owl_register_scripts'); -add_action('wp_print_styles', 'owl_register_styles'); -add_action('widgets_init', 'owl_widgets_init'); -add_action('manage_edit-owl-carousel_columns', 'owl_columnfilter'); -add_action('manage_posts_custom_column', 'owl_column'); -add_action('admin_menu', 'owl_carousel_menu'); -add_action('admin_enqueue_scripts', 'owl_carousel_admin_register_scripts'); - -if(filter_var(get_option('owl_carousel_wordpress_gallery', false), FILTER_VALIDATE_BOOLEAN)) { - add_filter('post_gallery', 'owl_carousel_post_gallery', 10, 2); +add_theme_support( 'post-thumbnails' ); + +add_action( 'init', 'owlcarousel_init' ); +add_action( 'wp_print_scripts', 'owl_register_scripts' ); +add_action( 'wp_print_styles', 'owl_register_styles' ); +add_action( 'widgets_init', 'owl_widgets_init' ); +add_action( 'manage_edit-owl-carousel_columns', 'owl_columnfilter' ); +add_action( 'manage_posts_custom_column', 'owl_column' ); +add_action( 'admin_menu', 'owl_carousel_menu' ); +add_action( 'admin_enqueue_scripts', 'owl_carousel_admin_register_scripts' ); + +if ( filter_var( get_option( 'owl_carousel_wordpress_gallery', false ), FILTER_VALIDATE_BOOLEAN ) ) { + add_filter( 'post_gallery', 'owl_carousel_post_gallery', 10, 2 ); } // Add functions to create a new attachments fields -add_filter("attachment_fields_to_edit", "owl_carousel_attachment_fields_to_edit", null, 2); -add_filter("attachment_fields_to_save", "owl_carousel_attachment_fields_to_save", null, 2); +add_filter( "attachment_fields_to_edit", "owl_carousel_attachment_fields_to_edit", null, 2 ); +add_filter( "attachment_fields_to_save", "owl_carousel_attachment_fields_to_save", null, 2 ); /** * Initilize the plugin */ function owlcarousel_init() { - $labels = array( - 'name' => __('Owl Carousel', 'owl-carousel-domain'), - 'singular_name' => __('Carousel Item', 'owl-carousel-domain'), - 'add_new' => __('Add New Item', 'owl-carousel-domain'), - 'add_new_item' => __('Add New Carousel Item', 'owl-carousel-domain'), - 'edit_item' => __('Edit Carousel Item', 'owl-carousel-domain'), - 'new_item' => __('Add New Carousel Item', 'owl-carousel-domain'), - 'view_item' => __('View Item', 'owl-carousel-domain'), - 'search_items' => __('Search Carousel', 'owl-carousel-domain'), - 'not_found' => __('No carousel items found', 'owl-carousel-domain'), - 'not_found_in_trash' => __('No carousel items found in trash', 'owl-carousel-domain'), - ); - - register_post_type('owl-carousel', array( - 'public' => true, - 'publicly_queryable' => false, - 'exclude_from_search' => true, - 'label' => 'Owl Carousel', - 'menu_icon' => plugins_url('/owl-carousel/images/owl-logo-16.png'), - 'labels' => $labels, - 'capability_type' => 'post', - 'supports' => array( - 'title', - 'editor', - 'thumbnail' - ) - )); - - register_taxonomy( + $labels = array( + 'name' => __( 'Owl Carousel', 'owl-carousel-domain' ), + 'singular_name' => __( 'Carousel Item', 'owl-carousel-domain' ), + 'add_new' => __( 'Add New Item', 'owl-carousel-domain' ), + 'add_new_item' => __( 'Add New Carousel Item', 'owl-carousel-domain' ), + 'edit_item' => __( 'Edit Carousel Item', 'owl-carousel-domain' ), + 'new_item' => __( 'Add New Carousel Item', 'owl-carousel-domain' ), + 'view_item' => __( 'View Item', 'owl-carousel-domain' ), + 'search_items' => __( 'Search Carousel', 'owl-carousel-domain' ), + 'not_found' => __( 'No carousel items found', 'owl-carousel-domain' ), + 'not_found_in_trash' => __( 'No carousel items found in trash', 'owl-carousel-domain' ), + ); + + register_post_type( 'owl-carousel', array( + 'public' => true, + 'publicly_queryable' => false, + 'exclude_from_search' => true, + 'label' => 'Owl Carousel', + 'menu_icon' => plugins_url( '/owl-carousel/images/owl-logo-16.png' ), + 'labels' => $labels, + 'capability_type' => 'post', + 'supports' => array( + 'title', + 'editor', + 'thumbnail' + ) + ) ); + + register_taxonomy( 'Carousel', 'owl-carousel', array( 'label' => __( 'Carousel' ), 'rewrite' => array( 'slug' => 'carousel' ), 'hierarchical' => true, - 'show_admin_column' => true, + 'show_admin_column' => true, ) ); - add_image_size('owl_widget', 180, 100, true); - add_image_size('owl_function', 600, 280, true); + add_image_size( 'owl_widget', 180, 100, true ); + add_image_size( 'owl_function', 600, 280, true ); - add_shortcode('owl-carousel', 'owl_function'); - add_filter("mce_external_plugins", "owl_register_tinymce_plugin"); - add_filter('mce_buttons', 'owl_add_tinymce_button'); + add_shortcode( 'owl-carousel', 'owl_function' ); + add_filter( "mce_external_plugins", "owl_register_tinymce_plugin" ); + add_filter( 'mce_buttons', 'owl_add_tinymce_button' ); - // Add Wordpress Gallery option - add_option('owl_carousel_wordpress_gallery', 'off'); - add_option('owl_carousel_orderby', 'post_date'); + // Add Wordpress Gallery option + add_option( 'owl_carousel_wordpress_gallery', 'off' ); + add_option( 'owl_carousel_orderby', 'post_date' ); } + function owl_carousel_menu() { - add_submenu_page('edit.php?post_type=owl-carousel', __('Parameters', 'owl-carousel-domain'), __('Parameters', 'owl-carousel-domain'), 'manage_options', 'owl-carousel-parameters', 'submenu_parameters'); + add_submenu_page( 'edit.php?post_type=owl-carousel', __( 'Parameters', 'owl-carousel-domain' ), __( 'Parameters', 'owl-carousel-domain' ), 'manage_options', 'owl-carousel-parameters', 'submenu_parameters' ); } + function submenu_parameters() { - $isWordpressGallery = (filter_var(get_option('owl_carousel_wordpress_gallery', false), FILTER_VALIDATE_BOOLEAN)) ? 'checked' : ''; - $orderBy = get_option('owl_carousel_orderby', 'post_date'); - $orderByOptions = array('post_date', 'title'); + $isWordpressGallery = ( filter_var( get_option( 'owl_carousel_wordpress_gallery', false ), FILTER_VALIDATE_BOOLEAN ) ) ? 'checked' : ''; + $orderBy = get_option( 'owl_carousel_orderby', 'post_date' ); + $orderByOptions = array( 'post_date', 'title' ); - echo '
- - + +
- - + +
$instance['category'], singleItem => "true", autoPlay => "true", pagination => "false")); - echo $after_widget; - } + } + + + public function update( $new_instance, $old_instance ) { + $instance = array(); + $instance['title'] = strip_tags( $new_instance['title'] ); + $instance['category'] = strip_tags( $new_instance['category'] ); + + return $instance; + } + + + public function widget( $args, $instance ) { + extract( $args ); + $title = apply_filters( 'widget_title', $instance['title'] ); + echo $before_widget; + if ( !empty( $title ) ) + echo $before_title . $title . $after_title; + echo owl_function( array( category => $instance['category'], singleItem => "true", autoPlay => "true", pagination => "false" ) ); + echo $after_widget; + } + } + /** * Add custom column filters in administration * @param array $columns */ -function owl_columnfilter($columns) { - $thumb = array('thumbnail' => 'Image'); - $columns = array_slice($columns, 0, 2) + $thumb + array_slice($columns, 2, null); +function owl_columnfilter( $columns ) { + $thumb = array( 'thumbnail' => 'Image' ); + $columns = array_slice( $columns, 0, 2 ) + $thumb + array_slice( $columns, 2, null ); - return $columns; + return $columns; } + /** * Add custom column contents in administration * @param string $columnName */ -function owl_column($columnName) { - global $post; - if ($columnName == 'thumbnail') { - echo edit_post_link(get_the_post_thumbnail($post->ID, 'thumbnail'), null, null, $post->ID); - } +function owl_column( $columnName ) { + global $post; + if ( $columnName == 'thumbnail' ) { + echo edit_post_link( get_the_post_thumbnail( $post->ID, 'thumbnail' ), null, null, $post->ID ); + } } + /** * Adding our images custom fields to the $form_fields array * @param array $form_fields * @param object $post * @return array */ -function owl_carousel_attachment_fields_to_edit($form_fields, $post) { - // add our custom field to the $form_fields array - // input type="text" name/id="attachments[$attachment->ID][custom1]" - $form_fields["owlurl"] = array( - "label" => __("Owl Carousel URL"), - "input" => "text", - "value" => get_post_meta($post->ID, "_owlurl", true) - ); - - return $form_fields; +function owl_carousel_attachment_fields_to_edit( $form_fields, $post ) { + // add our custom field to the $form_fields array + // input type="text" name/id="attachments[$attachment->ID][custom1]" + $form_fields["owlurl"] = array( + "label" => __( "Owl Carousel URL" ), + "input" => "text", + "value" => get_post_meta( $post->ID, "_owlurl", true ) + ); + + return $form_fields; } + /** * Save images custom fields * @param array $post * @param array $attachment * @return array */ -function owl_carousel_attachment_fields_to_save($post, $attachment) { - if( isset($attachment['owlurl']) ){ - update_post_meta($post['ID'], '_owlurl', $attachment['owlurl']); - } +function owl_carousel_attachment_fields_to_save( $post, $attachment ) { + if ( isset( $attachment['owlurl'] ) ) { + update_post_meta( $post['ID'], '_owlurl', $attachment['owlurl'] ); + } - return $post; + return $post; } + /** * Plugin main function * @param type $atts Owl parameters * @param type $content * @return string Owl HTML code */ -function owl_function($atts, $content = null) { - extract(shortcode_atts(array( - 'category' => 'Uncategoryzed' - ), $atts)); - - $data_attr = ""; - foreach ($atts as $key => $value) { - if ($key != "category") { - $data_attr .= ' data-' . $key . '="' . $value . '" '; - } - } - - $lazyLoad = array_key_exists("lazyload", $atts) && $atts["lazyload"] == true; - - $args = array( - 'post_type' => 'owl-carousel', - 'orderby' => get_option('owl_carousel_orderby', 'post_date'), - 'order' => 'asc', - 'tax_query' => array( - array( - 'taxonomy' => 'Carousel', - 'field' => 'slug', - 'terms' => $atts['category'] - ) - ), - 'nopaging' => true - ); - - $result = '