-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprintmyblog.php
271 lines (253 loc) · 9.92 KB
/
printmyblog.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?php //phpcs:disable Files.SideEffects.FoundWithSymbols -- it's normal for plugin main files to be loose with that requirement.
/**
* @package PrintMyBlog
*
* @wordpress-plugin
* Plugin Name: Print My Blog
* Plugin URI: https://printmy.blog
* Description: Make printing your blog easy and impressive. For you & your visitors. One post or thousands.
* Author: Michael Nelson
* Author URI: https://printmy.blog
* Version: 3.27.6
* Requires at least: 4.7
* Requires PHP: 5.4
* Text Domain: print-my-blog
*/
if (! defined('PMB_MIN_PHP_VER_REQUIRED')) {
define('PMB_MIN_PHP_VER_REQUIRED', '5.4.0');
}
if (! defined('PMB_MIN_WP_VER_REQUIRED')) {
define('PMB_MIN_WP_VER_REQUIRED', '4.7');
}
global $wp_version;
// make sure another version of PMB isn't installed
if (defined('PMB_VERSION')) {
/**
* Function that says another version of PMB is already active.
*
* @return void
*/
function pmb_already_active()
{
?>
<div class="error">
<p>
<?php
esc_html_e(
'We’re sorry, but you have another version of Print My Blog active. Only one can be active at a time. Please deactivate one.',
'print-my-blog'
);
?>
</p>
</div>
<?php
}
add_action('admin_notices', 'pmb_already_active', 1, 0);
// then make sure the minimum version of PHP is being used
} elseif (version_compare(PHP_VERSION, PMB_MIN_PHP_VER_REQUIRED, '<')) {
/**
* Function that says PHP version isn't high enough to run PMB.
*
* @return void
*/
function pmb_minimum_php_version_error()
{
?>
<div class="error">
<p>
<?php
printf(
// translators: 1: version number, 2: version number, 3: HTML line break, 4: website address
esc_html__(
'We’re sorry, but Print My Blog requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
'print-my-blog'
),
esc_html(PMB_MIN_PHP_VER_REQUIRED),
PHP_VERSION,
'<br/>',
'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
);
?>
</p>
</div>
<?php
}
add_action('admin_notices', 'pmb_minimum_php_version_error', 1, 0);
} elseif (
version_compare(
// first account for wp_version being pre-release
// (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
strpos($wp_version, '-') > 0 ?
substr($wp_version, 0, strpos($wp_version, '-')) :
$wp_version,
PMB_MIN_WP_VER_REQUIRED,
'<'
)
) {
/**
* Function that expresses WP version isn't high enough to run PMB.
*
* @return void
*/
function pmb_minimum_wp_version_error()
{
global $wp_version;
?>
<div class="error">
<p>
<?php
printf(
// translators: 1: version number, 2: version number, 3: HTML line break, 4: URL
esc_html__(
'We’re sorry, but Print My Blog requires WordPress %1$s. You are using %2$s.%3$sFor information on how to update, please see %4$s.',
'print-my-blog'
),
esc_html(PMB_MIN_WP_VER_REQUIRED),
esc_html($wp_version),
'<br/>',
'<a href="https://wordpress.org/support/article/updating-wordpress/">https://wordpress.org/support/article/updating-wordpress/</a>'
);
?>
</p>
</div>
<?php
}
add_action('admin_notices', 'pmb_minimum_wp_version_error', 1, 0);
} else {
// it's all good! start bootstraping PMB.
define('PMB_VERSION', '3.27.6');
define('PMB_DIR', wp_normalize_path(__DIR__) . '/');
define('PMB_MAIN_FILE', __FILE__);
define('PMB_TEMPLATES_DIR', PMB_DIR . 'templates/');
define('PMB_NO_THEME_DIR', PMB_TEMPLATES_DIR . 'no_theme/');
define('PMB_VENDOR_DIR', PMB_DIR . 'vendor/');
define('PMB_ADMIN_CAP', 'read_private_posts');
define('PMB_BASENAME', plugin_basename(PMB_MAIN_FILE));
define('PMB_DIRNAME', dirname(PMB_BASENAME));
define('PMB_ADMIN_PAGE_SLUG', 'print-my-blog-now');
define('PMB_ADMIN_PAGE_PATH', '/admin.php?page=' . PMB_ADMIN_PAGE_SLUG);
define('PMB_ADMIN_PROJECTS_PAGE_SLUG', 'print-my-blog-projects');
define('PMB_ADMIN_PROJECTS_PAGE_PATH', '/admin.php?page=' . PMB_ADMIN_PROJECTS_PAGE_SLUG);
define('PMB_ADMIN_SETTINGS_PAGE_SLUG', 'print-my-blog-settings');
define('PMB_ADMIN_SETTINGS_PAGE_PATH', '/admin.php?page=' . PMB_ADMIN_SETTINGS_PAGE_SLUG);
define('PMB_ADMIN_HELP_PAGE_SLUG', 'print-my-blog-help');
define('PMB_ADMIN_DESIGNS_PAGE_SLUG','print-my-blog-designs');
define('PMB_ADMIN_DESIGNS_PAGE_PATH', '/admin.php?page=' . PMB_ADMIN_DESIGNS_PAGE_SLUG);
define('PMB_ADMIN_HELP_PAGE_PATH', '/admin.php?page=' . PMB_ADMIN_HELP_PAGE_SLUG);
define('PMB_DESIGNS_DIR', PMB_DIR . 'designs/');
define('TWINE_MAIN_FILE', PMB_MAIN_FILE);
define('PMB_SUPPORT_EMAIL', '[email protected]');
/* WPML support */
if (! defined('WPML_LOAD_API_SUPPORT')) {
define('WPML_LOAD_API_SUPPORT', true);
}
/**
* Adds a wp-option to indicate that PMB has been activated via the WP admin plugins page.
* This can be used to do initial plugin installation or redirect the user to the setup page.
*/
function pmb_plugin_activation()
{
update_option('pmb_activation', true, false);
}
register_activation_hook(PMB_MAIN_FILE, 'pmb_plugin_activation');
define('PMB_PRINTPAGE_SLUG', 'print-my-blog');
require_once 'bootstrap.php';
if (function_exists('pmb_fs')) {
pmb_fs()->set_basename(true, __FILE__);
} else {
if (! function_exists('pmb_fs')) {
/**
* Initialize Freemius' code.
* @return Freemius
* @throws Freemius_Exception
*/
function pmb_fs()
{
global $pmb_fs;
if (! isset($pmb_fs)) {
// Include Freemius SDK.
require_once dirname(__FILE__) . '/freemius/start.php';
// don't ask to opt in if it's a tastewp site
$site_url = get_site_url();
$is_demo_site = (bool)preg_match('~https:\/\/([^\.]*\.[^-]*-tastewp\.com|[^.]*.instawp.xyz)~',$site_url);
$pmb_fs = fs_dynamic_init(
array(
'id' => '5396',
'slug' => 'print-my-blog',
'premium_slug' => 'print-my-blog-pro',
'type' => 'plugin',
'public_key' => 'pk_0443e9596f0e906d282bf05b115dd',
'is_premium' => true,
'premium_suffix' => 'Pro',
// If your plugin is a serviceware, set this option to false.
'has_premium_version' => true,
'has_addons' => false,
'has_paid_plans' => true,
'menu' => array(
'slug' => 'print-my-blog-projects',
'first-path' => 'admin.php?page=print-my-blog-now&welcome=1',
'contact' => false,
'support' => false,
),
'anonymous_mode' => $is_demo_site
)
);
}
return $pmb_fs;
}
// Init Freemius.
pmb_fs();
// Signal that SDK was initiated.
do_action('pmb_fs_loaded');
}
}
// Disable the active theme if generating a PDF.
// This needs to be done super early
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- we're just looking, not processing or saving etc.
if ((
defined('DOING_AJAX') ||
isset($_REQUEST[PrintMyBlog\controllers\Frontend::PMB_AJAX_INDICATOR])
) &&
isset($_REQUEST['action'], $_REQUEST['format']) &&
$_REQUEST['action'] === PrintMyBlog\controllers\Frontend::PMB_PROJECT_STATUS_ACTION) {
$use_theme = true;
if(isset($_REQUEST[PrintMyBlog\controllers\Frontend::PMB_USE_THEME]) && $_REQUEST[PrintMyBlog\controllers\Frontend::PMB_USE_THEME] === '0'){
$use_theme = false;
}
if ($use_theme) {
// ha, they say to use the theme. So don't change anything
return;
}
// unregister the theme once we have a moment to override it
add_action(
'template_redirect',
function(){
// We don't want the theme interfering. Kill it.
add_filter('wp_using_themes', '__return_false');
},
9
);
// some plugins and theme still assume a theme, so give them the directory of our bundled fake theme
add_filter(
'template_directory',
function () {
return PMB_NO_THEME_DIR;
},
100
);
add_filter(
'stylesheet_directory',
function () {
return PMB_NO_THEME_DIR;
},
100
);
add_action(
'init',
function () {
remove_action('wp_head', 'wp_custom_css_cb', 11);
remove_action('wp_head', 'wp_custom_css_cb', 101);
}
);
}
}