create_function() is deprecated as of PHP 7.2.0, so you should avoid using it. Instead, use an anonymous function.
Additionally, it’s better the check the current user role inside the callback function, so that the current user role is checked when the filter is applied, not when the hook is added, which could be before the current user role can be determined.
add_filter(
'wp_default_editor',
function( $default_editor ) {
if ( current_user_can( 'editor' ) || current_user_can( 'author' ) ) {
$default_editor="html";
}
return $default_editor;
}
);
Related Posts:
- Solution to render Shortcodes in Admin Editor
- Apply custom role capabilities to administrator (without plugin)
- Roles & capabilities GUI that does not create separate table
- VERY new to coding – keep breaking site trying to add to functions.php
- How do I redirect upon login a specific user based on role?
- How to add another user to this remove_menu function?
- Add a new subscriber role using a function
- How to test for Super Admin
- Custom roles can’t access to wp-admin
- Custom registration URL lost when user makes signup mistake
- Custom function for specific user role
- Hide Author.php template from specific user role
- wpautop – disable tags, keep tags
- edit role display name and label name without plugins
- Tiny MCE-modifications (plugins) stopped working in WordPress 5.6
- create shortcode to list users with specific meta key value
- Toggle User Roles with button
- Publish/Update post is changing image links from file url to post url
- How to change or add user role after getting post request data about pay? [closed]
- Execute a ultimate member action when user role is updated
- Insert image in WordPress with HTML5 tag and caption function
- Allowing users to view private posts (pending approval)
- WordPress functions.php – Execute plugin specific user online
- Allow Contributor to edit their own posts after Adm aproval
- How to add custom JavaScript in functions?
- load CSS only for administrators on backend
- Adding additional roles on registration
- Where do I go to edit this area? [closed]
- The Capability to choose post/page template
- How to add array [closed]
- WordPress wraps span tags into p tags
- Get users with different roles and call function on each of them (user_meta)
- Adding tables to the WordPress Editor
- How can I show different content for different user-levels?
- Custom user role still showing up after deletion, ideas?
- Editor cannot access Theme Options
- How to load a css file depending on the current role
- Allow user select role in wordpress default registration without plugin
- Remove check boxes and its label from screen option for custom role
- Add Change role button for list of user in an event
- How to show only specific category post by user role without plugin and restrict all other cats
- Change user role based on total number of items ordered
- Remove all video attachment, both files and post/postmeta from database?
- delete_user_meta for user in spesific group
- Change the second role depending on the first
- Restrict certain roles registrations by domain
- Multisite Admin Roles
- Add functionality to post editor
- add_role menu pages are not visible
- Remove heading tags on line break
- Limit length of headline in Editor
- Welcome Mails based on user role
- When the WP_EDITOR button is pressed, the user is prompted to select a photo from their device
- Get all users from role and add to dropdown (select) – wordpress, javascript
- Would it be possible to disable embeds for specific user roles? If so, how?
- How to make my logged-in user-role shortcode displaying name instead of slug?
- How to check if a user exists by a given id
- How to use the do_action () with parameter
- TinyMCE custom styles remove class when switching styles
- Add admin bar link to edit author
- Extending the site search to include a single custom field
- Notify users whenever a new post is published based on their preference
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- syntax for remove_filter in parent theme with class
- Remove Header and Footer in iframe
- How to Acheive the custom woocommerce category template
- Can I remove the Rich Text box editor for a specific post?
- Formatting post content to exclude gallery
- Why do I get undefined function export_wp()?
- How to add CSS style sheet dynamically in wordpress
- How to update BuddyPress xprofile fields programmatically? [closed]
- Redirect if not logged in?
- How to set global variables in template page?
- A snippet after every image
- Programmatically set page template based on page ID
- Setting featured image with function, 1 part not working
- Function to show only first instance of shortcode
- How can I add an image field to BuddyPress Extended Profile Fields? [closed]
- wp_remote_post with ssl:// protocol
- Best way to programatically add “rel” attributes to page and post images
- Comments to only be seen by their author
- Remove function or filter
- options.php problem – data not saved
- Filtering posts by category name based on page’s slug
- adding custom classes for tables
- Load parent theme files before child theme functions.php
- CSS for menu item added via functions.php
- Default Gallery Edit/Template Editable?
- Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘greenday_head’ not found or invalid function name
- Override a theme function in a child theme?
- changing behaviour of get_search_form
- Make parent page only link to first subpage
- Include default functions and methods
- How to validate this deprecated function
- How can I modify all existing tags while keeping the urls themselves?
- Scripts not appending to element in AJAX call – why?
- Trigger a custom function when option are saved in admin area
- Please Explain the Importing Process of Multiple Stylesheets for Child Themes
- Functions.php – Cannot Modify Header Information SOLVED [closed]
- How would I add “edit profile” and “blog post” functions to front-end?