PHP requirement for plugins

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

PHP requirement for plugins

Stephen Rider
Hi all —

Is there a standardized method in WordPress to declare that a plugin or theme requires a certain version of PHP?  I’ve started coding my plugins to require PHP 5.4.

I know I can write code that does something like check for the right PHP version and deactivate the plugin if it’s not met; but is there anything like this already within WP?  It would be great if we could just add a line to the Readme.txt or the plugin Headers.

--
Stephen Rider

[hidden email]
http://striderweb.com/nerdaphernalia



_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: PHP requirement for plugins

J.D. Grimes
Hi Stephen,

I don't know if there is a "best practice" implementation of this out there or not. There is nothing like this in WordPress core, and probably never will be. You might want to take a look at https://core.trac.wordpress.org/ticket/26909 and the related tickets for a better understanding of why.

- J.D.

> On May 2, 2016, at 5:52 PM, Stephen Rider <[hidden email]> wrote:
>
> Hi all —
>
> Is there a standardized method in WordPress to declare that a plugin or theme requires a certain version of PHP?  I’ve started coding my plugins to require PHP 5.4.
>
> I know I can write code that does something like check for the right PHP version and deactivate the plugin if it’s not met; but is there anything like this already within WP?  It would be great if we could just add a line to the Readme.txt or the plugin Headers.
>
> --
> Stephen Rider
>
> [hidden email]
> http://striderweb.com/nerdaphernalia
>
>
>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: PHP requirement for plugins

