Disable WYSISYG editor in Wordpress - wordpress

I'm trying to write a plugin to disable the WordPress WSYIWYG editor for all users.
I wrote some code to remove the tinymce directory, but this breaks the editor- you can't write anything or use the HTML tab.
$dirName = ABSPATH . '/wp-includes/js/tinymce';
if (is_dir($dirName)) {
rename("$dirName", $dirName."_DISABLED");
}
I'm trying to emulate what happens when you select the "Disable the visual editor when writing" checkbox in the user settings tab, but for all users all the time.

If you want to go with a very frontal solution, you could emulate that by updating a few rows directly in the database, like that :
UPDATE wp_usermeta SET meta_value = 'false' WHERE meta_key = 'rich_editing';
Or else, if you want to use Wordpress functions, you could use update_user_meta. Here is the doc: http://codex.wordpress.org/Function_Reference/update_user_meta

Jean pointed the way, but wanted to share the full working code:
In my plugin:
// Only do this if we're in admin section:
if(is_admin()) {
// Add the action on the init hook, when user stuff is already initialized:
add_action('init', 'disable_rich_editing');
}
function disable_rich_editing(){
$current_user = wp_get_current_user();
$isRichEditing = $current_user->get('rich_editing');
if ($isRichEditing) {
update_user_meta( $current_user->ID, 'rich_editing', 'false' );
}
}
What it does:
Normally the only way to disable WYSIWYG is to select the "Disable the visual editor when writing" on each user's settings page. This will force that option to be checked for all users all the time, even if they try to uncheck it.

Related

possible woocommce bug keep showing "total_sales" in metabox "custom field" add/edit product page?

As shown in the edit/add product page, this item "total_sales" always show up in the default metabox "custom field".
It's not doing any harm yet but it's annoying.
However, someone might edit the total sales number by accident and would cause problems.
I am writing a child theme from storeFront.
Is this a bug in woocommerce or did I accidentally changed something somewhere that causes this?
This is by default. If you think this is a bug then you can always open a thread on https://github.com/woocommerce/woocommerce/issues
EDIT
Custom fields or post meta entries can be hidden from the by default in Wordpress available »Custom Fields«-Metabox by prefixing them with a underscore - _ - as noted here.
If you want to hide the field you can use this piece of code that i wrote for you
function filter_is_protected_meta( $protected, $meta_key, $meta_type ) {
if ( $meta_key == 'total_sales' ) {
$protected = true;
}
return $protected;
}
add_filter( 'is_protected_meta', 'filter_is_protected_meta', 10, 3 );

how to use a wp plugin as a theme part not as a plugin?

I am developing a word press theme and I have a free plugin which helps me to add new features to my theme. I want to use this plugin in this theme but I don't want to use it as a plugin and have to activate in plugins section. I want to use it as a theme part and disable activating or deactivating it. It will be activate automatically when theme set up.
If your theme uploaded somewhere then refer -> https://wordimpress.com/how-to-easily-require-plugins-for-your-wordpress-themes/
Or
add_action( 'admin_notices', 'my_theme_dependencies' );
function my_theme_dependencies() {
if( ! function_exists('plugin_function') )
echo '<div class="error"><p>' . __( 'Warning: The theme needs Plugin X to function', 'my-theme' ) . '</p></div>';
}
OR
if your theme is in local setup then you can use must-up plugin, for that refer -> https://codex.wordpress.org/Must_Use_Plugins
So if I understand correctly you want your plugin to be in Wordpress but you don't want it to be shown to anyone else or be able to deactivate it?
Try using this plugin, which will hide your plugin('s) from everyone - WP Hide Plugins.
Or add this to your functions.php file:
function hide_plugin_trickspanda() {
global $wp_list_table;
$hidearr = array('plugin-directory/plugin-file.php');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr)) {
unset($wp_list_table->items[$key]);
}
}
}
add_action('pre_current_active_plugins', 'hide_plugin_trickspanda');
Info to go with this code: rename the plugin name in the first line, also change the "plugin-directory/plugin-file.php" to the plugin file of your plugin and in the last line change the plugin name too.

Wordpress admin - add item next to "Activate Edit Delete" list

In the plugins section of the admin screen, each plugin generally has a list of a few things you can do, usually "activate, edit, delete". How can I add an item to this list?
In your plugin file just add this code.
// Add settings link on plugin page
function your_plugin_settings_link($links) {
$settings_link = 'Settings';
array_unshift($links, $settings_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'your_plugin_settings_link' );
EDIT: OK so i guess you are administrating the sites, and you want your users to report if something goes wrong with any plugin. Here are some of the options.
Use Jquery to add links.
Use the above function and add a loop around the add_filter, and then loop through `$all_plugins = get_plugins();

Modify User Roles in WordPress?

I have been working on a client's WordPress Website and last day my client want to hide navigation menu and pages from author/contributor categories.
I have searched and tried some of the plugin but didn't get the exact thing. Please let me know what should i use to hide some pages from user and from navigation.
Only Admin can see all the pages and other members should see only 1 section that is allowed to visible for them.
Thank You
use this plugin to manage All roll:
http://wordpress.org/plugins/user-role-editor/
Here is the Complete function for removing each Menu and submenu from wp-admin for another user:
function remove_menus() {
global $menu, $submenu;
$restricted = array(__('Dashboard'), __('Profile'), __('Users'), __('Tools'), __('Comments'), __('Settings'), __('Plugins')); //Here you can also define the name like Pages
end($menu);
while (prev($menu)) {
$value = explode(' ', $menu[key($menu)][0]);
if (in_array($value[0] != NULL ? $value[0] : "", $restricted)) {
unset($menu[key($menu)]);
}
}
unset($menu[5]); // this is just for example
unset($submenu['edit.php'][16]); // this is just for example
}
Now You have to put a conditon for other user i.e:
$thisusername = $current_user->user_login; // this is to get the current user login
if (($thisusername == "user123")) {
add_action('admin_menu', 'remove_menus');
}
Note: You can find many plugins but all of them are not in depth like this code.Well you can try this plugin to manage your user's roles.Capability Manager Plugin

Wordpress, filter pages in Admin edit screen

Is it possible to 'filter' which pages are shown in the 'edit' screen for pages ( http://cl.ly/6nLC ) in Wordpress? I have looked in the action / hook section of Wordpress for plugin developers but I could not find any.
What I am trying to accomplish is is that certain users can edit certain pages (and child pages) and other persons cannot edit those pages but might be able to edit other pages.
I have allready written a plugin which makes it possible to put different users in differtent groups, which now just needs to have different rights, which user is member of which group is stored in the user_meta table.
However if there is 'any' filter hook / method for this, can someone point this out, I think I will be able to go further from there.
Kind regards.
You can use a posts_where filter to add a condition to the SQL query to filter out some pages. A load-{filename} action can be used to ensure the filter is only applied when managing pages.
add_action('load-edit.php', 'my_load_edit_php_action');
function my_load_edit_php_action() {
if ($_GET['post_type'] !== 'page') return;
add_filter('posts_where', 'my_posts_where_filter');
}
function my_posts_where_filter($sql) {
if (current_user_can('your_capability')) {
global $wpdb;
$sql = " AND $wpdb->posts.ID NOT IN (1,2,3)" . $sql;
}
return $sql;
}

Resources