• Resolved Rhapsody348

    (@rhapsody348)


    Hello Javier,

    I have been using your plugin successfully for a few years in a multisite environment. I was wondering if you would consider an enhancement for importing the Extra Profile fields that are stored in user meta. WordPress uses the functions insert_user_meta and add_user_meta to store the user meta values in the {wp_prefix}usermeta table. This is also available globally for a particular user across all sites in a multisite installation.

    In order to have user meta Extra Profile fileds accessible only to a single site in a multisite installation, the function update_user_option is used to save the user meta. The WordPress function automatically prepends the multisite table prefix to the option name. The WordPress functions to retrieve the user meta such as get_user_option recognizes the prefix and only loads the user meta on the desired site. Thus if a user is imported on a particular site, the Extra Profile fields are only available on that site.

    Would it be possible to provide a checkbox on the import setup to determine if the Extra Profile fileds user meta should be imported as globally available or on a per site basis? This could be added as a checkbox under the Update Users section of the Import tab, or as checkboxes next to each field on the Extra Profile Fields tab. The selection would determine if the user meta.

    Another method might be to include and optional row on the import table that defined how an extra profile field is handled. Below is a sample CSV pasted showing the optional 1st row with global and site annotations.

    global,global,global,global,global,global,site,site
    Username,Email,display_name,first_name,last_name,mobile,allposts,corecrew
    johnsmith,[email protected],Sailor,John,Smith,4015551212, yes, yes
    

    Thanks for your consideration. This is a great plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Javier Carazo

    (@carazo)

    @rhapsody348,

    It can be exciting, but the development would be complex and only solve problems for people who use multisite (which are not the majority).

    Maybe create some custom addon can be the solution but it would take some time.

    Thread Starter Rhapsody348

    (@rhapsody348)

    Thanks – I understand Javier.

    I’ve posted a solution that was added to my plugin to accommodate two fields ‘allposts’ and ‘corecrew’. These fields are included on an import template provided to multisite admins for importing users on their sites. It also incorporates an action button at the bottom of the page displayed after import. I am using the shortcode [acui_import] from your plugin to provide the import page.

    The solution below may help other multisite users.

    // this is triggered after acui import and displays the refresh page button
    /******************************************************************
     * function cm_acui_add_message( ) hooks the import plugin 
     * after acui import and forces a users cache update,
     * fixes global allposts and corecrew to local and 
     * displays the refresh page button
    *******************************************************************/
    if (isset($users_created) || isset($users_updated) || isset($users_deleted) || isset($users_ignored)) do_action( 'acui_after_import_users', $users_created, $users_updated, $users_deleted, $users_ignored );
    
    add_action( 'acui_after_import_users', 'cm_acui_add_message', 10, 4);
    
    function cm_acui_add_message( $users_created, $users_updated, $users_deleted, $users_ignored ) { 
    // this is the cache control for user query
    	cm_cache_control($key = 'ID', $group = 'users', $force_flush = TRUE); // clear the cached user data to force a new query; // clear the cached user data to force a new query
    
    // loop through the new users users imported and update 'corecrew' and 'allposts' to local
    foreach ($users_created as $user_id) {
    $status = delete_user_option( $user_id, 'allposts', TRUE); // deletes if set global on import, data will be saved locally
      ($status) ? update_user_option( $user_id, 'allposts', 'yes', FALSE ) : delete_user_option( $user_id, 'allposts', FALSE); // saves local
    
    $status = delete_user_option( $user_id, 'corecrew', TRUE); // deletes if set global on import, data will be saved locally
      ($status) ? update_user_option( $user_id, 'corecrew', 'yes', FALSE ) : delete_user_option( $user_id, 'corecrew', FALSE); // saves local
    }
    
    $refresh_message = '<br><br><b>Click</b> <input type="button" value="Refresh Page"  title="Refresh Page to display Import File Chooser"  onClick="window.location.href=window.location.href"><b> after reviewing imported data to restore the Crew Import file chooser, or navigate to another page if done</b>';
    
    echo $refresh_message;
    }
    Plugin Author Javier Carazo

    (@carazo)

    Thanks for sharing the code.

    But this is a custom code for you, this use cm_cache_control and other metas like allposts and corecrew that are not from WordPress core standard.

    Anyway thanks for it and I will try to make possible the multi site functionality in the future.

    Thread Starter Rhapsody348

    (@rhapsody348)

    Yes – you are correct that the cache control is my own and not needed for others. The coreposts and allcrew are custom fields that are used on my sites. I hard coded these fields to make this work for my application as indicated in my original post.

    A long term solution for the proposed enhancement would be to provide logic that accommodates any custom fields added by a user so these fields may be selected as global or site specific for import on multisite installations.

    Your plugin is already excellent with many features. The shortcodes provide flexibility for advanced users. Thanks for all the support!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Enhancement for Multisite User Meta Import’ is closed to new replies.