-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcustom-post-type-date-archives.php
237 lines (209 loc) · 7.04 KB
/
custom-post-type-date-archives.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
/*
Plugin Name: Custom Post Type Date Archives
Version: 2.7.0
Plugin URI: https://wordpress.org/plugins/custom-post-type-date-archives
Description: This plugin allows you to add date archives to custom post types. It also adds extra options to the archive, calendar and recent posts widget.
Author: keesiemijer
Author URI: https://keesiemeijer.wordpress.com
Text Domain: custom-post-type-date-archives
Domain Path: languages
License: GPL v2
Custom Post Type Date Archives
Copyright 2014 Kees Meijer (email : keesie.meijer@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. You may NOT assume that you can use any other version of the GPL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Custom_Post_Type_Date_Archives' ) ) :
/**
* Main Custom_Post_Type_Date_Archives Class
*
* @since 1.0
*/
final class Custom_Post_Type_Date_Archives {
/**
* Plugin instance.
*
* @var Plugin instance
* @since 1.0
*/
private static $instance;
/**
* Post type.
*
* @var Post type object
* @since 1.0
*/
public $post_type;
/**
* Rewrite object
*
* @var Rewrite object
* @since 1.0
*/
public $rewrite;
/**
* Replace default WP core widgets.
*
* @since 2.3.2
* @var bool
*/
public $replace_widgets = true;
/**
* Main Custom_Post_Type_Date_Archives Instance
*
* Insures that only one instance of CS_Custom_Post_Type_Date_Archives exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0
* @uses Custom_Post_Type_Date_Archives::setup_constants() Setup the constants needed
* @uses Custom_Post_Type_Date_Archives::includes() Include the required files
* @uses Custom_Post_Type_Date_Archives::load_textdomain() load the language files
* @return Custom_Post_Type_Date_Archives instance.
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Custom_Post_Type_Date_Archives ) ) {
self::$instance = new Custom_Post_Type_Date_Archives;
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->load_textdomain();
self::$instance->post_type = new CPTDA_Post_Types();
if ( class_exists( 'WP_REST_Controller' ) ) {
$cptda_rest_api_calendar = new CPTDA_Rest_API_Calendar();
$cptda_rest_api_calendar->init();
$cptda_rest_api_recent_post = new CPTDA_Rest_API_Recent_Posts();
$cptda_rest_api_recent_post->init();
$cptda_rest_api_archives = new CPTDA_Rest_API_Archives();
$cptda_rest_api_archives->init();
}
if ( is_admin() ) {
new CPTDA_Admin();
}
}
return self::$instance;
}
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0
* @access protected
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'content-shortcuts' ), '1.0' );
}
/**
* Disable unserializing of the class
*
* @since 1.0
* @access protected
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'content-shortcuts' ), '1.0' );
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0
* @return void
*/
private function setup_constants() {
// Plugin version
if ( ! defined( 'CPT_DATE_ARCHIVES_VERSION' ) ) {
define( 'CPT_DATE_ARCHIVES_VERSION', '2.7.0' );
}
// Plugin Folder Path
if ( ! defined( 'CPT_DATE_ARCHIVES_PLUGIN_DIR' ) ) {
define( 'CPT_DATE_ARCHIVES_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL
if ( ! defined( 'CPT_DATE_ARCHIVES_PLUGIN_URL' ) ) {
define( 'CPT_DATE_ARCHIVES_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File
if ( ! defined( 'CPT_DATE_ARCHIVES_PLUGIN_FILE' ) ) {
define( 'CPT_DATE_ARCHIVES_PLUGIN_FILE', __FILE__ );
}
}
/**
* Include required files
*
* @access private
* @since 1.0
* @return void
*/
private function includes() {
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/cpt-rewrite.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/functions.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/calendar.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/archives.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/deprecated.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/link-template.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/post_type.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/widgets.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/admin-settings.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/utils/recent-posts.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/utils/archives.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/utils/calendar.php';
if ( class_exists( 'WP_REST_Controller' ) ) {
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/editor-blocks.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/rest-api/class-rest-api-calendar.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/rest-api/class-rest-api-recent-posts.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/rest-api/class-rest-api-archives.php';
}
if ( ! is_admin() ) {
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/rewrite.php';
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/query.php';
} else {
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/admin.php';
}
require_once CPT_DATE_ARCHIVES_PLUGIN_DIR . 'includes/install.php';
}
/**
* Loads the plugin language files
*
* @access public
* @since 1.0
* @return void
*/
public function load_textdomain() {
$dir = dirname( plugin_basename( CPT_DATE_ARCHIVES_PLUGIN_FILE ) ) . '/languages/';
load_plugin_textdomain( 'custom-post-type-date-archives', '', $dir );
}
}
endif;
/**
* Returns the Custom_Post_Type_Date_Archives instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $instance = cptda_date_archives(); ?>
*
* @since 1.0
* @return object Custom_Post_Type_Date_Archives Instance.
*/
function cptda_date_archives() {
return Custom_Post_Type_Date_Archives::instance();
}
// Instantiate plugin
cptda_date_archives();