-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check requirements and display error messages when needed
- Loading branch information
1 parent
d248ca2
commit 557b0b2
Showing
3 changed files
with
86 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,22 @@ | |
Author URI: https://beapi.fr | ||
Contributors: Maxime Culea | ||
---- | ||
Copyright 2017 Be API Technical team ([email protected]) | ||
Copyright 2018 Be API Technical team ([email protected]) | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
|
||
|
@@ -28,30 +43,11 @@ | |
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_CPT_AGENT_MIN_PHP_VERSION, '<' ) ) { | ||
require_once( BEA_CPT_AGENT_DIR . 'compat.php' ); | ||
|
||
// possibly display a notice, trigger error | ||
add_action( 'admin_init', array( 'BEA\CPT_Agent\Compatibility', 'admin_init' ) ); | ||
|
||
// stop execution of this file | ||
return; | ||
} | ||
|
||
/** | ||
* Autoload all the things \o/ | ||
*/ | ||
/** Autoload all the things \o/ */ | ||
require_once BEA_ACF_OPTIONS_FOR_POLYLANG_DIR . 'autoload.php'; | ||
|
||
BEA\ACF_Options_For_Polylang\Plugin::get_instance(); | ||
\BEA\ACF_Options_For_Polylang\Requirements::get_instance(); | ||
|
||
/** | ||
* Load at plugins loaded to ensure ACF and Polylang are used | ||
* | ||
* @since 1.0.2 | ||
* @author Maxime CULEA | ||
*/ | ||
add_action( 'plugins_loaded', function () { | ||
add_action( 'bea_acf_options_for_polylang_load', function () { | ||
\BEA\ACF_Options_For_Polylang\Main::get_instance(); | ||
} ); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php namespace BEA\ACF_Options_For_Polylang; | ||
|
||
class Requirements { | ||
|
||
use Singleton; | ||
|
||
public $satsify_requiremeents = true; | ||
|
||
/** | ||
* @since 1.0.0 | ||
*/ | ||
public function init() { | ||
add_action( 'admin_init', [ $this, 'check_requirements' ] ); | ||
} | ||
|
||
/** | ||
* All about requirements checks | ||
* | ||
* @return bool | ||
*/ | ||
public function check_requirements() { | ||
// Not on ajax | ||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | ||
do_action( 'bea_acf_options_for_polylang_load' ); | ||
return true; | ||
} | ||
|
||
// Check activation | ||
if ( ! current_user_can( 'activate_plugins' ) ) { | ||
do_action( 'bea_acf_options_for_polylang_load' ); | ||
return true; | ||
} | ||
|
||
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') ); | ||
return false; | ||
} | ||
|
||
if ( '5.6.0' > acf()->version ) { | ||
$this->display_error( __( 'Advanced Custom Fields should be on version 5.6.0 or above.', 'bea-acf-options-for-polylang' ) ); | ||
return false; | ||
}; | ||
|
||
do_action( 'bea_acf_options_for_polylang_load' ); | ||
return true; | ||
} | ||
|
||
// Display message and handle errors | ||
public function display_error( $message ) { | ||
$this->satsify_requiremeents = false; | ||
|
||
trigger_error( $message ); | ||
|
||
add_action( 'admin_notices', function () use ($message) { | ||
printf('<div class="notice error is-dismissible"><p>%s</p></div>', $message ); | ||
} ); | ||
|
||
// Deactive self | ||
deactivate_plugins( BEA_ACF_OPTIONS_MAIN_FILE_DIR ); | ||
unset( $_GET['activate'] ); | ||
} | ||
} |