forked from FancyThemes/wp-advanced-excerpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced-excerpt.php
211 lines (168 loc) · 5.69 KB
/
advanced-excerpt.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
211
<?php
/**
* The Advanced Excerpt plugin loader.
*
* Control the appearance of WordPress post excerpts.
*
* @package Advanced_Excerpt
*/
/**
* Plugin Name: Advanced Excerpt
* Plugin URI: http://wordpress.org/plugins/advanced-excerpt/
* Description: Control the appearance of WordPress post excerpts.
* Version: 4.3
* Author: Chris Aprea
* Author URI: http://twitter.com/chrisaprea
* License: GNU General Public License v3 or later
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Advanced Excerpt loader class.
*/
final class Advanced_Excerpt_Loader {
/** Magic *****************************************************************/
/**
* Advanced Excerpt uses many variables, several of which can be filtered to
* customize the way it operates. Most of these variables are stored in a
* private array that gets updated with the help of PHP magic methods.
*
* This is a precautionary measure, to avoid potential errors produced by
* unanticipated direct manipulation of Advanced Excerpt's run-time data.
*
* @see Advanced_Excerpt::setup_globals()
* @var array
*/
private $data;
/** Singleton *************************************************************/
/**
* Main Advanced Excerpt Instance
*
* Insures that only one instance of Advanced Excerpt exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @staticvar object $instance
* @return The one true Advanced Excerpt Loader
*/
public static function instance() {
// Store the instance locally to avoid private static replication.
static $instance = null;
// Only run these methods if they haven't been ran previously.
if ( null === $instance ) {
$instance = new Advanced_Excerpt_Loader;
$instance->setup_globals();
$instance->includes();
$instance->setup_actions();
}
// Always return the instance.
return $instance;
}
/** Magic Methods *********************************************************/
/**
* A dummy constructor to prevent Advanced Excerpt from being loaded more than once.
*/
private function __construct() { /* Do nothing here */ }
/**
* A dummy magic method to prevent Advanced Excerpt from being cloned
*/
public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'advanced-excerpt' ), '1.0.0' ); }
/**
* A dummy magic method to prevent Advanced Excerpt from being unserialized
*/
public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'advanced-excerpt' ), '1.0.0' ); }
/**
* Magic method for checking the existence of a certain custom field
*/
public function __isset( $key ) { return isset( $this->data[$key] ); }
/**
* Magic method for getting Advanced Excerpt variables
*/
public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; }
/**
* Magic method for setting Advanced Excerpt variables
*/
public function __set( $key, $value ) { $this->data[$key] = $value; }
/**
* Magic method for unsetting Advanced Excerpt variables
*/
public function __unset( $key ) { if ( isset( $this->data[$key] ) ) unset( $this->data[$key] ); }
/**
* Magic method to prevent notices and errors from invalid method calls
*/
public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; }
/** Private Methods *******************************************************/
/**
* Set some smart defaults to class variables.
*/
private function setup_globals() {
$this->version = '4.3.0';
// Setup some base path and URL information.
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
$this->plugin_dir = plugin_dir_path( $this->file );
$this->plugin_url = plugin_dir_url( $this->file );
// Includes.
$this->inc_dir = $this->plugin_dir . 'inc/';
// Classes.
$this->classes = $this->inc_dir . 'classes/';
// Functions.
$this->functions = $this->inc_dir . 'functions/';
// Assets.
$this->assets_dir = $this->plugin_dir . 'assets/';
$this->assets_url = $this->plugin_url . 'assets/';
// Templates.
$this->templates = $this->plugin_dir . 'template/';
// CSS folder.
$this->css_dir = $this->assets_dir . 'css/';
$this->css_url = $this->assets_url . 'css/';
// Images folder.
$this->image_dir = $this->assets_dir . 'img/';
$this->image_url = $this->assets_url . 'img/';
// JS folder.
$this->js_dir = $this->assets_dir . 'js/';
$this->js_url = $this->assets_url . 'js/';
}
/**
* Include required files.
*/
private function includes() {
// Main plugin class.
$this->main = require $this->classes . 'class-advanced-excerpt.php';
// Global functions.
require $this->functions . 'functions.php';
}
/**
* Setup the default hooks and actions.
*/
private function setup_actions() {
// Attach functions to the activate / deactive hooks.
add_action( 'activate_' . $this->basename, array( $this, 'activate' ) );
add_action( 'deactivate_' . $this->basename, array( $this, 'deactivate' ) );
}
/** Public Methods *******************************************************/
/**
* Plugin activation.
*/
public function activate() {
}
/**
* Plugin deactivation.
*/
public function deactivate() {
}
}
/**
* The main function responsible for returning the one true Advanced Excerpt Instance
* to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $advanced_excerpt = advanced_excerpt(); ?>
*
* @return The one true Advanced Excerpt Instance
*/
function advanced_excerpt() {
return Advanced_Excerpt_Loader::instance();
}
$GLOBALS['advanced_excerpt'] = advanced_excerpt();