Jamie Currie
Nothing I'm aware of. This is what I use:

 public static function check_php_version() {
            $plugin_name = PLUGIN_NAME;
            $php_min_version = MIN_PHP_VERSION;
            $php_min_version_formatted = MIN_PHP_VERSION_FORMATTED;

            if ( ! ( PHP_VERSION_ID ) || version_compare( PHP_VERSION_ID,
$php_min_version, '<' )) {
                wp_die( sprintf( __( 'PHP version %1$s or greater is
required to use this version of the %2$s plugin!', 'text-domain' ),
"<strong>{$php_min_version_formatted}</strong>", $plugin_name ) );
            }

        }

The constants it references look like:

const MIN_PHP_VERSION = '50300';
const MIN_PHP_VERSION_FORMATTED = '5.3.0';

*Jamie Currie*
------------------
CEO, wunderdojo
949-734-0758
Located in sunny Southern California
GMT / UTC - 7 hours

On Mon, May 2, 2016 at 3:05 PM, J.D. Grimes <[hidden email]> wrote:

> Hi Stephen,
>
> I don't know if there is a "best practice" implementation of this out
> there or not. There is nothing like this in WordPress core, and probably
> never will be. You might want to take a look at
> https://core.trac.wordpress.org/ticket/26909 and the related tickets for
> a better understanding of why.
>
> - J.D.
>
> > On May 2, 2016, at 5:52 PM, Stephen Rider <[hidden email]>
> wrote:
> >
> > Hi all —
> >
> > Is there a standardized method in WordPress to declare that a plugin or
> theme requires a certain version of PHP?  I’ve started coding my plugins to
> require PHP 5.4.
> >
> > I know I can write code that does something like check for the right PHP
> version and deactivate the plugin if it’s not met; but is there anything
> like this already within WP?  It would be great if we could just add a line
> to the Readme.txt or the plugin Headers.
> >
> > --
> > Stephen Rider
> >
> > [hidden email]
> > http://striderweb.com/nerdaphernalia
> >
> >
> >
> > _______________________________________________
> > wp-hackers mailing list
> > [hidden email]
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: PHP requirement for plugins

Chloé Desoutter
Hello,

I don't mean to troll but why as plug-in/theme developers should we
consider supporting obsolete, unmaintained versions of PHP that will suffer
from huge security flaws?

This grasping to past versions, broadest compatibility, etc. hinders with
providing secure, reliable code.

We should be the ones pushing hosters and hoster customers towards newer,
better supported code versions.

That said, your version test code needs to be the first called by your
plug-in and to refrain from using newer syntactic elements that would cause
parse errors.

Yours sincerely,

2016-05-03 0:56 GMT+02:00 James Currie <[hidden email]>:

> Nothing I'm aware of. This is what I use:
>
>  public static function check_php_version() {
>             $plugin_name = PLUGIN_NAME;
>             $php_min_version = MIN_PHP_VERSION;
>             $php_min_version_formatted = MIN_PHP_VERSION_FORMATTED;
>
>             if ( ! ( PHP_VERSION_ID ) || version_compare( PHP_VERSION_ID,
> $php_min_version, '<' )) {
>                 wp_die( sprintf( __( 'PHP version %1$s or greater is
> required to use this version of the %2$s plugin!', 'text-domain' ),
> "<strong>{$php_min_version_formatted}</strong>", $plugin_name ) );
>             }
>
>         }
>
> The constants it references look like:
>
> const MIN_PHP_VERSION = '50300';
> const MIN_PHP_VERSION_FORMATTED = '5.3.0';
>
> *Jamie Currie*
> ------------------
> CEO, wunderdojo
> 949-734-0758
> Located in sunny Southern California
> GMT / UTC - 7 hours
>
> On Mon, May 2, 2016 at 3:05 PM, J.D. Grimes <[hidden email]> wrote:
>
> > Hi Stephen,
> >
> > I don't know if there is a "best practice" implementation of this out
> > there or not. There is nothing like this in WordPress core, and probably
> > never will be. You might want to take a look at
> > https://core.trac.wordpress.org/ticket/26909 and the related tickets for
> > a better understanding of why.
> >
> > - J.D.
> >
> > > On May 2, 2016, at 5:52 PM, Stephen Rider <[hidden email]>
> > wrote:
> > >
> > > Hi all —
> > >
> > > Is there a standardized method in WordPress to declare that a plugin or
> > theme requires a certain version of PHP?  I’ve started coding my plugins
> to
> > require PHP 5.4.
> > >
> > > I know I can write code that does something like check for the right
> PHP
> > version and deactivate the plugin if it’s not met; but is there anything
> > like this already within WP?  It would be great if we could just add a
> line
> > to the Readme.txt or the plugin Headers.
> > >
> > > --
> > > Stephen Rider
> > >
> > > [hidden email]
> > > http://striderweb.com/nerdaphernalia
> > >
> > >
> > >
> > > _______________________________________________
> > > wp-hackers mailing list
> > > [hidden email]
> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> > _______________________________________________
> > wp-hackers mailing list
> > [hidden email]
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: PHP requirement for plugins

Abdussamad-2

Hi,

WordPress.org maintains stats about the PHP versions people are using.
It's worth a look:

https://wordpress.org/about/stats/

The data is current. The page is updated based on data from active WP
installations.

Regards,
Abdussamad

On 05/03/2016 01:29 PM, Chloé Desoutter wrote:

> Hello,
>
> I don't mean to troll but why as plug-in/theme developers should we
> consider supporting obsolete, unmaintained versions of PHP that will suffer
> from huge security flaws?
>
> This grasping to past versions, broadest compatibility, etc. hinders with
> providing secure, reliable code.
>
> We should be the ones pushing hosters and hoster customers towards newer,
> better supported code versions.
>
> That said, your version test code needs to be the first called by your
> plug-in and to refrain from using newer syntactic elements that would cause
> parse errors.
>
> Yours sincerely,
>
> 2016-05-03 0:56 GMT+02:00 James Currie <[hidden email]>:
>
>> Nothing I'm aware of. This is what I use:
>>
>>   public static function check_php_version() {
>>              $plugin_name = PLUGIN_NAME;
>>              $php_min_version = MIN_PHP_VERSION;
>>              $php_min_version_formatted = MIN_PHP_VERSION_FORMATTED;
>>
>>              if ( ! ( PHP_VERSION_ID ) || version_compare( PHP_VERSION_ID,
>> $php_min_version, '<' )) {
>>                  wp_die( sprintf( __( 'PHP version %1$s or greater is
>> required to use this version of the %2$s plugin!', 'text-domain' ),
>> "<strong>{$php_min_version_formatted}</strong>", $plugin_name ) );
>>              }
>>
>>          }
>>
>> The constants it references look like:
>>
>> const MIN_PHP_VERSION = '50300';
>> const MIN_PHP_VERSION_FORMATTED = '5.3.0';
>>
>> *Jamie Currie*
>> ------------------
>> CEO, wunderdojo
>> 949-734-0758
>> Located in sunny Southern California
>> GMT / UTC - 7 hours
>>
>> On Mon, May 2, 2016 at 3:05 PM, J.D. Grimes <[hidden email]> wrote:
>>
>>> Hi Stephen,
>>>
>>> I don't know if there is a "best practice" implementation of this out
>>> there or not. There is nothing like this in WordPress core, and probably
>>> never will be. You might want to take a look at
>>> https://core.trac.wordpress.org/ticket/26909 and the related tickets for
>>> a better understanding of why.
>>>
>>> - J.D.
>>>
>>>> On May 2, 2016, at 5:52 PM, Stephen Rider <[hidden email]>
>>> wrote:
>>>>
>>>> Hi all —
>>>>
>>>> Is there a standardized method in WordPress to declare that a plugin or
>>> theme requires a certain version of PHP?  I’ve started coding my plugins
>> to
>>> require PHP 5.4.
>>>>
>>>> I know I can write code that does something like check for the right
>> PHP
>>> version and deactivate the plugin if it’s not met; but is there anything
>>> like this already within WP?  It would be great if we could just add a
>> line
>>> to the Readme.txt or the plugin Headers.
>>>>
>>>> --
>>>> Stephen Rider
>>>>
>>>> [hidden email]
>>>> http://striderweb.com/nerdaphernalia
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> [hidden email]
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>> _______________________________________________
>>> wp-hackers mailing list
>>> [hidden email]
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: PHP requirement for plugins

James DiGioia
There's also this library, which will handle PHP version checking and put
up an admin notice in WordPress if the user's version isn't high enough:

https://github.com/WPupdatePHP/wp-update-php

- James

On Tue, May 3, 2016 at 5:02 AM, Abdussamad <[hidden email]> wrote:

>
> Hi,
>
> WordPress.org maintains stats about the PHP versions people are using.
> It's worth a look:
>
> https://wordpress.org/about/stats/
>
> The data is current. The page is updated based on data from active WP
> installations.
>
> Regards,
> Abdussamad
>
>
> On 05/03/2016 01:29 PM, Chloé Desoutter wrote:
>
>> Hello,
>>
>> I don't mean to troll but why as plug-in/theme developers should we
>> consider supporting obsolete, unmaintained versions of PHP that will
>> suffer
>> from huge security flaws?
>>
>> This grasping to past versions, broadest compatibility, etc. hinders with
>> providing secure, reliable code.
>>
>> We should be the ones pushing hosters and hoster customers towards newer,
>> better supported code versions.
>>
>> That said, your version test code needs to be the first called by your
>> plug-in and to refrain from using newer syntactic elements that would
>> cause
>> parse errors.
>>
>> Yours sincerely,
>>
>> 2016-05-03 0:56 GMT+02:00 James Currie <[hidden email]>:
>>
>> Nothing I'm aware of. This is what I use:
>>>
>>>   public static function check_php_version() {
>>>              $plugin_name = PLUGIN_NAME;
>>>              $php_min_version = MIN_PHP_VERSION;
>>>              $php_min_version_formatted = MIN_PHP_VERSION_FORMATTED;
>>>
>>>              if ( ! ( PHP_VERSION_ID ) || version_compare(
>>> PHP_VERSION_ID,
>>> $php_min_version, '<' )) {
>>>                  wp_die( sprintf( __( 'PHP version %1$s or greater is
>>> required to use this version of the %2$s plugin!', 'text-domain' ),
>>> "<strong>{$php_min_version_formatted}</strong>", $plugin_name ) );
>>>              }
>>>
>>>          }
>>>
>>> The constants it references look like:
>>>
>>> const MIN_PHP_VERSION = '50300';
>>> const MIN_PHP_VERSION_FORMATTED = '5.3.0';
>>>
>>> *Jamie Currie*
>>> ------------------
>>> CEO, wunderdojo
>>> 949-734-0758
>>> Located in sunny Southern California
>>> GMT / UTC - 7 hours
>>>
>>> On Mon, May 2, 2016 at 3:05 PM, J.D. Grimes <[hidden email]> wrote:
>>>
>>> Hi Stephen,
>>>>
>>>> I don't know if there is a "best practice" implementation of this out
>>>> there or not. There is nothing like this in WordPress core, and probably
>>>> never will be. You might want to take a look at
>>>> https://core.trac.wordpress.org/ticket/26909 and the related tickets
>>>> for
>>>> a better understanding of why.
>>>>
>>>> - J.D.
>>>>
>>>> On May 2, 2016, at 5:52 PM, Stephen Rider <[hidden email]>
>>>>>
>>>> wrote:
>>>>
>>>>>
>>>>> Hi all —
>>>>>
>>>>> Is there a standardized method in WordPress to declare that a plugin or
>>>>>
>>>> theme requires a certain version of PHP?  I’ve started coding my plugins
>>>>
>>> to
>>>
>>>> require PHP 5.4.
>>>>
>>>>>
>>>>> I know I can write code that does something like check for the right
>>>>>
>>>> PHP
>>>
>>>> version and deactivate the plugin if it’s not met; but is there anything
>>>> like this already within WP?  It would be great if we could just add a
>>>>
>>> line
>>>
>>>> to the Readme.txt or the plugin Headers.
>>>>
>>>>>
>>>>> --
>>>>> Stephen Rider
>>>>>
>>>>> [hidden email]
>>>>> http://striderweb.com/nerdaphernalia
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> wp-hackers mailing list
>>>>> [hidden email]
>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>>
>>>>
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> [hidden email]
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>
>>>> _______________________________________________
>>> wp-hackers mailing list
>>> [hidden email]
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers