0

Good Day Everyone,

I want to test my Plugin online on my real website but I don't know why, the following line would give an error, when on my local installation everything works perfectly. (I tried to deactivate and reactivate on my local install and I don't get the error).

Both are using the latest version of WordPress (4.2.2)

add_action('wp_enqueue_scripts', 'plugin_jquery');
function plugin_jquery()
{
    if (!is_admin())
        wp_enqueue_script('plugin-jquery', plugins_url('js/plugin_regpage.js', __FILE__), ['jquery'], true);

    wp_enqueue_style(
        'plugin-regpage-css',
         plugins_url('css/plugin_regpage.css', __FILE__)
    );
}

I get:

Parse error: syntax error, unexpected '[' in html/wp-content/plugins/plugin/plugin.php on line 49

Why would a bracket make a problem online and not locally?

  • 1
    The new short array syntax ([]) is only avaible from PHP 5.4. – Pieter Goosen Jun 4 '15 at 10:28
  • 2
    Online version is less than PHP 5.4 while offline is bigger than PHP5.4 ;-) – Pieter Goosen Jun 4 '15 at 10:30
  • Hmmmmmmmm... Let me have a look at that ;-) You might have put your finger on it... How would I fix it then :-/ – pSyToR Jun 4 '15 at 10:34
  • 1
    O yes, array( 'jquery' ) is correct – Pieter Goosen Jun 4 '15 at 10:49
  • 1
    Thanks at least this way I will be able to test it properly for the time being... I will also contact them as 5.3 is EOL since 9 months already... – pSyToR Jun 4 '15 at 10:58
1

This is an issue with your PHP versions on your local and live install.

The new short array syntax ([]) was implemented in PHP 5.4. This tells you that your PHP version on your local install is at least PHP 5.4 and your live install has a version older than that. The new short array syntax will lead to a PHP error in older versions as it is invalid PHP in the older versions.

SOLUTION

As PHP 5.3 was EOL'ed almost a year ago, it is a very good and security wise idea to ask your host to upgrade their PHP version to atleast PHP 5.4. Alternatively, you can change your new short array syntax back to the old array syntax.

['jquery']

then becomes

array( 'jquery' )
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.