wpsharks / s2member

s2Member® Framework (membership management for WordPress®).
64 stars 36 forks source link

create_function deprecated in PHP 7.2 #1145

Open KTS915 opened 6 years ago

KTS915 commented 6 years ago

EXPLANATION OF THE ISSUE

See http://php.net/manual/en/function.create-function.php

SOLUTION

There are three instances of create_function being used in s2Member Framework, and another four in Pro.

For Framework, two instances appear from line 175 of s2member.php These lines should now be changed to read:

        if(!version_compare(PHP_VERSION, WS_PLUGIN__S2MEMBER_MIN_PHP_VERSION, '>='))
    {
        add_action( 'all_admin_notices', function() {
            echo '<div class="error fade"><p>You need PHP v' . WS_PLUGIN__S2MEMBER_MIN_PHP_VERSION . '+ to use the s2Member plugin.</p></div>';
        });
    }
    else if(!version_compare(get_bloginfo('version'), WS_PLUGIN__S2MEMBER_MIN_WP_VERSION, '>='))
    {
        add_action('all_admin_notices', function() {
            echo '<div class="error fade"><p>You need WordPress v' . WS_PLUGIN__S2MEMBER_MIN_WP_VERSION . '+ to use the s2Member plugin.</p></div>';
        });
    }

One instance is on line 1457 of /src/includes/externals/markdown/nc.markdown.inc.php, which should be changed to read:

                $this->utf8_strlen = function( $text ) {
            return preg_match_all("/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", $text, $m);
        };

The four instances in Pro start on line 125 of pro-module.php, and should now be changed to:

        if(!version_compare(PHP_VERSION, WS_PLUGIN__S2MEMBER_PRO_MIN_PHP_VERSION, '>='))
    {
        add_action('all_admin_notices', function() {
            echo '<div class="error fade"><p>You need PHP v'.WS_PLUGIN__S2MEMBER_PRO_MIN_PHP_VERSION.'+ to use the s2Member Pro Add-on.</p></div>';
        });
    }
    else if(!version_compare(get_bloginfo('version'), WS_PLUGIN__S2MEMBER_PRO_MIN_WP_VERSION, '>='))
    {
        add_action('all_admin_notices', function() {
            echo '<div class="error fade"><p>You need WordPress v'.WS_PLUGIN__S2MEMBER_PRO_MIN_WP_VERSION.'+ to use the s2Member Pro Add-on.</p></div>';
        });
    }
    else if(!defined('WS_PLUGIN__S2MEMBER_VERSION') || !defined('WS_PLUGIN__S2MEMBER_MIN_PRO_VERSION') || !version_compare(WS_PLUGIN__S2MEMBER_VERSION, WS_PLUGIN__S2MEMBER_PRO_MIN_FRAMEWORK_VERSION, '>='))
    {
        add_action('all_admin_notices', function() {
            echo '<div class="error fade"><p>In order to load the s2Member Pro Add-on, you need the <a href="http://s2member.com/release-archive/" target="_blank">s2Member Framework</a>, v'.WS_PLUGIN__S2MEMBER_PRO_MIN_FRAMEWORK_VERSION.'+. It\\\'s free.</p></div>';
        });
    }
    else if(!version_compare(WS_PLUGIN__S2MEMBER_PRO_VERSION, WS_PLUGIN__S2MEMBER_MIN_PRO_VERSION, '>=') && file_exists(dirname(__FILE__).'/src/includes/classes/upgrader.inc.php'))
    {
        include_once dirname(__FILE__).'/src/includes/classes/upgrader.inc.php'; // Include upgrader class. s2Member Pro autoload functionality will NOT be available in this scenario. Using ``include_once()``.
        add_action('admin_init', 'c_ws_plugin__s2member_pro_upgrader::upgrade').add_action('all_admin_notices', function() {
            echo c_ws_plugin__s2member_pro_upgrader::wizard();
        });
    }