| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: FakerPress |
| 4 |
* Plugin URI: https://fakerpress.com |
| 5 |
* Description: FakerPress is a clean way to generate fake data to your WordPress installation, great for developers who need testing |
| 6 |
* Version: 0.9.2 |
| 7 |
* Author: Gustavo Bordoni |
| 8 |
* Author URI: https://bordoni.me |
| 9 |
* Text Domain: fakerpress |
| 10 |
* License: GPL-2.0+ |
| 11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 12 |
* Domain Path: /languages |
| 13 |
* GitHub Plugin URI: https://github.com/bordoni/fakerpress |
| 14 |
*/ |
| 15 |
|
| 16 |
// Need to store this variable before leaving this file. |
| 17 |
define( '__FP_FILE__', __FILE__ ); |
| 18 |
|
| 19 |
/** |
| 20 |
* Version compares to PHP 8.0, so we can use namespaces, anonymous functions |
| 21 |
* and a lot of packages require 8.0, so... |
| 22 |
*/ |
| 23 |
if ( PHP_VERSION_ID < 80100 ) { |
| 24 |
if ( ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && is_admin() ) { |
| 25 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 26 |
|
| 27 |
if ( ! is_plugin_active( plugin_basename( __FP_FILE__ ) ) ) { |
| 28 |
// Register activation hook to handle PHP version incompatibility. |
| 29 |
return register_activation_hook( __FP_FILE__, '_fp_handle_activation' ); |
| 30 |
} |
| 31 |
|
| 32 |
_fp_handle_activation(); |
| 33 |
} |
| 34 |
} else { |
| 35 |
require_once dirname( __FP_FILE__ ) . '/src/functions/load.php'; |
| 36 |
// Add a second action to handle the case where Common is not loaded, we still want to let the user know what is happening. |
| 37 |
add_action( 'plugins_loaded', 'fakerpress_load_plugin', 50 ); |
| 38 |
} |
| 39 |
|
| 40 |
// Check for PHP version error flag and display notice. |
| 41 |
add_action( 'admin_notices', '_fp_display_activation_notice' ); |
| 42 |
|
| 43 |
/** |
| 44 |
* Handles plugin activation and version incompatibility. |
| 45 |
* |
| 46 |
* @since 0.8.0 |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
function _fp_handle_activation() { |
| 51 |
// Deactivate the plugin immediately upon activation. |
| 52 |
deactivate_plugins( plugin_basename( __FP_FILE__ ) ); |
| 53 |
|
| 54 |
// Get the plugin data to access version. |
| 55 |
$plugin_data = get_plugin_data( __FP_FILE__, false, false ); |
| 56 |
$version = ! empty( $plugin_data['Version'] ) ? $plugin_data['Version'] : 'generic'; |
| 57 |
|
| 58 |
// Set a version-specific option with the error type. |
| 59 |
update_option( "_fp_activation_error_{$version}", 'php_invalid' ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Displays PHP version notice if needed. |
| 64 |
* |
| 65 |
* @since 0.8.0 |
| 66 |
* |
| 67 |
* @return void |
| 68 |
*/ |
| 69 |
function _fp_display_activation_notice() { |
| 70 |
if ( ! is_admin() ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
if ( ! current_user_can( 'activate_plugins' ) ) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
// Get the plugin data to access version. |
| 79 |
$plugin_data = get_plugin_data( __FP_FILE__, false, false ); |
| 80 |
$version = ! empty( $plugin_data['Version'] ) ? $plugin_data['Version'] : 'generic'; |
| 81 |
|
| 82 |
// Check for any version-specific error. |
| 83 |
$option_name = "_fp_activation_error_{$version}"; |
| 84 |
$error_type = get_option( $option_name ); |
| 85 |
|
| 86 |
if ( ! $error_type ) { |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
if ( 'php_invalid' !== $error_type ) { |
| 91 |
return; |
| 92 |
} |
| 93 |
?> |
| 94 |
<div class="error"> |
| 95 |
<p> |
| 96 |
<?php |
| 97 |
printf( |
| 98 |
/* translators: %s: Plugin name */ |
| 99 |
esc_html__( '%s requires PHP 8.1 or higher, and the plugin has now disabled itself.', 'fakerpress' ), |
| 100 |
'<b>FakerPress</b>' |
| 101 |
); |
| 102 |
?> |
| 103 |
<br /> |
| 104 |
<?php esc_html_e( 'To allow better control over dates, advanced security improvements and performance gain.', 'fakerpress' ); ?> |
| 105 |
<br /> |
| 106 |
<?php esc_html_e( 'Contact your Hosting or your system administrator and ask for this Upgrade to version 8.1 of PHP.', 'fakerpress' ); ?> |
| 107 |
</p> |
| 108 |
</div> |
| 109 |
<?php |
| 110 |
|
| 111 |
// Clear the flag after displaying the notice, only delete the flag if the notice was displayed. |
| 112 |
delete_option( $option_name ); |
| 113 |
} |
| 114 |
|