Title: Question about the code
Last modified: July 5, 2018

---

# Question about the code

 *  Resolved [Ulrich](https://wordpress.org/support/users/grapplerulrich/)
 * (@grapplerulrich)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/question-about-the-code/)
 * Hi [@dglingren](https://wordpress.org/support/users/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](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/question-about-the-code/#post-10467371)
 * 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](https://wordpress.org/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](https://wordpress.org/support/users/grapplerulrich/)
 * (@grapplerulrich)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/question-about-the-code/#post-10468323)
 * 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.

 * ![](https://ps.w.org/media-library-assistant/assets/icon-256x256.png?rev=973502)
 * [Media Library Assistant](https://wordpress.org/plugins/media-library-assistant/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-assistant/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-assistant/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-assistant/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-assistant/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-assistant/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Ulrich](https://wordpress.org/support/users/grapplerulrich/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/question-about-the-code/#post-10468323)
 * Status: resolved