-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheight-day-week.php
205 lines (168 loc) · 5.36 KB
/
eight-day-week.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
<?php
/**
* Plugin Name: Eight Day Week
* Plugin URI: https://github.com/10up/eight-day-week
* Description: Optimize publication workflows by using WordPress as your print CMS.
* Version: 1.2.4
* Requires at least: 6.5
* Requires PHP: 7.4
* Author: 10up
* Author URI: https://10up.com
* License: GPL-2.0-or-later
* Text Domain: eight-day-week-print-workflow
*
* @package Eight_Day_Week
*/
/**
* Copyright (c) 2015 10up (email : [email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Load vip compat functions.
require_once __DIR__ . '/vip-compat.php';
// Load plugin loader.
require_once __DIR__ . '/plugins.php';
// Useful global constants.
define( 'EDW_VERSION', '1.2.4' );
define( 'EDW_URL', Eight_Day_Week\plugins_url( __FILE__ ) );
define( 'EDW_PATH', __DIR__ . '/' );
define( 'EDW_INC', EDW_PATH . 'includes/' );
// Allow override from wp-config (et al).
if ( ! defined( 'EDW_PRODUCTION' ) ) {
// If on VIP, let VIP define production state.
if ( defined( 'WPCOM_IS_VIP_ENV' ) ) {
define( 'EDW_PRODUCTION', WPCOM_IS_VIP_ENV );
} else {
// Otherwise, assume production.
define( 'EDW_PRODUCTION', true );
}
}
// More specific constants, used throughout.
define( 'EDW_PRINT_ISSUE_CPT', 'print-issue' );
define( 'EDW_ADMIN_MENU_SLUG', 'edit.php?post_type=' . EDW_PRINT_ISSUE_CPT );
define( 'EDW_SECTION_CPT', 'pi-section' );
define( 'EDW_ARTICLE_STATUS_TAX', 'pi-article-status' );
define( 'EDW_AJAX_NONCE_SLUG', 'edw_ajax_nonce' );
/**
* Get the minimum version of PHP required by this plugin.
*
* @return string Minimum version required.
*/
function edw_minimum_php_requirement() {
return '7.4';
}
/**
* Checks whether PHP installation meets the minimum requirements
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function edw_site_meets_php_requirements() {
return version_compare( phpversion(), edw_minimum_php_requirement(), '>=' );
}
if ( ! edw_site_meets_php_requirements() ) {
add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'Eight Day Week requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'eight-day-week-print-workflow' ),
esc_html( edw_minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}
/**
* Calls the setup function of any namespaced files
* in the includes/functions dir
*/
function edw_bootstrap() {
$map = edw_build_namespace_map();
if ( ! $map ) {
return;
}
$core_file = EDW_INC . 'functions' . DIRECTORY_SEPARATOR . 'core.php';
if ( ! isset( $map[ $core_file ] ) ) {
return;
}
require_once $core_file;
Eight_Day_Week\Core\setup();
unset( $map[ $core_file ] );
foreach ( $map as $file => $namespace ) {
// Play nice.
try {
require_once $file;
$setup = $namespace . '\setup';
// Allow files *not* to have a setup function.
if ( function_exists( $setup ) ) {
$setup();
do_action( $namespace . '\setup' );
}
} catch ( \Exception $e ) {
// Do nothing
}
}
}
// Hook before init so the plugin has its own "init" action.
add_action( 'after_setup_theme', 'edw_bootstrap' );
/**
* Builds a map of files + namespaces
*
* @return array Map of files => namespace
*/
function edw_build_namespace_map() {
$dir = EDW_INC . 'functions';
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD
);
$map = array();
foreach ( $iterator as $file ) {
if ( 'php' !== $file->getExtension() ) {
continue;
}
// Get just the file name, e.g. "core".
$file_name = str_replace( '.php', '', $file->getFileName() );
// Convert dashes to spaces.
$spaced = str_replace( '-', ' ', $file_name );
// So that ucwords will work.
$capitalized = ucwords( $spaced );
// Get the "end" namespace.
$tip_of_the_iceberg = str_replace( ' ', '_', $capitalized );
$path = $file->getPathInfo()->getPathname();
if ( $dir !== $path ) {
$sub_directory = str_replace( $dir . DIRECTORY_SEPARATOR, '', $path );
// Convert slashes to spaces.
$capitalized = ucwords( str_replace( DIRECTORY_SEPARATOR, ' ', $sub_directory ) );
$tip_of_the_iceberg = str_replace( ' ', '\\', $capitalized ) . '\\' . $tip_of_the_iceberg;
}
// Add the namespace prefix + convert spaces to underscores for the final namespace.
$namespace = '\Eight_Day_Week\\' . $tip_of_the_iceberg;
// Add it all the map.
$map[ $file->getPathname() ] = $namespace;
}
return apply_filters( 'edw_files_to_load', $map );
}