WordPress.org

Ready to get started?Download WordPress

Forums

WordPress MU Domain Mapping
Minor: get_current_site_name() Deprecated in 3.9 (16 posts)

  1. scottnelle
    Member
    Posted 3 months ago #

    I was reading through the release notes and found that get_current_site_name(), used in sunrise.php, has been deprecated. Going forward, the plugin should use get_current_site() instead.

    https://wordpress.org/plugins/wordpress-mu-domain-mapping/

  2. Eric
    Member
    Posted 2 months ago #

    I could not get get_current_site() to work, but I did find that commenting out two lines of sunrise.php as specified here does the trick. Since sunrise seems to set the $current_site variable twice, there don't seem to be ill effects to eliminating the redundant code.

    It would be nice if the plugin were updated with this fix.

  3. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 months ago #

    @ecceleste - get_current_site() returns an object not a string. You need to use the site_name member of the object.

  4. lkraav
    Member
    Posted 2 months ago #

    The problem is get_current_site() isn't available at the time sunrise.php is loaded.

    https://core.trac.wordpress.org/ticket/14965

  5. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 months ago #

    The problem is get_current_site() isn't available at the time sunrise.php is loaded.

    That's not what that trac ticket was about. If the function didn't exist all installs running domain mapping would white screen.

    At the time sunrise.php is executed the $current_site object does not have the name attribute.

  6. jonbeddoes
    Member
    Posted 2 months ago #

    Here is a code fix for this issue. Update the reference at the end of sunrise.php:

    if( function_exists( 'get_current_site' ) )
    {
    	$current_site_obj = get_current_site( $current_site );
    	$current_site = $current_site_obj->site_name;
    }
  7. khromov
    Member
    Posted 2 months ago #

    What exactly does setting $current_site do? When I try out jonbeddoes fix then the function does in fact NOT exist, so the code does not run, yet everything seems to work fine. So is it not really required to set $current_site?

  8. jonbeddoes
    Member
    Posted 2 months ago #

    Hi khromov,

    I am sorry my solution didn't help you. I must admit I didn't consider the outcome if the function was never called. In my case I was simply trying to modify the sunrise.php file to keep it's behavior the same as it was before. Because the get_current_site_name() function was deprecated I essentially achieve the same thing with those two lines. Once I made this update my warnings went away.

    Are you running multiple sites through the domain mapping plugin? Do you have any warnings still? If not then you should probably assume everything is working as expected :)

    JB

  9. khromov
    Member
    Posted 2 months ago #

    You're right jonbeddoes, the function doesn't do anything as of WP 3.9.

    After removing the $current_site stuff, I had one deprecation warning left:

    Notice: wpdb::escape is <strong>deprecated</strong> since version 3.6! Use wpdb::prepare() or esc_sql() instead.

    It wasn't all that easy though, as esc_sql() is not defined yet in sunrise, however you can use the hidden method $wpdb->_escape(); to get rid of the deprecation warnings. So just change every instance of $wpdb->escape(); to $wpdb->_escape();

    But I'm a bit worried about the state of this plugin. Is it actually usable or are there a lot of hidden edge cases and bugs?

  10. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 months ago #

    Notice: wpdb::escape is deprecated since version 3.6! Use wpdb::prepare() or esc_sql() instead.

    Download the development version. That warning has been fixed.

    What exactly does setting $current_site do?

    That's necessary to bypass the core site lookup.

  11. jonbeddoes
    Member
    Posted 2 months ago #

    @Khromov I had that warning issue too but that change fixes it indeed. @RonRennick good to know that the official version fixes that too.

    @RonRennick Out of interest, are you happy with the proposed fix I suggested above for the other warning that spawned after the 3.9 update?

  12. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 1 month ago #

    @jonbeddoes - it looks good but I haven't had a chance to test it.

  13. Haitham
    Member
    Posted 1 month ago #

    @RonRennick - jonbeddoes's solution worked perfectly for wp3.9.1

    @jonbeddoes - Thank you!

  14. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 weeks ago #

    @Haitham - jonbeddoes's solution doesn't actually do anything. It eliminates the warning by removing the function call. If you just deleted the code the warning would also go away.

    The development version has the warning fixed.

  15. jonbeddoes
    Member
    Posted 3 weeks ago #

    @RonRennick - bit confused by your response;
    I wrote code to mimic the same functionality as was there before, but your suggestion to remove the code implies it has no purpose and is never executed?

    If that is the case, what change(a) did you make in the development version instead if it's not my change and not deleting the code fragment? :)

  16. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 weeks ago #

    but your suggestion to remove the code implies it has no purpose and is never executed?

    I didn't say it didn't execute. I said it didn't do anything. The code below processes but doesn't do anything:

    function get_x() {
    global $x;
    return $x;
    }
    
    $x = 1;
    $x = get_x( $x );
    // $x is 1

    https://plugins.trac.wordpress.org/changeset?sfp_email=&sfph_mail=&reponame=&new=940547%40wordpress-mu-domain-mapping&old=940546%40wordpress-mu-domain-mapping&sfp_email=&sfph_mail=

Reply

You must log in to post.

About this Plugin

About this Topic

Tags