Customise the theme customiser

Hi, Is it possible to block certain features in the theme live customiser for all the administrator of Multisite subsite without having to edit the theme core file so that every update will go easy and smooth? I would like to block and hide the following functions:

1. Hide and block the Draggable elements which is in the left bar inside the upfront customiser.

2. Able to show preview button once saved just like the spirit demo. Currently after installation and going to live customiser, it only shows save button.

3. Complete block and hide the custom "css styles & anchor settings" that comes up within any created block or element in the page. Eg. Text box appearance, select preset, etc.

4. Complete block, hide the creating menu, page and post via theme customiser. This also means that admin cannot change the menu link only. But able to add custom link in buttons, read more tag and other link.

4. Disable and hide the light box element. Since we are not letting any admin to add any elements in the page

5. Disable and hide the delete "X" option in any of the element. Bacically we are not allowing admin to add or delete any of the element we created. All the can do it edit the element that already exits.

6. Add redirection link in the "edit profile" to either buddy press profile or customs profile that we will create at later stage.

Anyway may be by this time you already know that in the Multisite expect super admin. No one are allowed to add or delete page content, page, post, menu custom css. All they can do it edit whatever that is in the page.

I am not sure how to do it without customising the theme file. Any alternative suggestion will do too. Unless if there is a way to create Multisite by only giving capability as an author only when any anyone creates or register for the site from the beginning and also automatically. Without having a superadmin do or change it manually. Also still able to go to customiser.

Basically, we are trying to make Multisite admin or owner edit the existed page and post via front end only. No access to the Wordpress backend. I can and am able to restrict the admin not to go specific backend page with a plugin we have created.

Thanks and hoping to hear from you guys soon

Bhupen T

