Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforced minimum PHP, Genesis and WP version requirements. #44

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@
* @link https://www.christophherr.com/
*/

namespace ChristophHerr\Prometheus2;
/**
* Get the version of the Genesis framework.
*
* @since 2.0
*
* @return string
*/
function prometheus_2_get_genesis_version() {
return wp_get_theme( 'genesis' )->get( 'Version' );
}

// Check minimum requirements.
if ( version_compare( $GLOBALS['wp_version'], '4.8', '<' ) || version_compare( PHP_VERSION, '5.6', '<' ) || version_compare( prometheus_2_get_genesis_version(), '2.6', '<' ) ) {
require_once 'lib/minimum-requirements.php';
return;
}

// Start the Child Theme.
require_once 'lib/init.php';
Expand Down
35 changes: 35 additions & 0 deletions languages/prometheus-2.pot
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,41 @@ msgstr ""
msgid "The maximum width of the logo in pixels."
msgstr ""

#. translators: 1 is the required Genesis Version, 2 is the required WordPress version, 3 is the required PHP version, 4 is the user's current Genesis version, 5 is the user's current WordPress version and 6 is the user's current PHP version.
#: lib/minimum-requirements.php:79
msgid "Prometheus 2 cannot be activated because it requires Genesis version %1$s, WordPress version %2$s and PHP version %3$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %4$s, WordPress version %5$s and PHP version %6$s. Please upgrade Genesis, WordPress and PHP and try again."
msgstr ""

#. translators: 1 is the required WordPress version, 2 is the required PHP version, 3 is the user's current WordPress version amd 4 is the user's current PHP version.
#: lib/minimum-requirements.php:90
msgid "Prometheus 2 cannot be activated because it requires WordPress version %1$s and PHP version %2$s. The Genesis Framework (parent theme) has been activated instead. You are running WordPress version %3$s and PHP version %4$s. Please upgrade WordPress and PHP and try again."
msgstr ""

#. translators: 1 is the required Genesis version, 2 is the required WordPress version, 3 is the user's current Genesis version and 4 is the user's current WordPress version.
#: lib/minimum-requirements.php:99
msgid "Prometheus 2 was not activated because it requires Genesis version %1$s and WordPress version %2$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %3$s and WordPress version %4$s. Please upgrade Genesis and WordPress and try again."
msgstr ""

#. translators: 1 is the required Genesis version, 2 is the required PHP version, 3 is the user's current Genesis version and 4 is the user's current PHP version.
#: lib/minimum-requirements.php:108
msgid "Prometheus 2 was not activated because it requires Genesis version %1$s and PHP version of %2$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %3$s and PHP version %4$s. Please upgrade Genesis and PHP and try again."
msgstr ""

#. translators: 1 is the required WordPress version and 2 is the user's current WordPress version.
#: lib/minimum-requirements.php:117
msgid "Prometheus 2 was not activated because it requires WordPress version %1$s. The Genesis Framework (parent theme) has been activated instead. You are running WordPress version %2$s. Please upgrade WordPress and try again."
msgstr ""

#. translators: 1 is the required PHP version and 2 is the user's current PHP version.
#: lib/minimum-requirements.php:124
msgid "Prometheus 2 was not activated because it requires PHP version %1$s. The Genesis Framework (parent theme) has been activated instead. You are running PHP version %2$s. Please upgrade PHP and try again."
msgstr ""

#. translators: 1 is the required Genesis version and 2 is the user's current Genesis version.
#: lib/minimum-requirements.php:131
msgid "Prometheus 2 was not activated because it requires Genesis version %1$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %2$s. Please upgrade Genesis and try again."
msgstr ""

#: lib/plugins/woocommerce/woocommerce-setup.php:67
msgid "Previous Page"
msgstr ""
Expand Down
137 changes: 137 additions & 0 deletions lib/minimum-requirements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Handle when minimum requirements are not met.
*
* @package ChristophHerr\Prometheus2
* @since 2.0.0
* @author Christoph Herr
* @link https://www.christophherr.com
* @license GNU General Public License 2+
*/

add_action( 'after_switch_theme', 'prometheus_2_switch_theme' );
/**
* Switch to the Genesis parent theme after the theme has been activated.
*
* @since 2.0.0
*
* @return void
*/
function prometheus_2_switch_theme() {
switch_theme( 'genesis' );
unset( $_GET['activated'] );
add_action( 'admin_notices', 'prometheus_2_show_deactivation_and_upgrade_notice' );
}

add_action( 'load-customize.php', 'prometheus_2_do_not_load_customizer' );
/**
* Don't load the Customizer.
*
* @since 2.0.0
*
* @return void
*/
function prometheus_2_do_not_load_customizer() {
wp_die( esc_html( prometheus_2_upgrade_message() ), '', array( 'back_link' => true ) );
}

