Skip to content

Commit

Permalink
#23 fix check php version int main file
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeCulea committed Aug 3, 2018
1 parent 4460a1a commit 46ab0ed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.1.3 - 2 Aug 2018
* [#23](https://github.com/BeAPI/acf-options-for-polylang/pull/23) : Requirement to php5.6 whereas namespace are 5.3

## 1.1.2 - 31 Jul 2018
* [#22](https://github.com/BeAPI/acf-options-for-polylang/pull/22) : Fix error with repeater fields default values

Expand Down
13 changes: 11 additions & 2 deletions bea-acf-options-for-polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Plugin Name: BEA - ACF Options for Polylang
Version: 1.1.2
Version: 1.1.3
Plugin URI: https://github.com/BeAPI/acf-options-for-polylang
Description: Add ACF options page support for Polylang.
Author: Be API Technical team
Expand Down Expand Up @@ -34,7 +34,7 @@
}

// Plugin constants
define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_VERSION', '1.1.2' );
define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_VERSION', '1.1.3' );
define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION', '5.6' );

// Plugin URL and PATH
Expand All @@ -43,6 +43,15 @@
define( 'BEA_ACF_OPTIONS_MAIN_FILE_DIR', __FILE__ );
define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_PLUGIN_DIRNAME', basename( rtrim( dirname( __FILE__ ), '/' ) ) );

// Check PHP min version
if ( version_compare( PHP_VERSION, BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION, '<' ) ) {
require_once( BEA_PB_DIR . 'compat.php' );
// possibly display a notice, trigger error
add_action( 'admin_init', array( 'BEA\PB\Compatibility', 'admin_init' ) );
// stop execution of this file
return;
}

/** Autoload all the things \o/ */
require_once BEA_ACF_OPTIONS_FOR_POLYLANG_DIR . 'autoload.php';

Expand Down
6 changes: 0 additions & 6 deletions classes/requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class Requirements {
* @return bool
*/
public function check_requirements() {
if ( version_compare( PHP_VERSION, BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION, '<' ) ) {
$this->display_error( sprintf( __( 'Plugin Boilerplate require PHP version %s or greater to be activated. Your server is currently running PHP version %s.', 'bea-acf-options-for-polylang' ), BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION, PHP_VERSION ) );

return false;
}

if ( ! function_exists( 'acf' ) || ! function_exists( 'pll_current_language' ) ) {
$this->display_error( __( 'Advanced Custom Fields and Polylang are required plugins.', 'bea-acf-options-for-polylang' ) );

Expand Down
38 changes: 38 additions & 0 deletions compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php namespace BEA\ACF_Options_For_Polylang;

class Compatibility {
/**
* admin_init hook callback
*
* @since 0.1
*/
public static function admin_init() {
// Not on ajax
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}

// Check activation
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}

trigger_error( sprintf( 'ACF Options For Polylang requires PHP version %s or greater to be activated.', BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION ) );

// Deactive self
deactivate_plugins( BEA_ACF_OPTIONS_FOR_POLYLANG_DIR . 'bea-plugin-boilerplate.php' );

unset( $_GET['activate'] );

add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
}

/**
* Notify the user about the incompatibility issue.
*/
public static function admin_notices() {
echo '<div class="notice error is-dismissible">';
echo '<p>' . esc_html( sprintf( 'Plugin Boilerplate require PHP version %s or greater to be activated. Your server is currently running PHP version %s.', BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION, PHP_VERSION ) ) . '</p>';
echo '</div>';
}
}

0 comments on commit 46ab0ed

Please sign in to comment.