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?
- Custom User Role not working
- Missing feature image link function
- What’s the difference between home_url() and site_url()
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- get_template_directory_uri pointing to parent theme not child theme
- How to customize the_archive_title()?
- remove empty paragraphs from the_content?
- What is the “with_front” rewrite key?
- Why use if function_exists?
- How to override parent functions in child themes?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- How long does a deprecated function live in core?
- How to add a data attribute to a WordPress menu item
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- remove_action on after_setup_theme not working from child theme
- plugins_url vs plugin_dir_url
- Remove type attribute from script and style tags added by WordPress
- How to run a function every 5 minutes?
- Best way of passing PHP variable between partials?
- Upload Multiple Files With media_handle_upload
- How to display custom field in woocommerce orders in admin panel?
- Adding fields to the “Add New User” screen in the dashboard
- Issues with title-tag and document_title_parts
- How do I get the current edit page ID in the admin?
- How to check if a user exists by a given id
- Why isn’t is_page working when I put it in the functions.php file?
- Add tags to the section via functions.php
- Add image size if page template
- How to create a custom order status in woocommerce!
- Remove Actions/Filters added via Anonymous Functions
- Adding a second email address to a completed order in WooCommerce [closed]
- How to load parent_theme functions.php before child_theme?
- How to load scripts/styles specific for a page
- Programatically add options to “add new” custom field dropdown
- Is there any global functions.php file which works for any theme?
- Excluding iPad from wp_is_mobile
- When should you, and when should you not, use wp_list_pluck()?
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Difference between the_permalink() and get_permalink() function
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?