• Resolved Rhapsody348

    (@rhapsody348)


    I wrote a plugin used on a multisite (subdomains) application. Recently I decided that uploaded media need organizing so I started to write my own code to address that. While writing this I did some research and a Google search took me to your plugin. I installed it and was amazed on how well the MLA plugin handles everything I was trying to accomplish, plus more. No need for me to reinvent the wheel. This plugin is fantastic!

    I am looking for information on how to make the MLA setting the same on all subsites. I see the Export All Settings button on the General tab. I did not find where these may be imported. I would like the settings to be the same for all existing sites, and when I add anew site. Ideally I can run a script or execute a shortcode via a script to import the settings on the subsites.

    Is there a way to import saved settings to subsites?

    Thanks – and again great job on this amazing plugin!

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

    (@dglingren)

    Thanks for the positive feedback regarding MLA and for your question. You can find the current answer to your export/import question in this earlier topic:

    The IPTC data isn’t coming through | www.remarpro.com

    Hiding the Import button until there’s something to import seems to confuse people. I am looking at changing that in my next MLA version.

    I am marking this topic resolved, but please update it if you have problems or further questions regarding the suggestions in the earlier topic. Thanks for your interest in MLA.

    Thread Starter Rhapsody348

    (@rhapsody348)

    Thanks for the answer David. That will allow me to manually import the settings to subsites.

    I have a feature request associated with this. Would it be possible to have a shortcode that could be executed from a script to allow import? something like the following:

    [mla_import file=c:\temp\mla__options_XXXXXXXX_YYY.txt]
    where the path and filename are passed

    or

    [mla_import site=xx post=yyyy]
    where for a multisite application having the source for the exported settings located on the site id and a post containing the mla text file pasted in it.

    ps: in a pinch I can get the serialized array settings stored in the wp_options table having “mla” in the option_name and use those to update the wp_xx_options on subsites, but it would probably be better if you had a supported function/shortcode to accomplish this.

    • This reply was modified 1 year, 11 months ago by Rhapsody348. Reason: added ps
    Thread Starter Rhapsody348

    (@rhapsody348)

    David – adding other potential options for the import shortcode. These would probably be easier to handle on a multisite installation than creating a separate file. If the shortcode detects a multisite installation, the following options are available.

    [mla_import] with no parameters would copy the mla settings from the main site to the subsite the shortcode is executed on.

    [mla_import blog=xx] would import the mla settings from the blog ID designated to the subsite the shortcode is executed on.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your suggestions to add something to MLA to handle this task. It has been quite a while since I looked at the multisite logic, but I will investigate further when I have time to get back to it. I regret that the time I have available is quite limited, so I cannot promise any quick action. Thanks for your ideas and for your understanding.

    Thread Starter Rhapsody348

    (@rhapsody348)

    David – no problem and thanks for considering. I may be able to provide some code already used for my multisite application to make this easier for you. I created some PHP routines that copy saved options settings from the master site to subsites. What I don’t have is an understanding of all the settings MLA stores, and which settings should be transferred. If you could provide the relevant saved option names (e.g. mla_custom_field_mapping, …) and whether there are particular options in the array that should NOT be transferred, I may be able to assist.

    It’s a busy time as I get my boat ready for the sailing season, but when I do get a chance can send you some annotated PHP files and descriptions. Do you have a preferred place I can transfer the files? (FTP site, Dropbox, Google drive, Email, etc.)

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your flexibility and your offer. You can contact me at my web site?to send more information by email.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for working with me by email to test and refine the new “Copy Options” tool and Documentation tab I added to the “MLA Multisite Extensions” example plugin.

    I have uploaded a new MLA Development Version dated 20230427 that contains the new example plugin version. You can find step-by-step instructions for using the Development Version in this earlier topic:

    PHP Warning on media upload with Polylang

    Once the Development Version is installed you must install (or update) and activate the example plugin. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “Multisite” in the text box and click “Search Plugins” to filter the table.

    You are looking for the “MLA Multisite Extensions” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” (or “Update”) rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate (or verify) the example plugin as you would any other plugin. Make sure you have the latest version, 1.10, installed.

    Once the Development Version and updated example plugin are installed and active you can navigate to the Settings/MLA Multisite admin screen and try the new tool for your application, including the “Copy Defaults” variation I just completed. You will find a Documentation tab with quite a bit of instructions and information. I would be very interested in any suggestions you have about the documentation content.

    This example plugin enhancement will be part of my next MLA version, but in the interim it would be great if you could install the Development Version and the example plugin and let me know if it works for you. Thanks for inspiring this long-wanted MLA improvement.

    Thread Starter Rhapsody348

    (@rhapsody348)

    Thanks for the update David. I just installed the Development Version and have started to play with it. I’ll do so over the upcoming weekend and post comments here.

    Two initial comments:
    1. I’m using my test server that only has 6 subsites. Checking the boxes to update sites is no problem. On my production multisite installation there are about a hundred subsites. Including master “Check All” / “Uncheck All” buttons would be helpful. I have embedded JS code on my plugin to do this and will send you that code at the end of the weekend after my testing.
    2. It would be helpful to have an option to copy any media categories under the Organize Media that are on the site to be copied. I have some PHP code I will send you that is in my plugin that does this for when I use my plugin to copy a media item from one subsite to another subsite and will also send you this code.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for installing and trying the new example plugin. Thanks as well for your two comments.

    Regarding comment #1, I have uploaded a new MLA Development Version dated 20230428 that adds an “ALL Sites” checkbox to the Destination Site(s) list. This is a simple but adequate alternative to a more complex JavaScript approach. You can follow the steps in my previous post to get the new Development Version.

    Regarding comment #2, copying taxonomy terms from one site to another in a general way can be quite complex because the term assignments use an ID value that will differ from one site to another. It may be more than I have time for, but I will have a look at your code and investigate further.

    Thanks for your help and your understanding.

    Thread Starter Rhapsody348

    (@rhapsody348)

    David,

    I did testing this weekend and found everything working well. The “All Sites” checkbox meets the need, so I won’t send the JS code for the check box manipulation.

    I was able to generate PHP code that allowed me to copy the media categories and tags from the original site to the subsite. I only handle Media Categories and Att. Tags as listed on your General Setting tab in the section Taxonomy Support. I pasted the code in two sections below. The first section contains two functions. The first function loads an array from the source site with all the Media Categories and Att. Tags so it may be used in the second function to copy (insert) these into the target site. You will see that I handle site switching in the 2nd function and always return on the original site the routine was entered with.

    /****************************************************************
    * function get_media_cats_tags()
    * gets the categories and tags assigned by the MLA plugin used 
    * to organize media and returns an array that may be iterated for individual
    * terms and taxonomies
    * items in the array needed for copying to another site are:
    	wp_term_taxonomy => taxonomy = 'attachment_category' or 'attachment_tag'
    	wp_term_taxonomy => term_id = int on the source (created when inserted)
    	wp_term_taxonomy => description = descriptive text of term
    	wp_term_taxonomy => parent = parent term_taxonomy_id if tiered, 0 otherwise
    	wp_terms => name = text displayed as friendly name for term
    	wp_terms => slug = slug for a particular term
    	wp_terms => term_group = int, usually 0
    	wp_term_taxonomy => term_taxonomy_id = int key auto generated when inserted
    	wp_terms => term_id = int key auto generated when inserted, used to relate
    	            wp_terms and wp_term_taxonomy
    *****************************************************************/
    function get_media_cats_tags() {
    $tags = get_terms( array(
        'taxonomy'   =>'attachment_tag',
        'hide_empty' => false,
    ) );
    
    if (is_wp_error( $tags )) $tags = array();
    
    $cats = get_terms( array(
        'taxonomy'   => 'attachment_category',
        'hide_empty' => false,
    ) );
    
    if (is_wp_error( $cats )) $cats = array();
    
    //combine the media categories and tags arrays and return the combined array
    return array_merge($cats, $tags);	
    
    } // end function get_media_cats_tags()
    /*****************************************************************
    * function copy_media_cats_tags(array $media_cats_tags, int $target_site)
    * copies the media categories and tags passed in an array 
    * (use function get_media_cats_tags() for input) and creates on the target
    * site.
    * 1. if multisite, iterate through array and do the following on target_site:
    * 2. register_taxonomy_for_object_type( string $taxonomy, string $object_type )
    *    $object_type is 'attachment' for media
    * 3. wp_insert_term( string $term, string $taxonomy, array|string $args = array() )
    * 4. return to the original site
    ******************************************************************/
    function copy_media_cats_tags($media_cats_tags, $target_site) {
    
    if (is_multisite()) foreach ($media_cats_tags as $single) {
    	
    	$parent_slug = null; // initialize
    	
    	$parent_term_id = 0; // default for no parent
    
    	$site_id = get_current_blog_id(); // gets current site blog id
    
    	switch_to_blog( $target_site ); // selects the target blog
    
    
    //register the taxonomy if it does not already exist
    	if (!taxonomy_exists( $single->taxonomy )) register_taxonomy_for_object_type( $single->taxonomy, 'attachment' );
    
    //store and array of slugs in order to look up parent if needed
    	$slugs[$single->term_id] = $single->slug;
    
    // check if the term has a parent, if so need the inserted parent
    //get the original parent slug to be used for looking up inserted taxonomy
    	if ($single->parent > 0) {
    		$parent_slug = $slugs[$single->parent];
    
    //get the new inserted term as an object
    		$inserted_term = get_term_by( 'slug', $parent_slug, $single->taxonomy, $output = OBJECT, $filter = 'raw' );
    
    //extract the inserted term_id for parent
    		if ($inserted_term) $parent_term_id = $inserted_term->term_id;
    
    	} // end if ($single->parent > 0)
    		
    	$args = array(
    		'description' => $single->description,
    		'slug' => $single->slug,
    		'parent' => $parent_term_id,
    	);
    
    //insert the term if it does not already exist
    	if (!term_exists( $single->name, $single->taxonomy ) ) wp_insert_term( $single->name, $single->taxonomy, $args );
    
    } // end foreach ($media_cats_tags as $single)
    
    if (is_multisite()) switch_to_blog( $site_id ); // return to original site 
    	
    } // end copy_media_cats_tags($media_cats_tags, $target_site)
    

    Below is test code I used to force the desired subsite for testing. This could be handled in your iterative loop you have that copies the settings to each selected site where the site_id is changed.

    /***** code for testing media cats & tags copy ***/
    	$media_cats_tags = get_media_cats_tags();
    
    	if (is_multisite()) $target_id = 72; // kai site for testing
    
    	copy_media_cats_tags($media_cats_tags, $target_id);
    /*****^^^^^ code for testing media cats & tags copy ^^^^***/
    Plugin Author David Lingren

    (@dglingren)

    Thanks for sharing your code to kickstart a “Copy Terms” tool for the “MLA Multisite Extensions” example plugin.

    I have uploaded a new MLA Development Version dated 20230605 that contains the completed tool in a new example plugin version. You can find step-by-step instructions for using the Development Version in this earlier topic:

    PHP Warning on media upload with Polylang

    Once the Development Version is installed you must install (or update) and activate the example plugin. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “Multisite” in the text box and click “Search Plugins” to filter the table.

    You are looking for the “MLA Multisite Extensions” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” (or “Update”) rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate (or verify) the example plugin as you would any other plugin. Make sure you have the latest version, 1.12, installed.

    Once the Development Version and updated example plugin are installed and active you can navigate to the Settings/MLA Multisite admin screen and try the new tool for your application. You will find updates in the Documentation tab with instructions and information. I would be very interested in any suggestions you have about the documentation content.

    This example plugin enhancement will be part of my next MLA version, but in the interim it would be great if you could install the Development Version and the example plugin and let me know if it works for you. Thanks for inspiring this MLA improvement.

    Thread Starter Rhapsody348

    (@rhapsody348)

    David,

    I have updated to the latest development version and successfully used it to copy Media categories from a “Master Site” to subsites. It works exactly as expected. I will take some time over the next week to review the documentation tab.

    Nice work & Thanks!

    Thread Starter Rhapsody348

    (@rhapsody348)

    David,

    I have tested the MLA Multisite Extensions development version where you added the functions and shortcodes to copy multisite settings and media terms. These were in the MLA Multisite Extensions development version 20230708. I tested both a new site setup and copying the settings and terms to selected sites that already exist. I can report that these work great so you may incorporate the development version into your next full release. Thanks for taking the time to do this!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for working with me by email to develop and test the shortcodes and API functions I added to the latest update. Thanks as well for the good news on the results. All of these improvements will be in my next MLA version.

    Thread Starter Rhapsody348

    (@rhapsody348)

    David,

    I just installed the 3.10 update that includes the updates you had in the development version I was testing.

    Question – Do I need to uninstall and reinstall the MLA Multisite Extensions after the 3.10 update? The MLA Multisite Extensions are listed as version 1.13.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Save and Import Settings for Multisite’ is closed to new replies.