• Resolved Ulrich

    (@grapplerulrich)


    Hi @dglingren

    I have the problem on one of my sites that is using MLA that get_option( 'page_on_front' ) is returning the value for another site.

    I was looking through all of the cases of the code that have switch_to_blog() and found the following code in MLAMultisiteExtensions::mla_gallery_query_arguments() which I don’t fully understand.

    $blog_details = get_blog_details( reset( $site_ids ) );
    
    if ( $blog_details ) {
    	switch_to_blog( current( $site_ids ));
    } else {
    	unset( self::$shortcode_attributes['site_id'] );
    }

    Thank you for looking into and explaining to me why the switch_to_blog() is needed here.

    Ulrich

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Good to hear from you again! Thanks for the question.

    The “MLA Multisite Extensions” example plugin was developed in response to this earlier support topic:

    Using Shortcodes to retrieve media from another sites media library

    As documented in that topic, the example plugin adds a site_id=id[,id...]|all parameter to the [mla_gallery] shortcode that names one or more or all sites to query.

    The code you’ve posted and asked about is executed when the site_id= parameter is present and contains exactly one ID value. For this case, the plugin first checks to ensure that the parameter value selects a valid blog ( get_blog_details() ). If it does, the switch_to_blog() function makes the selected blog the target for the database query that selects items for the gallery display and for the MLA code that formats the gallery. After everything has been processed the code in the mla_gallery_item_values() function restores the current blog that was active before the shortcode was processed.

    Of course, the code only runs if you have installed and activated the example plugin. It’s not part of the MLA core code.

    I hope that answers your question. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above explanation. Thanks for your continued interest in the plugin.

    Thread Starter Ulrich

    (@grapplerulrich)

    Thank you for the explanation. We are not using this shortcode so it can’t be the cause of our issue.

    Thanks again!

    Ulrich

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Question about the code’ is closed to new replies.