add_action( 'template_redirect', 'prometheus_2_do_not_load_customizer_preview' );
/**
* Don't load the Customizer preview on installs prior to WordPress 4.7.
*
* @since 2.0.0
*
* @return void
*/
function prometheus_2_do_not_load_customizer_preview() {
if ( isset( $_GET['preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification -- Just checking, no processing going on.
wp_die( esc_html( prometheus_2_upgrade_message() ) );
}
}

/**
* Show an admin notice.
*
* @since 2.0.0
*
* @return void
*/
function prometheus_2_show_deactivation_and_upgrade_notice() {
printf( '<div class="error"><p>%s</p></div>', esc_html( prometheus_2_upgrade_message() ) );
}

/**
* Content of the admin notice detailing that the theme was not activated and which requirement wasn't met.
*
* @since 2.0.0
*
* @return string
*/
function prometheus_2_upgrade_message() {
$genesis_version = prometheus_2_get_genesis_version();
$compare_wp_version = version_compare( $GLOBALS['wp_version'], '4.8', '<' );
$compare_php_version = version_compare( PHP_VERSION, '5.6', '<' );
$compare_genesis_version = version_compare( $genesis_version, '2.6', '<' );

if ( $compare_wp_version && $compare_php_version && $compare_genesis_version ) {
return sprintf(
// Translators: 1 is the required Genesis Version, 2 is the required WordPress version, 3 is the required PHP version, 4 is the user's current Genesis version, 5 is the user's current WordPress version and 6 is the user's current PHP version.
__( 'Prometheus 2 cannot be activated because it requires Genesis version %1$s, WordPress version %2$s and PHP version %3$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %4$s, WordPress version %5$s and PHP version %6$s. Please upgrade Genesis, WordPress and PHP and try again.', 'prometheus2' ),
'2.6',
'4.9.6',
'5.6',
$genesis_version,
$GLOBALS['wp_version'],
PHP_VERSION
);
} elseif ( $compare_wp_version && $compare_php_version ) {
return sprintf(
// Translators: 1 is the required WordPress version, 2 is the required PHP version, 3 is the user's current WordPress version amd 4 is the user's current PHP version.
__( 'Prometheus 2 cannot be activated because it requires WordPress version %1$s and PHP version %2$s. The Genesis Framework (parent theme) has been activated instead. You are running WordPress version %3$s and PHP version %4$s. Please upgrade WordPress and PHP and try again.', 'prometheus2' ),
'4.9.6',
'5.6',
$GLOBALS['wp_version'],
PHP_VERSION
);
} elseif ( $compare_genesis_version && $compare_wp_version ) {
return sprintf(
// Translators: 1 is the required Genesis version, 2 is the required WordPress version, 3 is the user's current Genesis version and 4 is the user's current WordPress version.
__( 'Prometheus 2 was not activated because it requires Genesis version %1$s and WordPress version %2$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %3$s and WordPress version %4$s. Please upgrade Genesis and WordPress and try again.', 'prometheus2' ),
'2.6',
'4.9.6',
$genesis_version,
$GLOBALS['wp_version']
);
} elseif ( $compare_genesis_version && $compare_php_version ) {
return sprintf(
// Translators: 1 is the required Genesis version, 2 is the required PHP version, 3 is the user's current Genesis version and 4 is the user's current PHP version.
__( 'Prometheus 2 was not activated because it requires Genesis version %1$s and PHP version of %2$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %3$s and PHP version %4$s. Please upgrade Genesis and PHP and try again.', 'prometheus2' ),
'2.6',
'5.6',
$genesis_version,
PHP_VERSION
);
} elseif ( $compare_wp_version ) {
return sprintf(
// Translators: 1 is the required WordPress version and 2 is the user's current WordPress version.
__( 'Prometheus 2 was not activated because it requires WordPress version %1$s. The Genesis Framework (parent theme) has been activated instead. You are running WordPress version %2$s. Please upgrade WordPress and try again.', 'prometheus2' ),
'4.9.6',
$GLOBALS['wp_version']
);
} elseif ( $compare_php_version ) {
return sprintf(
// Translators: 1 is the required PHP version and 2 is the user's current PHP version.
__( 'Prometheus 2 was not activated because it requires PHP version %1$s. The Genesis Framework (parent theme) has been activated instead. You are running PHP version %2$s. Please upgrade PHP and try again.', 'prometheus2' ),
'5.6',
PHP_VERSION
);
} elseif ( $compare_genesis_version ) {
return sprintf(
// Translators: 1 is the required Genesis version and 2 is the user's current Genesis version.
__( 'Prometheus 2 was not activated because it requires Genesis version %1$s. The Genesis Framework (parent theme) has been activated instead. You are running Genesis version %2$s. Please upgrade Genesis and try again.', 'prometheus2' ),
'2.6',
$genesis_version
);
}
return '';
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"homepage": "https://github.com/christophherr/prometheus#readme",
"devDependencies": {
"ajv": "^6.5.0",
"ajv": "^6.5.4",
"autoprefixer": "^9.2.1",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.7.0",
Expand Down Expand Up @@ -67,8 +67,8 @@
"prettier-eslint": "^8.2.1",
"prettier-stylelint": "^0.4.2",
"pump": "^3.0.0",
"sort-css-media-queries": "^1.3.4",
"stylelint": "^9.2.1",
"sort-css-media-queries": "^1.4.1",
"stylelint": "^9.6.0",
"stylelint-config-wordpress": "^13.0.0",
"stylelint-order": "^0.8.1"
},
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<property name="prefixes" type="array">
<element value="CHILD_THEME"/>
<element value="CHILD_TEXT_DOMAIN"/>
<element value="prometheus_2"/>
</property>
</properties>
</rule>
Expand Down