WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multisite Theme Edit (24 posts)

  1. Bettega
    Member
    Posted 3 years ago #

    Greetings,

    I have a multisite installs with six sites and six themes (one for each site). The themes are activated on a per-site basis (super-admin->sites->edit).

    Is there a way to grant to the site admin the permission to edit the theme allowed for his site? It seems that only a super-admin can edit themes, that's true?

  2. It seems that only a super-admin can edit themes, that's true?

    Yep.

  3. Bettega
    Member
    Posted 3 years ago #

    Humm, I see :/

    Any ideas on how to change this? Maybe a plugin like "User Role Editor"?

  4. I doubt that plugin has anything to bridge Between a blog administrator and a super admin. I don't know of any that does.

    What kind of edits are they making? If it;s just css, give them one of these plugins:
    http://wpmututorials.com/plugins/css-editor-plugins/

  5. rickymurphy
    Member
    Posted 3 years ago #

    I would also like a way to give regular admins (not just super-admins) access to the full-blown theme editor.

  6. Bettega
    Member
    Posted 3 years ago #

    @Andrea_r: We have a small network of like-minded sites (one about Tolkien, another about Literature, another one about Books and so on). Every site have his own unique template and we have to give to the Admin of the site the right to edit the template assigned to his site. I'll try to hack the code and see what I can find/do =]

  7. There's a plugin called Userthemes for mu, but last I had heard it wasn;t quite working in 3.0. that may have changed tho.

  8. Bettega
    Member
    Posted 3 years ago #

    Ok, I did it. It was not pretty, but it works.

    a) In the file menu.php I changed the line

    add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php');

    to

    add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'switch_themes', 'theme-editor.php');

    b) In the file theme-editor.php I changed the line

    $themes=get_themes();

    to

    $themes=get_allowed_themes();

  9. Inserting standard disclaimer here that people with open signups really *really* do not want to do this. ;)

  10. remizyaka
    Member
    Posted 3 years ago #

    didn't help for me

    You do not have sufficient permissions to edit templates for this site.

    that's what I see on theme editor page,
    admin user have all theme capabilities on this site ...

  11. maveseli
    Member
    Posted 3 years ago #

    Hi

    In order to allow blog admins to edit only the themes they are using on their blog I just removed form for selecting theme in file theme-editor.php. Now only selected theme is shown in editor.

    Also changed what Bettega mention in menu.php and now I can see edit theme menu item but still get following message:

    "You do not have sufficient permissions to edit templates for this site."

    Does anybody knows how to get this permisions.

    Thanks

  12. jroakes
    Member
    Posted 3 years ago #

    To add the editor to your MU accounts:

    <?php
    
       /*
    
       Tested Working on WordPress Multisite 3.1
    
       Instructions:
       		1. Place this text in a file in the wp-content/mu-plugins/ folder.
       		2. Make the following edits:
    
       EDIT 1: in wp-admin/theme-editor.php
    
    	   Comment out this line as so:
    
    	 	/*
    		if ( is_multisite() && ! is_network_admin() ) {
    		wp_redirect( network_admin_url( 'theme-editor.php' ) );
    		exit();
    		}
    
       EDIT 2:
    
    	Replace:
    		$themes = get_themes();
    	With:
    		$themes=get_allowed_themes();
    
                    3. Done.
    
    	*/
    
    	add_action('admin_menu', '_add_themes_utility_editor', 102);
    
     	function _add_themes_utility_editor() {
    	// Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook
    	add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'switch_themes', 'theme-editor.php');}
    
       // get the the role object
       $editor = get_role('administrator');
       // add $cap capability to this role object
       $editor->add_cap('edit_theme_options');
       $editor->add_cap('edit_themes');
    
    ?>
  13. mpfeifer
    Member
    Posted 3 years ago #

    Hi jroakes.

    Thank you very much. This is exactly what I need.
    Now I can see the editor-Link, bit when I click on it, I get the message:
    "You do not have sufficient permissions to edit templates for this site."

    The user has the role "Administrator" for this specific blog.

    Is there something else which needs to be done?

    Regards, Markus

  14. jroakes
    Member
    Posted 3 years ago #

    Try doing a hard refresh (ctrl +f5). This is what worked for me. I cannot think of anything else that I did. If something comes to mind I will report back.

  15. dallasm
    Member
    Posted 3 years ago #

    Hi, Another option might be a highly customisable theme like Weaver 2.0
    This is built on the default twenty ten theme but allows the user to make heaps of tweaks to sidebars, css headers, widgets etc etc.
    Only superadmin can edit the theme but the users get huge flexibility. Great theme with good support at wpweaver.info

  16. jrue
    Member
    Posted 3 years ago #

    @jroakes Thanks for the code. It almost works. The themes link shows up, but I get the following error.

    Fatal error: Cannot redeclare _add_themes_utility_editor() (previously declared in /Volumes/staging/test_site/wp-content/plugins/theme-editor.php:44) in /Volumes/staging/test_site/wp-content/plugins/theme-editor.php on line 44

    In theme-editor.php I only commented out the following:

    if ( is_multisite() && ! is_network_admin() ) {
    		wp_redirect( network_admin_url( 'theme-editor.php' ) );
    		exit();
    		}

    I didn't notice the closing comment tag, so I assumed it was only this block of code. Also switched to
    $themes=get_allowed_themes();

    Thanks in advance.

  17. jrue
    Member
    Posted 3 years ago #

    Hi All, I found the issues. It was two things.

    First: the Fatal Error I had was because I stupidly named the plugin the same name "theme-editor.php" Once I changed to something unique, that error went away.

    The permissions error dallasm was getting was fixed by commenting out a few additional lines of code in wp-admin/theme-editor.php

    Here is what needs to be commented out:

    /*
    if ( is_multisite() && ! is_network_admin() ) {
    	wp_redirect( network_admin_url( 'theme-editor.php' ) );
    	exit();
    }
    
    if ( !current_user_can('edit_themes') )
    	wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site.').'</p>');
    */

    Thanks again for the plugin. Works perfectly. I need these for a controlled classroom instruction where each student will have a unique theme they are editing, so there is no concern of one person editing a theme that another WP site is using.

  18. jroakes
    Member
    Posted 3 years ago #

    Glad you got it working!

  19. jroakes
    Member
    Posted 3 years ago #

    You might want to use the following code...

    /*
    if ( is_multisite() && ! is_network_admin() ) {
    	wp_redirect( network_admin_url( 'theme-editor.php' ) );
    	exit();
    }
    */
    
    if ( !is_admin() )
    	wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site.').'</p>');

    ...instead of just commenting out both if statements. The first if statement is ok because it is just really checking to see if this is a MU install. The second one checks to see if you should be there. I would at least put an is_admin() test.

  20. Donald McIntyre
    Member
    Posted 3 years ago #

    I also need for single site admins to be able to edit their themes, but I don´t understand the first part: "1. Place this text in a file in the wp-content/mu-plugins/ folder." I created a .php file within the plugins folder. Or I have to create a folder and then a .php? I am not a programmer! can some one explain the whole thing "for dummies" please?

    This is what I did:

    1. created wp-content/plugins/chachacha.php
    2. chachacha.php has the code:

    <?php
    add_action('admin_menu', '_add_themes_utility_editor', 102);

    function _add_themes_utility_editor() {
    // Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook
    add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'switch_themes', 'theme-editor.php');}

    // get the the role object
    $editor = get_role('administrator');
    // add $cap capability to this role object
    $editor->add_cap('edit_theme_options');
    $editor->add_cap('edit_themes');

    ?>

    3. "comment out" (that I guess is to put /* and */ at the beggining and end of the thing to be commented out)

    /*
    if ( is_multisite() && ! is_network_admin() ) {
    wp_redirect( network_admin_url( 'theme-editor.php' ) );
    exit();
    }

    if ( !current_user_can('edit_themes') )
    wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site.').'</p>');
    */

    4. Changed:

    $themes = get_themes();
    With:
    $themes = get_allowed_themes(); (notice I put a space before and after the = sign)

    5. Went to one users dashboard and ... nothing... The edit link does not show. I am frustrated it´s been 3 days looking for this functionality...

    I am using WP 3.1.2 Multisite and BuddyPress.

    Thank you! and pls somebody pls help me!!! (as if I was a 3 year old!)

  21. jrue
    Member
    Posted 3 years ago #

    @donmcint

    In order for a plugin to show up in the admin, you have to put some comment code at the top so that WordPress will detect is as a plugin. At the top of "chachacha.php" add the following:

    <?php
    /*
    Plugin Name: Theme Editor
    Plugin URI: http://wordpress.org/extend/plugins/
    Description: Allows Theme Editor in MU
    Author: jroakes
    Version: 0.1
    */

    After that, go into network admin, not just the admin of each site.

    Hope this helps.

  22. However...

    This is what I did:

    1. created wp-content/plugins/chachacha.php
    2. chachacha.php has the code:

    And

    "1. Place this text in a file in the wp-content/mu-plugins/ folder."

    is your problem. Move the file to MU-PLUGINS. If the folder doesn't exist, you can safely create it.

    And you don't need a plugin header for files in mu-plugins, though they're nice :)

  23. Donald McIntyre
    Member
    Posted 3 years ago #

    Thx guys!! It worked!!

    My suggestion to WordPress is to let WP Multisites installs to have it own Theme and Plugin repository folders and when a member creates a site he should be able to use the themes and plugins, but copied in their own sub.site so they can edit without changing other member´s themes and plugins.

    Thank you JRUE and IPSTENU!!!!!!!!!!

    Donald.

    PS: and JROAKES for creating it!!

  24. That would defeat the point of MultiSite, alas.

    The idea of MultiSite is 'You're running your own version of WP.com'

    You can't edit your theme there (you can edit CSS, and other per-theme settings, but NOT the theme files). Can't edit plugins either.

    There IS a reason for this: If someone can edit your PHP files, then they can use that to write code that gives them access to the REST of your install and, logically, your server. It's a HUGE security hole, and WP would rather protect you.

    If everyone needs to be able to customize their themes and plugins, you're better off with multiple single, separate, sites.

Topic Closed

This topic has been closed to new replies.

About this Topic