1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Class to include and init default templates. |
4
|
|
|
* The templates are no longer an extension and are built in and included by default |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
if ( ! class_exists( 'FooGallery_Default_Templates' ) ) { |
8
|
|
|
|
9
|
|
|
define( 'FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL', plugin_dir_url( __FILE__ ) ); |
10
|
|
|
define( 'FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH', plugin_dir_path( __FILE__ ) ); |
11
|
|
|
|
12
|
|
|
define( 'FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL', FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'shared/' ); |
13
|
|
|
define( 'FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_PATH', FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'shared/' ); |
14
|
|
|
|
15
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'functions.php' ); |
16
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'default/class-default-gallery-template.php' ); |
17
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'image-viewer/class-image-viewer-gallery-template.php' ); |
18
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'justified/class-justified-gallery-template.php' ); |
19
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'masonry/class-masonry-gallery-template.php' ); |
20
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'simple-portfolio/class-simple-portfolio-gallery-template.php' ); |
21
|
|
|
require_once( FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_PATH . 'thumbnail/class-thumbnail-gallery-template.php' ); |
22
|
|
|
|
23
|
|
|
class FooGallery_Default_Templates { |
|
|
|
|
24
|
|
|
|
25
|
|
|
function __construct() { |
26
|
|
|
new FooGallery_Default_Gallery_Template(); |
27
|
|
|
new FooGallery_Image_Viewer_Gallery_Template(); |
28
|
|
|
new FooGallery_Justified_Gallery_Template(); |
29
|
|
|
new FooGallery_Masonry_Gallery_Template(); |
30
|
|
|
new FooGallery_Simple_Portfolio_Gallery_Template(); |
31
|
|
|
new FooGallery_Thumbnail_Gallery_Template(); |
32
|
|
|
|
33
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/*** |
37
|
|
|
* Enqueue the assets needed by the default templates |
38
|
|
|
* @param $hook_suffix |
39
|
|
|
*/ |
40
|
|
|
function enqueue_assets( $hook_suffix ){ |
|
|
|
|
41
|
|
|
if( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) { |
42
|
|
|
$screen = get_current_screen(); |
43
|
|
|
|
44
|
|
|
if ( is_object( $screen ) && FOOGALLERY_CPT_GALLERY == $screen->post_type ){ |
45
|
|
|
|
46
|
|
|
// Register, enqueue scripts and styles here |
47
|
|
|
wp_enqueue_style( 'foogallery-core-admin-settings', FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_SHARED_URL . 'css/admin-foogallery.css', array(), FOOGALLERY_VERSION ); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.