Editoren erlauben, Menüs zu bearbeiten?
7 Antworten
- Stimmen
-
- 2011-02-24
Fügen Sie dies zu den
functions.php
Ihres Themas hinzu:// add editor the privilege to edit theme // get the the role object $role_object = get_role( 'editor' ); // add $cap capability to this role object $role_object->add_cap( 'edit_theme_options' );
add this to your theme's
functions.php
:// add editor the privilege to edit theme // get the the role object $role_object = get_role( 'editor' ); // add $cap capability to this role object $role_object->add_cap( 'edit_theme_options' );
-
istget_roleeine Klasse?is get_role a class?
- 1
- 2011-02-24
- Mild Fuzz
-
@Mild Fuzz -nicht selbstnein,aberesgibt eine Instanz von `WP_Role` zurück@Mild Fuzz - not itself no, but it returns an instance of `WP_Role`
- 4
- 2011-08-14
- TheDeadMedic
-
Sie sollten dies wahrscheinlichnichtbei jeder Anfragetun,da diesnachmeinem Verständnis zueinem Datenbankschreibenführt.Besser auf `admin_init` undnur`if! $ Role_object-> has_cap ('edit_theme_options') `You probably shouldn't do this on every request, as this causes a db write as far as i understood. Better on `admin_init` and only `if !$role_object->has_cap('edit_theme_options')`
- 9
- 2017-02-14
- jsphpl
-
Diese Einstellung wirdin der Datenbankgespeichert (in der Tabelle wp_options,Feld wp_user_roles),daheristesmöglicherweisebesser,siebei der Aktivierung des Themas/Plugins auszuführen.Siehe https://codex.wordpress.org/Function_Reference/add_capThis setting is saved to the database (in table wp_options, field wp_user_roles), so it might be better to run this on theme/plugin activation. See https://codex.wordpress.org/Function_Reference/add_cap
- 0
- 2018-03-12
- Pim Schaaf
-
Oder Sie könnenes zufunctions.php hinzufügen,einmal ausführen und dannentfernenOr you could add it to functions.php, run it once and then remove it
- 0
- 2019-01-16
- d79
-
- 2013-04-16
BEARBEITEN: Updatefür WP 4.9 & amp;nur Menüelementefür Editor
ausblendenWenn Siemöchten,dass Ihre Benutzer das Navigationsmenü ändern können,nichtjedoch die anderen Optionen unter Darstellung: Verwenden Sie diese Option
// Do this only once. Can go anywhere inside your functions.php file $role_object = get_role( 'editor' ); $role_object->add_cap( 'edit_theme_options' );
Sie können diesengesamten Code auskommentieren,nachdem Sie Ihr Admin-Panel aktualisiert haben,da der obige Code dauerhafte Änderungen an der Datenbank vornimmt.
Sie habenjetzt alle Optionen unter Darstellungfür die Redakteure sichtbar. Sie können die anderen Optionen wiefolgt ausblenden:
function hide_menu() { if (current_user_can('editor')) { remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php' ); // hide the customizer submenu remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php&autofocus%5Bcontrol%5D=background_image' ); // hide the background submenu // these are theme-specific. Can have other names or simply not exist in your current theme. remove_submenu_page( 'themes.php', 'yiw_panel' ); remove_submenu_page( 'themes.php', 'custom-header' ); remove_submenu_page( 'themes.php', 'custom-background' ); } } add_action('admin_head', 'hide_menu');
Die letzten 3 Zeilenin der Funktion
hide_menu()
sindthemenspezifischfürmein Thema. Siefinden den zweiten Parameter,indem Sieim Admin-Bereich auf das Untermenü klicken,das Sie ausblendenmöchten. Ihre URL lautet dann wiefolgt:example.com/wp-admin/themes.php?page= yiw_panelIn diesem Beispiel lautet der zweite Parameterfür die Funktion
remove_submenu_page()
yiw_panel
EDIT: update for WP 4.9 & only hiding menu items for Editor
If you want your users to be able to change the navigation menu, but not the other options under appearance: use this
// Do this only once. Can go anywhere inside your functions.php file $role_object = get_role( 'editor' ); $role_object->add_cap( 'edit_theme_options' );
You can comment out this entire code after you have refreshed your admin panel, because the above code will make persistent changes to the database.
You now have all the options under appearance visible to the editors. You can hide the other options like so:
function hide_menu() { if (current_user_can('editor')) { remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php' ); // hide the customizer submenu remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php&autofocus%5Bcontrol%5D=background_image' ); // hide the background submenu // these are theme-specific. Can have other names or simply not exist in your current theme. remove_submenu_page( 'themes.php', 'yiw_panel' ); remove_submenu_page( 'themes.php', 'custom-header' ); remove_submenu_page( 'themes.php', 'custom-background' ); } } add_action('admin_head', 'hide_menu');
The last 3 lines in the
hide_menu()
function are theme specific for my theme. You can find the second parameter by clicking on the submenu you want to hide, in the admin panel. Your URL will then be something like: example.com/wp-admin/themes.php?page=yiw_panelSo, in this example, the second parameter for the
remove_submenu_page()
function will beyiw_panel
-
Dies verbirgt Themen usw. auchfür Administratoren.this hides themes etc for admins too.
- 1
- 2017-09-15
- JorgeLuisBorges
-
- 2014-01-09
In WordPress 3.8 wäre diesein besserer Code als die aktuell akzeptierte Antwort.
/** * @var $roleObject WP_Role */ $roleObject = get_role( 'editor' ); if (!$roleObject->has_cap( 'edit_theme_options' ) ) { $roleObject->add_cap( 'edit_theme_options' ); }
In WordPress 3.8, this would be better code than the current accepted answer.
/** * @var $roleObject WP_Role */ $roleObject = get_role( 'editor' ); if (!$roleObject->has_cap( 'edit_theme_options' ) ) { $roleObject->add_cap( 'edit_theme_options' ); }
-
- 2010-11-17
Wennichmir die Admin-Menüstruktur ansehe,scheintes Der Link
nav-menus.php
ist an die Funktionedit_theme_options
gebunden.Können Sie die Editorrolle ändern,um diese Funktioneinzuschließen?Dies würdeihnen auch die Möglichkeitgeben,Widgets zubearbeiten ,ich weißnicht,ob dasein Problemist?Alle Ajax-Menüelemente sind durch diese Funktioneingeschränkt,sodass das Ändern der Administratormenüfunktion zum Bearbeiten von Menüs wahrscheinlichnichtfunktioniert.When I look at the admin menu structure, it seems the
nav-menus.php
link is tied to the capabilityedit_theme_options
. Can you modify the editor role to include this capability? This would also give them the option to edit widgets, I don't know whether this is a problem? All the menu Ajax stuff is restricted by this capability, so just changing the admin menu capability for editing menus will probably not work. -
- 2011-04-14
Plugin "User Role Editor"installieren -edit_theme_options EIN schalten - Plugininstallieren Adminimize - "Widgets" und "Theme wechseln"für Editoren ausschalten;)
instal plugin "User Role Editor" - Switch edit_theme_options ON - install plugin Adminimize - switch off "Widgets" and "Switch Theme" for Editors ;)
-
- 2011-01-05
Ich habefestgestellt,dass Ihr Menüfolgendermaßenfunktioniert: Plugininstallieren " Benutzerrollen-Editor "und dort können Sie die Bedingungenfür die Editor-Rolle und anderebearbeiten.Schalten Sieedit_theme_optionsein.Aberjetzt: Sie sehen "Menü" -Option unter "Themen","Widgets". Fürmich: Nach dem Klicken auf "Menü" (als Editor) seheich keinegefüllten Optionen,aber leer.Also habeich das Plugin "User Role Editor" deaktiviert und die ausgefüllten Optionenfür "menu" werden korrekt angezeigt.Beachten Sie,dass das Deaktivieren des Plugins "User Role Editor" die Bedingungenfür den aktiven Editorbleiben!Gutfürmich,vielleicht hilftes dir auch
I´ve found, that your menu will work this way: instal plugin "User Role Editor" and there you can edit condition for editor role and other too. Switch edit_theme_options ON. But now: you will see "menu" -option under "themes", "widgets". For me: After click to "menu" (as editor) I´d not see filled options but empty. So I´d deactivate plugin "User Role Editor" and filled options for "menu" appears correctly. Note that deactivating plugin "User Role Editor" remains conditions for editor active! Good for me, maybe it will help you too
-
- 2020-03-30
Esist 2020,WordPressistjetztnach V5.3,also dachteich,ich würdeeine aktualisierte Versionbeisteuern,in der die Einstellungnureinmalin der Datenbankgespeichert wird -bei Aktivierung des Themas undentfernt,wenn das Thema deaktiviert wird.
function add_theme_caps(){ global $pagenow; // gets the author role $role = get_role('editor'); if ('themes.php' == $pagenow && isset($_GET['activated'])) { // Test if theme is activated // Theme is activated // This only works, because it accesses the class instance. // would allow the editor to edit the theme options $role->add_cap('edit_theme_options'); } else { // Theme is deactivated // Remove the capability when theme is deactivated $role->remove_cap('edit_theme_options'); } } add_action( 'load-themes.php', 'add_theme_caps' );
Ichbevorzugees auch,in einem OOP-Stil zu codieren,daherist dieseine OOP-Version:
/** * YourClient Class * * @author John Doe * @package YourClient * @since 1.0 */ if (!defined('ABSPATH')) { exit; } if (!class_exists('YourClient')) { /** * The main YourClient class */ class YourClient { /** * Setup class */ public function __construct() { // Give more privileges on Theme Activation add_action('load-themes.php', array($this, 'add_theme_caps')); } function add_theme_caps() { global $pagenow; // gets the author role $role = get_role('editor'); if ('themes.php' == $pagenow && isset($_GET['activated'])) { // Test if theme is activated // Theme is activated // This only works, because it accesses the class instance. // would allow the author to edit others' posts for current theme only $role->add_cap('edit_theme_options'); } else { // Theme is deactivated // Remove the capability when theme is deactivated $role->remove_cap('edit_theme_options'); } } } }
It's 2020, WordPress is now past V5.3 so i thought i would contribute an updated version in which the setting is saved only once in the database - upon theme activation, and removed when the theme is desactivated.
function add_theme_caps(){ global $pagenow; // gets the author role $role = get_role('editor'); if ('themes.php' == $pagenow && isset($_GET['activated'])) { // Test if theme is activated // Theme is activated // This only works, because it accesses the class instance. // would allow the editor to edit the theme options $role->add_cap('edit_theme_options'); } else { // Theme is deactivated // Remove the capability when theme is deactivated $role->remove_cap('edit_theme_options'); } } add_action( 'load-themes.php', 'add_theme_caps' );
I also prefer to code in an OOP style so this is an OOP version:
/** * YourClient Class * * @author John Doe * @package YourClient * @since 1.0 */ if (!defined('ABSPATH')) { exit; } if (!class_exists('YourClient')) { /** * The main YourClient class */ class YourClient { /** * Setup class */ public function __construct() { // Give more privileges on Theme Activation add_action('load-themes.php', array($this, 'add_theme_caps')); } function add_theme_caps() { global $pagenow; // gets the author role $role = get_role('editor'); if ('themes.php' == $pagenow && isset($_GET['activated'])) { // Test if theme is activated // Theme is activated // This only works, because it accesses the class instance. // would allow the author to edit others' posts for current theme only $role->add_cap('edit_theme_options'); } else { // Theme is deactivated // Remove the capability when theme is deactivated $role->remove_cap('edit_theme_options'); } } } }
Ichmöchtemeinen Redakteuren die Möglichkeitgeben,das Menü zu ändern. Kann dies durchgeführt werden?
Die Registerkarte "Darstellung" scheint überhaupt keine Option zu sein. Kannich das somachen?