Apex World.

    Milan

    Hi Bhupen,

    Welcome to Wpmu Dev Community.

    I hope you are having a good day and thanks for posting a question.

    I've read every bit of your question also tried to find solution but the level of customization you want is not currently possible out of box with upfront.

    I wonder this plugin may help you achieve some of the customization with roles and restriction. https://wordpress.org/plugins/multisite-user-management/. This plugin will let you set default role to each user created with site, and then you can use https://wordpress.org/plugins/user-role-editor/ to customize capability of perticular role.

    Again the level of customization is not possible right now. I suggest you to post a job on our job portal https://premium.wpmudev.org/jobs/new-job/ for this.

    I hope this helps you.

    Please let me know if there is anything else I can help you with.

    Enjoy Wpmu-dev.

    Warmest Regards,
    Milan.

      Apex World

      Hi, I have looked at the plugin, and seems like you pointed me to the right direction.

      I checked it out and I set the administrator capabilities "not create the page", but In the live upfront customiser I can still see "add page and post" and when I clicked it, it will take admin to add page URL but it doesn't seem to save at all (that will just be in draft for revision" since admin doesn't have the capability to publish a page.) But isn't it supposed to not show the "add page, post" option at all since they don't have the capabilities? Cause if I go to in the Wordpress backend there is no menu to add a page at all. It should be the same in the fronted customiser too. Is it a glitch here or am I missing something here..?

      Also why there is no preview button in the upfront customiser just like the demo site editor -spirit that you guys have. I can't seem to see the "preview button" after I hit save in the live upfront customiser. Thanks

    Milan

    Hi Bhupen,

    I am happy that solution helped you with something.

    Right now upfront is not providing facility to hiding those elements for non-admin user. Because we think that every user can request level of customization he/she wants with upfront. So Upfront creates revision as user customizes page.

    If you want to completely disable upfront for specific role you can do this with this filter,

    function stop_upfront_for_user($perms) {
       //Again you can tweak below condition. :)
    
       //You can grab wordpress user role and evaluate condition.
        if (1 == get_current_user_id() ) {
                     //this will flag upfront that do not let user customize.
                      return array(Upfront_Permissions::DEFAULT_LEVEL => false);
        }
        else return $perms;
    }
    add_filter('upfront-access-permissions_map', 'stop_upfront_for_user');

    If you really want to change permission for upfront, all the permission which controls upfront are listed as constants in /wp-content/themes/upfront/library/ class_upfront_permissions.php . But I suggest you do not edit core files as your changes will not be preserved when upfront gets updated.

    On our demo site you see preview button that's because we don't let user customize and save customization. Otherwise it will be like every single user's own customized page.. But normally on your environment you will save changes that you've made with upfront and see it's reflection on live site.

    I hope this helps you dear Bhupen.

    Please let me know if there is anything else I can help you with.

    Enjoy Wpmu-dev.

    Warmest Regards,
    Milan.

      Apex World

      Hi, seems like that code will not do any good for me at all. The above code simply disables the upfront customiser as in whole. I am after something like removing the left upfront sidebar expect the "SAVE" button and allow them to edit whatever content is in the page. So basically remove the left bar expect the SAVE button but still allow them to edit the content which can be done easily just double clicking the text, dragging the adjust the position resizing the image and so and so. Is there is any hooks or filters action if i can use it like this? :

      function modify_capabilities()
      {
      // get the role of administrator"
      $administrator_role = get_role('administrator');
      $administrator_role->remove_cap('publish_pages');
      }
      add_action('admin_init','modify_capabilities');

      if ( !current_user_can('publish_pages') ) {
      //remove all the upfront customiser left bar's section except the "SAVE" Button
      }
      else //some code ;
      }
      //add filter;

      If its not possible with filters, or hooks then could you please give me some step wise instruction to modify the theme file. I really need to remove the those of the upfront customiser left bar except the "save" button but still allow them to edit from the right whatever option is available. Even if i have to delete some theme code just not to show the left bar option at all until the save button, i will do it. Thanks so much

      Bhupen T

    Milan

    Hi @Apex World,

    I hope you are having a good day and sorry for being late.

    There is one filter you could use for removing upfront customize elements. Upfront provides upfront-core_modules-load_module filter. Function hooked to this filter will accept 2 arguments.
    1) bool ( whether to include this element )
    2) which element we're dealing with

    Here is sample demonstrating how you can use this filter.

    function remove_upfront_elements( $includeThisElement, $elementWeAreDealingWith ){
    
            // var_dump( $includeThisElement );    //Boolean
            // var_dump( $elementWeAreDealingWith );    //element path
    
    	if( $elementWeAreDealingWith == 'element_path_you_do_not_want_to_include' ){
               		return false;
    	}
    
    	return $includeThisElement;
    }
    
    add_filter( 'upfront-core_modules-load_module', 'remove_upfront_elements', '', 2 );

    I hope this helps you Bhupen.

    let me know how it goes.

    Best Regards,
    Milan.

    Apex World

    Hello @Milan,
    Could you please clarify with an real example as well. I can't seem to understand. "$includeThisElement", "$elementWeAreDealingWith", ''element_path_you_do_not_want_to_include''

    1) element path - are you talking about the actual folder path of the element?
    2) Element Name - For e.g.. is it the var name " $text-upfront " or just " $text "

    I tried but gives me a white screen in the front end. So still stuck. For an example, lets say we remove the textbox element or any up to you. how would you do it the right way? thanks

    Milan

    Hi Bupen,

    I trust you are enjoying with us.

    Sorry to hear that my example confused you. But I am sure this example will give you better idea.

    Let say I want to remove gallery element, then code will be like.

    /*
    
    $includeThisElement: value of this variable will be boolean. If you return its value true, then elementWeAreDealingWith will displayed to user. If you return its value false, elementWeAreDealingWith won't included to upfront customizer.
    $elementWeAreDealingWith: This variable will give you current processing element's full path.
    
    */
    
    function hide_sidebbar( $includeThisElement, $elementWeAreDealingWith ){
    
    	//var_dump( $elementWeAreDealingWith );
    	//var_dump( $includeThisElement );
    
    	// Let's say I want to remove gallery from customizer
    	// so when gallery element will be ready to be processed $elementWeAreDealingWith will give me full path of gallery element.
    	// Iy my case it is "E:\xampp\htdocs\wpmudev-test/wp-content/themes/upfront/elements//upfront-gallery/loader.php". ( You can use var_dump( $elementWeAreDealingWith ) to know current processing element's path )
    	// So if i don't want to include gallery element in upfronot customizer, I can use condition like
    
    	if( $elementWeAreDealingWith == 'E:\xampp\htdocs\wpmudev-test/wp-content/themes/upfront/elements//upfront-gallery/loader.php' ){
    		$includeThisElement = false;
    	}
    
    	return $includeThisElement;
    }
    
    /*
    * This filter will be executed prior to new element being added in upfront customizer
    */
    add_filter( 'upfront-core_modules-load_module', 'hide_sidebbar', '', 2 );

    Bhupen there is also one nice plugin for managing custom code snippets,
    https://wordpress.org/plugins/code-snippets/

    Please also keep in mind that above code will completely remove gallery element functionality for that particular user. That means code won't let gallery function well for specific user. Furthermore above code is not advisable to use as it will stop core elements functioning well.

    So my suggestion to you is that you post new job for this requirement, You can post new job from here.

    https://premium.wpmudev.org/jobs/new-job/

    Let me know if you have any further question.

    With Kind Regards,
    Milan.

    Milan

    Hi Bhupen,

    I am sorry that you had to face this issue.

    Is there any JS or php code that checks the element loaded or not? May be something like show "loading" text until all elements are loaded or prepared..

    Upfront by default will show loading process by displaying loading icon, until every element is loaded. Are you talking about that loading process or something else ? please advice me about this.

    I have seen an update on " Upfront" - Does the above function works on 0.4.1.1 and spirit 0.1.7 ?

    I've tested with latest versions of both upfront and spirit, unfortunately code will not work with latest version too.

    Let me know if you have further query.

    Best Regards,
    Milan.

    Apex World

    I was taking about the loading process. So basically every time if I put the filters, the "/?edit=true" page keeps on showing the loading icon forever. I am not sure how long. Max I waited was around 2-3 mins.

    If I remove the filter, then loads quickly. So I thought, may be there's a JS or php is checking if all the elements are loaded or not before showing the customise page. I checked through some of the php files but seems like it's too many connections pretty hard it's a jargon down there.

    So, anyway I can't look at all the files one by one coz not much experience with Wordpress php. So just asking will there be any code that may work? Or are we both wasting time here for this solution.?

    Thanks
    Bhupen T