2017 © Pedro Peláez
 

wordpress-plugin gallery-types

Allows you to define a theme specific gallery type.

image

wearerequired/gallery-types

Allows you to define a theme specific gallery type.

  • Saturday, January 13, 2018
  • by wearerequired
  • Repository
  • 4 Watchers
  • 0 Stars
  • 183 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 49 % Grown

The README.md

Gallery Types

A plugin that allows you to define a theme specific gallery type. Props to Jetpack for their Gallery module., (*1)

By default the plugin supports only one type, WordPress default thumbnail grid. To add more types you can use the gallery_types.types filter., (*2)

add_filter( 'gallery_types.types', function( $types ) {
    return array_merge( $types, [
        'slider' => [
            'label' => __( 'Slider', 'gallery-types' ),
            'supports_columns' => false,
        ],
    ] );
} );

Each type has a key (slider) with two values: label for the label displayed in the select menu and supports_columns to define whether the type supports columns. If supports_columns is set to false the columns option will be hidden.
Once a user selects a type the shortcode will get a new type attribute with the key of a gallery type as value., (*3)

To change the default selected type you can use the gallery_types.default-type filter., (*4)

This plugin does not change the ouput of the gallery shortcode. That needs to be part of your theme and could be something like this:, (*5)

/**
 * Customizes the gallery shortcode output if the type attribute is set to 'slider'.
 *
 * @see gallery_shortcode()
 *
 * @param string $output The gallery output. Default empty.
 * @param array  $attr   Attributes of the gallery shortcode.
 * @return string HTML content to display gallery.
 */
function required_gallery_shortcode( $output, $attr ) {
    $is_slider = false;

    // Check if the type attribute is set.
    if ( isset( $attr['type'] ) && 'slider' === $attr['type'] ) {
        $is_slider = true;
    }

    // Return the default gallery if the type attribute isn't set.
    if ( ! $is_slider ) {
        remove_filter( 'post_gallery', 'required_gallery_shortcode', 10 );
        $output = gallery_shortcode( $attr );
        add_filter( 'post_gallery', 'required_gallery_shortcode', 10, 2 );
        return $output;
    }

    // Override shortcode attributes.
    $attr['size']    = 'thumbnail';
    $attr['link']    = 'file';
    $attr['columns'] = 0;

    // Get default gallery output and wrap it in a custom container div.
    remove_filter( 'post_gallery', 'required_gallery_shortcode', 10 );
    $output = gallery_shortcode( $attr );
    add_filter( 'post_gallery', 'required_gallery_shortcode', 10, 2 );

    return "<div class='gallery-slider'>$output</div>";
}
add_filter( 'post_gallery', 'required_gallery_shortcode', 10, 2 );

Contributing

Build Task

To update the minfied JavaScript file you need Node.js installed., (*6)

# to install dependencies run:
npm install

# to update the file run:
npm run build

The Versions

13/01 2018

dev-master

9999999-dev https://github.com/wearerequired/gallery-types

Allows you to define a theme specific gallery type.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.6

 

wordpress gallery slider

13/01 2018

1.0.1

1.0.1.0 https://github.com/wearerequired/gallery-types

Allows you to define a theme specific gallery type.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.6

 

wordpress gallery slider

11/05 2017

1.0.0

1.0.0.0

Allows you to define a theme specific gallery type.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.6