Skip to content

Commit

Permalink
Merge branch 'issue-15'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeCulea committed May 14, 2018
2 parents 983cc51 + f3b8618 commit 37f36a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 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.1 - 9 Mai 2018
* [#15](https://github.com/BeAPI/acf-options-for-polylang/issues/15) : fix way requirements are checked to trigger on front / admin.

## 1.1.0 - Mar 2018
* True (complet) plugin.
* Add check for ACF 5.6.
Expand Down
14 changes: 9 additions & 5 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.0
Version: 1.1.1
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.0' );
define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_VERSION', '1.1.1' );
define( 'BEA_ACF_OPTIONS_FOR_POLYLANG_MIN_PHP_VERSION', '5.6' );

// Plugin URL and PATH
Expand All @@ -46,8 +46,12 @@
/** Autoload all the things \o/ */
require_once BEA_ACF_OPTIONS_FOR_POLYLANG_DIR . 'autoload.php';

\BEA\ACF_Options_For_Polylang\Requirements::get_instance();
add_action( 'plugins_loaded', 'bea_acf_options_for_polylang_load', 100 );
function bea_acf_options_for_polylang_load() {
$requirements = \BEA\ACF_Options_For_Polylang\Requirements::get_instance();
if ( ! $requirements->check_requirements() ) {
return;
}

add_action( 'bea_acf_options_for_polylang_load', function () {
\BEA\ACF_Options_For_Polylang\Main::get_instance();
} );
}
41 changes: 11 additions & 30 deletions classes/requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,45 @@ 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') );
$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 );
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'] );
add_action( 'admin_init', function () {
deactivate_plugins( BEA_ACF_OPTIONS_MAIN_FILE_DIR );
unset( $_GET['activate'] );
} );
}
}
}

0 comments on commit 37f36a5

Please sign in to comment.