-
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathfakerpress.php
More file actions
113 lines (98 loc) · 3.41 KB
/
fakerpress.php
File metadata and controls
113 lines (98 loc) · 3.41 KB
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
<?php
/**
* Plugin Name: FakerPress
* Plugin URI: https://fakerpress.com
* Description: FakerPress is a clean way to generate fake data to your WordPress installation, great for developers who need testing
* Version: 0.9.0
* Author: Gustavo Bordoni
* Author URI: https://bordoni.me
* Text Domain: fakerpress
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/bordoni/fakerpress
*/
// Need to store this variable before leaving this file.
define( '__FP_FILE__', __FILE__ );
/**
* Version compares to PHP 8.0, so we can use namespaces, anonymous functions
* and a lot of packages require 8.0, so...
*/
if ( PHP_VERSION_ID < 80100 ) {
if ( ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && is_admin() ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( ! is_plugin_active( plugin_basename( __FP_FILE__ ) ) ) {
// Register activation hook to handle PHP version incompatibility.
return register_activation_hook( __FP_FILE__, '_fp_handle_activation' );
}
_fp_handle_activation();
}
} else {
require_once dirname( __FP_FILE__ ) . '/src/functions/load.php';
// Add a second action to handle the case where Common is not loaded, we still want to let the user know what is happening.
add_action( 'plugins_loaded', 'fakerpress_load_plugin', 50 );
}
// Check for PHP version error flag and display notice.
add_action( 'admin_notices', '_fp_display_activation_notice' );
/**
* Handles plugin activation and version incompatibility.
*
* @since 0.8.0
*
* @return void
*/
function _fp_handle_activation() {
// Deactivate the plugin immediately upon activation.
deactivate_plugins( plugin_basename( __FP_FILE__ ) );
// Get the plugin data to access version.
$plugin_data = get_plugin_data( __FP_FILE__, false, false );
$version = ! empty( $plugin_data['Version'] ) ? $plugin_data['Version'] : 'generic';
// Set a version-specific option with the error type.
update_option( "_fp_activation_error_{$version}", 'php_invalid' );
}
/**
* Displays PHP version notice if needed.
*
* @since 0.8.0
*
* @return void
*/
function _fp_display_activation_notice() {
if ( ! is_admin() ) {
return;
}
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
// Get the plugin data to access version.
$plugin_data = get_plugin_data( __FP_FILE__, false, false );
$version = ! empty( $plugin_data['Version'] ) ? $plugin_data['Version'] : 'generic';
// Check for any version-specific error.
$option_name = "_fp_activation_error_{$version}";
$error_type = get_option( $option_name );
if ( ! $error_type ) {
return;
}
if ( 'php_invalid' !== $error_type ) {
return;
}
?>
<div class="error">
<p>
<?php
printf(
/* translators: %s: Plugin name */
esc_html__( '%s requires PHP 8.1 or higher, and the plugin has now disabled itself.', 'fakerpress' ),
'<b>FakerPress</b>'
);
?>
<br />
<?php esc_html_e( 'To allow better control over dates, advanced security improvements and performance gain.', 'fakerpress' ); ?>
<br />
<?php esc_html_e( 'Contact your Hosting or your system administrator and ask for this Upgrade to version 8.1 of PHP.', 'fakerpress' ); ?>
</p>
</div>
<?php
// Clear the flag after displaying the notice, only delete the flag if the notice was displayed.
delete_option( $option_name );
}