PluginProbe
Catch Gallery / 1.2
Catch Gallery v1.2
trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.5 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 All 27 releases
catch-gallery / inc / functions.php

functions.php in Catch Gallery 1.2, at inc/functions.php

123 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Renders extra controls in the Gallery Settings section of the new media UI.
5 */
6 if ( ! class_exists( 'Catch_Gallery_Settings' ) ) :
7 class Catch_Gallery_Settings {
8 function __construct() {
9 add_action( 'admin_init', array( $this, 'admin_init' ) );
10 }
11
12 function admin_init() {
13 /**
14 * Filter the available gallery types.
15 *
16 * @module shortcodes, tiled-gallery
17 *
18 * @since 2.5.1
19 *
20 * @param array $value Array of the default thumbnail grid gallery type. Default array contains one key, ‘default’.
21 *
22 */
23 $this->gallery_types = apply_filters( 'jetpack_gallery_types', array( 'default' => __( 'Thumbnail Grid', 'jetpack' ) ) );
24
25 // Enqueue the media UI only if needed.
26 if ( count( $this->gallery_types ) > 1 ) {
27 add_action( 'wp_enqueue_media', array( $this, 'wp_enqueue_media' ) );
28 add_action( 'print_media_templates', array( $this, 'print_media_templates' ) );
29 }
30 // Add Slideshow and Galleries functionality to core's media gallery widget.
31 add_filter( 'widget_media_gallery_instance_schema', array( $this, 'core_media_widget_compat' ) );
32 }
33
34 /**
35 * Updates the schema of the core gallery widget so we can save the
36 * fields that we add to Gallery Widgets, like `type` and `conditions`
37 *
38 * @param $schema The current schema for the core gallery widget
39 *
40 * @return array the updated schema
41 */
42 public function core_media_widget_compat( $schema ) {
43 $schema['type'] = array(
44 'type' => 'string',
45 'enum' => array_keys( $this->gallery_types ),
46 'description' => __( 'Type of gallery.', 'jetpack' ),
47 'default' => 'default',
48 );
49 return $schema;
50 }
51
52 /**
53 * Registers/enqueues the gallery settings admin js.
54 */
55 function wp_enqueue_media() {
56 if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) {
57 /**
58 * This only happens if we're not in Jetpack, but on WPCOM instead.
59 * This is the correct path for WPCOM.
60 */
61 wp_register_script( 'jetpack-gallery-settings', plugin_dir_url( __FILE__ ) . '../js/gallery-settings.js', array( 'media-views' ), '20180514' );
62 }
63
64 wp_enqueue_script( 'jetpack-gallery-settings' );
65 }
66
67 /**
68 * Outputs a view template which can be used with wp.media.template
69 */
70 function print_media_templates() {
71 $default_gallery_type = apply_filters( 'jetpack_default_gallery_type', 'default' );
72
73 ?>
74 <script type="text/html" id="tmpl-jetpack-gallery-settings">
75 <label class="setting">
76 <span><?php esc_html_e( 'Type', 'catch-gallery' ); ?></span>
77 <select class="type" name="type" data-setting="type">
78 <?php foreach ( $this->gallery_types as $value => $caption ) : ?>
79 <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $default_gallery_type ); ?>><?php echo esc_html( $caption ); ?></option>
80 <?php endforeach; ?>
81 </select>
82 </label>
83 </script>
84 <?php
85 }
86 }
87 endif;
88 new Catch_Gallery_Settings;
89
90 if ( ! function_exists( 'catch_gallery_default_options' ) ) :
91 /**
92 * Return array of default options
93 *
94 * @since 1.0
95 * @return array default options.
96 */
97 function catch_gallery_default_options( $option = null ) {
98 $default_options['carousel_enable'] = 1;
99 $default_options['carousel_background_color'] = 'black';
100 $default_options['carousel_display_exif'] = 1;
101 $default_options['comments_display'] = 1;
102 $default_options['fullsize_display'] = 1;
103
104 if ( null == $option ) {
105 return apply_filters( 'catch_gallery_options', $default_options );
106 } else {
107 return $default_options[ $option ];
108 }
109 }
110 endif; // catch_gallery_default_options
111
112 if ( ! function_exists( 'catch_gallery_get_options' ) ) :
113 /**
114 * Returns saved options
115 * @return array options
116 */
117 function catch_gallery_get_options() {
118 $defaults = catch_gallery_default_options();
119 $options = get_option( 'catch_gallery_options', $defaults );
120
121 return $options;
122 }
123 endif; // catch_gallery_get_options