Gocodebox_Banner_Notifier::notification_test_check_plugin_version( bool $value, array $data )
Plugin version test.
Contents
Parameters Parameters
- $value
-
(bool) (Required) The current test value.
- $data
-
(array) (Required) Array from notification with plugin_file, comparison, and version to check.
Source Source
File: libraries/banner-notifications/src/notifications.php
function notification_test_check_plugin_version( $value, $data ) {
if ( ! is_array( $data ) ) {
return false;
}
if ( ! isset( $data[0] ) || ! isset( $data[1] ) || ! isset( $data[2] ) ) {
return false;
}
// TODO: Use get_plugin_data()?
$plugin_file = $data[0];
$comparison = $data[1];
$version = $data[2];
// Make sure data to check is in a good format.
if ( empty( $plugin_file ) || empty( $comparison ) || ! isset( $version ) ) {
return false;
}
// Get plugin data.
$full_plugin_file_path = WP_PLUGIN_DIR . '/' . $plugin_file;
if ( is_file( $full_plugin_file_path ) ) {
$plugin_data = get_plugin_data( $full_plugin_file_path, false, true );
}
// Return false if there is no plugin data.
if ( empty( $plugin_data ) || empty( $plugin_data['Version'] ) ) {
return false;
}
// Check version.
if ( version_compare( $plugin_data['Version'], $version, $comparison ) ) {
return true;
} else {
return false;
}
}
Expand full source code Collapse full source code View on GitHub