Skip to content

Commit cf0b766

Browse files
committed
Fixed various PHP 5.3 syntax issues
1 parent d60bcc5 commit cf0b766

5 files changed

Lines changed: 32 additions & 14 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This is a boilerplate WordPress plugin featuring namespace autoloading and integ
66

77
It may also be used as the means of [separating custom code](http://www.billerickson.net/core-functionality-plugin/) from the theme.
88

9+
## Requirements
10+
11+
* WordPress 4.0 or higher
12+
* PHP 5.4.0 or higher
13+
914
## Installation
1015

1116
### Clone Repository
@@ -32,6 +37,8 @@ It may also be used as the means of [separating custom code](http://www.billeric
3237
* Possibly add TGMPA example
3338
* Allow loading Carbon Fields via [plugin](https://github.com/dmhendricks/carbon-fields-loader) rather than Composer dependency
3439
* Test compatibility with WordPress 4.0 and higher
40+
* Remove closing ?> tags per [recommendation](https://github.com/dmhendricks/wordpress-base-plugin/issues/1)
41+
* Add uninstall.php
3542

3643
## Change Log
3744

@@ -40,8 +47,9 @@ It may also be used as the means of [separating custom code](http://www.billeric
4047
* Added Object Cache class
4148
* Added example of loading Font Awesome if enabled in plugin settings
4249
* Removed `./vendor` from repo
43-
* Renamed Helpers Class to Utils
44-
* Tested PHP 5.3 - 7.1 compatibility
50+
* Renamed Helpers class to Utils
51+
* Tested PHP 5.4 - 7.1 compatibility
52+
* Fixed various PHP 5.3 issues; bumped minimum suggested version to 5.4.0
4553
* Added minimum PHP version check
4654
* Added screenshot
4755

app/CPT.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function __construct() {
2020
private function add_post_type_client() {
2121
// Reference: https://github.com/jjgrainger/PostTypes
2222

23-
$options = [
23+
$options = array(
2424
'supports' => array('title'),
2525
'labels' => array(
2626
'menu_name' => 'Client List'
@@ -31,7 +31,7 @@ private function add_post_type_client() {
3131
'show_in_nav_menus' => false,
3232
'rewrite' => false,
3333
'has_archive' => false
34-
];
34+
);
3535

3636
$cpt = new \PostTypes\PostType(
3737
array(
@@ -65,7 +65,7 @@ private function add_post_type_client() {
6565

6666
public function hide_publishing_actions() {
6767
global $post;
68-
if( in_array($post->post_type, ['client']) ) {
68+
if( in_array($post->post_type, array('client')) ) {
6969
echo '<style type="text/css">
7070
#misc-publishing-actions,
7171
#minor-publishing-actions{

app/Cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public static function get_object( $key = null, $callback ) {
4747
*/
4848
public static function flush($ID = null, $post = null) {
4949

50-
$result = ['success' => true];
50+
$result = array('success' => true);
5151

5252
try {
5353
wp_cache_flush();
5454
} catch (Exception $e) {
55-
$result = ['success' => false, 'message' => $e->getMessage()];
55+
$result = array('success' => false, 'message' => $e->getMessage());
5656
}
5757

5858
if( defined('DOING_AJAX') && DOING_AJAX ) {

app/Plugin.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ private function verify_dependencies() {
5656

5757
$error = null;
5858

59-
if( version_compare( phpversion(), self::$settings['deps']['php'], '<' ) ) {
59+
if( $this->is_php_version( self::$settings['deps']['php'], '<' ) ) {
6060
$error = '<strong>' . self::$settings['data']['Name'] . ':</strong> ' . __('This plugin is not supported on versions of PHP under' . ' ' . self::$settings['deps']['php'] . '.' );
6161
} else if(!defined('\\Carbon_Fields\\VERSION')) {
6262
$error = '<strong>' . self::$settings['data']['Name'] . ':</strong> ' . __('A fatal error occurred while trying to load dependencies.');
6363
} else if( version_compare( \Carbon_Fields\VERSION, self::$settings['deps']['carbon_fields'], '<' ) ) {
6464
$error = '<strong>' . self::$settings['data']['Name'] . ':</strong> ' . __('Unable to load. An outdated version of Carbon Fields has been loaded:' . ' ' . \Carbon_Fields\VERSION) . ' (&gt;= '.self::$settings['deps']['carbon_fields'] . ' ' . __('required') . ')';
6565
}
6666

67-
if($error) Helpers::show_notice($error, 'error', false);
67+
if($error) Utils::show_notice($error, 'error', false);
6868
return !$error;
6969

7070
}
@@ -78,12 +78,13 @@ public function get_plugin_option( $key, $cache = true, $source = null ) {
7878

7979
if( $cache ) {
8080
// Attempt to get value from cache, else return value from database
81-
return Cache::get_object( self::$prefix . $key, function() use (&$key, &$source) {
82-
return carbon_get_theme_option( self::$prefix.$key );
81+
$prefix = self::$prefix; // For PHP 5.3 compatibility
82+
return Cache::get_object( self::$prefix . $key, function() use (&$key, &$source, &$prefix) {
83+
return carbon_get_theme_option( $prefix.$key );
8384
});
8485
} else {
8586
// Return uncached value
86-
return carbon_get_theme_option( self::$prefix.$key );
87+
return carbon_get_theme_option( $prefix.$key );
8788
}
8889

8990
}
@@ -96,7 +97,7 @@ public function get_plugin_option( $key, $cache = true, $source = null ) {
9697
* @return bool
9798
*/
9899
public function is_production() {
99-
return ( !defined('WP_ENV') || (defined('WP_ENV') && !in_array(WP_ENV, ['development', 'staging']) ) );
100+
return ( !defined( 'WP_ENV' ) || ( defined('WP_ENV' ) && !in_array( WP_ENV, array('development', 'staging') ) ) );
100101
}
101102

102103
/**
@@ -108,6 +109,15 @@ public function is_ajax() {
108109
return defined('DOING_AJAX') && DOING_AJAX;
109110
}
110111

112+
/**
113+
* Wrapper for phpversion() and version_compare()
114+
*
115+
* @return bool
116+
*/
117+
public function is_php_version( $version = '5.3', $operator = '>=' ) {
118+
return version_compare( phpversion(), $version, $operator );
119+
}
120+
111121
/**
112122
* Returns script ?ver= version based on environment (WP_ENV)
113123
*

wordpress-base-plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'textdomain' => 'my-plugin',
4343
'object_cache_group' => 'my_plugin_cache',
4444
'object_cache_expire' => 72, // In hours
45-
'deps' => ['php' => '5.3.29', 'carbon_fields' => '2.0.0'], // Optional
45+
'deps' => array('php' => '5.4.0', 'carbon_fields' => '2.0.0'), // Optional
4646
'prefix' => 'myplugin_' // Change to your own unique field prefix
4747
));
4848
?>

0 commit comments

Comments
 (0)