This repository has been archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple-photo-albums.php
210 lines (185 loc) · 4.77 KB
/
simple-photo-albums.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* Simple Photo Albums
*
* @package SimplePhotoAlbums
* @author Brady Vercher <[email protected]>
* @copyright Copyright (c) 2013, AudioTheme, LLC
* @license GPL-2.0+
*
* @wordpress-plugin
* Plugin Name: Simple Photo Albums
* Plugin URI: https://audiotheme.com/view/simple-photo-albums/?utm_source=wordpress-plugin&utm_medium=link&utm_content=simple-photo-albums-plugin-uri&utm_campaign=plugins
* Description: A shortcode for creating photo albums from a group of galleries.
* Version: 1.2.0
* Author: AudioTheme
* Author URI: https://audiotheme.com/?utm_source=wordpress-plugin&utm_medium=link&utm_content=simple-photo-albums-author-uri&utm_campaign=plugins
* License: GPL-2.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: simple-photo-albums
*/
/**
* Main plugin class.
*
* Sphoa = (S)imple (Pho)to (A)lbums
*
* @package SimplePhotoAlbums
* @author Brady Vercher <[email protected]>
* @since 1.0.0
*/
class Sphoa {
/**
* @access private
* @var Simple_Photo_Albums
*/
private static $instance;
/**
* Object to handle rendering of the photo albums.
*
* @access private
* @var Sphoa_Shortcode
*/
private $shortcode;
/**
* Main Simple_Photo_Albums instance.
*
* @since 1.0.0
*
* @return Simple_Photo_Albums
*/
public static function instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Constructor with initial setup.
*
* @access private
* @since 1.0.0
* @see Simple_Photo_Albums::instance();
*/
private function __construct() {
$this->includes();
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'init', array( $this, 'init' ) );
}
/**
* Retrieve a list of registered gallery scripts.
*
* Extensions should append an item to this array to add an option to the
* 'Gallery Script' dropdown on the media settings screen. Array keys will
* be used as the option/setting value, while the array value should be the
* name of the gallery script.
*
* <code>array( 'script-id' => 'Script Name );</code>
*
* @since 1.0.0
*
* @return array
*/
public function get_gallery_scripts() {
return apply_filters( 'simple_photo_albums_gallery_scripts', array() );
}
/**
* Retrieve the plugin settings.
*
* @since 1.0.0
*/
public function get_settings() {
$settings = wp_parse_args(
(array) get_option( 'simple_photo_albums' ),
array(
'gallery_script' => '',
)
);
return $settings;
}
/**
* Set the instance of the shortcode class to handle rendering.
*
* @since 1.0.0
*
* @param object $shortcode
*/
public function set_shortcode( $shortcode ) {
$this->shortcode = $shortcode;
}
/**
* Include files.
*
* @since 1.0.0
*/
private function includes() {
// Include the shortcode class.
require( plugin_dir_path( __FILE__ ) . 'includes/class-sphoa-shortcode.php' );
// Load default gallery scripts.
include( plugin_dir_path( __FILE__ ) . 'includes/jetpack-carousel.php' );
include( plugin_dir_path( __FILE__ ) . 'includes/magnific-popup.php' );
include( plugin_dir_path( __FILE__ ) . 'includes/swipebox.php' );
if ( is_admin() ) {
require( plugin_dir_path( __FILE__ ) . 'admin/includes/settings.php' );
}
}
/**
* Support localization for the plugin strings.
*
* @since 1.0.0
*/
public function load_textdomain() {
load_plugin_textdomain( 'simple-photo-albums' );
}
/**
* Set up plugin scripts and hooks.
*
* @since 1.0.0
*/
public function init() {
add_shortcode( 'simple_photo_album', array( $this->shortcode, 'shortcode' ) );
add_action( 'wp_print_footer_scripts', array( $this, 'print_scripts' ) );
}
/**
* Print JavaScript to display the galleries.
*
* @since 1.0.0
*/
public function print_scripts() {
$albums = $this->shortcode->get_albums();
$settings = $this->get_settings();
// Short-circuit execution if there aren't any albums or a gallery script hasn't been selected.
if ( empty( $albums ) || empty( $settings['gallery_script'] ) ) {
return;
}
// Prime the cache.
$ids = array();
foreach ( $albums as $gallery_id => $gallery ) {
if ( empty( $albums[ $gallery_id ]['attachment_ids'] ) ) {
continue;
}
$ids = array_merge( $ids, $albums[ $gallery_id ]['attachment_ids'] );
}
get_posts(
array(
'post_type' => 'attachment',
'post__in' => $ids,
'posts_per_page' => -1,
)
);
do_action( 'simple_photo_albums_print_footer_scripts', $albums );
}
}
/**
* Function to easily access the main plugin instance.
*
* @since 1.0.0
*
* @return Simple_Photo_Albums
*/
function sphoa() {
return Sphoa::instance();
}
// Get 'er started.
sphoa();
// Set the class for handling the shortcode.
sphoa()->set_shortcode( new Sphoa_Shortcode() );