This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Add a notice when requirements aren’t met #75
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,69 @@ | ||
<?php | ||
|
||
class Gutenberg_Ramp_Compatibility_Check { | ||
|
||
/** | ||
* Gutenberg Compatibility should only be checked in WordPress < 5.0, | ||
* because Core 5.0 and Gutenberg Plugin < 4.1.0 are not compatible anyway, | ||
* and Gutenberg_Ramp_Compatibility_Check is only needed to check for Gutenberg Plugin < 3.5.0 | ||
*/ | ||
public static function should_check_compatibility() { | ||
|
||
return apply_filters( 'gutenberg_ramp_should_check_compatibility', version_compare( $GLOBALS['wp_version'], '5.0', '<' ) ); | ||
} | ||
|
||
public static function should_display_message() { | ||
|
||
$gutenberg_version = static::get_gutenberg_version(); | ||
|
||
/** | ||
* If no Gutenberg version is found, don't display a notice | ||
* Because this class only cares about a specific condition ( GB < 3.5 ) | ||
*/ | ||
if ( false === $gutenberg_version ) { | ||
return false; | ||
} | ||
|
||
return version_compare( $gutenberg_version, '3.5', '<' ); | ||
} | ||
|
||
public static function get_gutenberg_version() { | ||
|
||
$gutenberg_plugin_path = gutenberg_ramp_get_validated_gutenberg_load_path(); | ||
if ( false === $gutenberg_plugin_path ) { | ||
return false; | ||
} | ||
|
||
$gutenberg_data = get_plugin_data( $gutenberg_plugin_path, false, false ); | ||
|
||
if ( empty( $gutenberg_data['Version'] ) ) { | ||
return false; | ||
} | ||
|
||
return $gutenberg_data['Version']; | ||
} | ||
|
||
|
||
// The backup sanity check, in case the plugin is activated in a weird way, | ||
// or the versions change after activation. | ||
public function maybe_display_notice() { | ||
|
||
if ( self::should_display_message() ) { | ||
add_action( 'admin_notices', [ $this, 'display_notice' ] ); | ||
} | ||
} | ||
|
||
public function display_notice() { | ||
|
||
?> | ||
<div class="notice notice-error is-dismissible"> | ||
<p> | ||
<strong> <?php esc_html_e( 'Gutenberg Ramp functionality is disabled' ); ?></strong> <br/> | ||
<?php esc_html_e( 'The version of Gutenberg you have installed is not compatible with Gutenberg Ramp. To restore Ramp functionality, please upgrade to Gutenberg 4.1 (or newer) or WordPress 5.0 (or newer).', 'gutenberg-ramp' ) ?> | ||
</p> | ||
</div> | ||
<?php | ||
|
||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we skip loading the rest of Ramp if the versions don't match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary. If Ramp isn't compatible - it doesn't do anything apart from attaching itself to 2 filters that will never be called, but it still does allow you to interact with ramp helper the you would normally.
I'm hesitant to change this because this is an edge case we're talking about. Refactoring the plugin to activate on a condition just because of an edge seems like a bit of overkill.
Ramp checks for whether it should be checking for compatibility at all, and if it should - it checks the compatibility and adds a notice - leaving the rest of the Ramp behavior as it was previously. It's simple, easy, and it works.