Remove button added by a tinymce plugin - wordpress

I want to hide the link options button shown in tinymce plugin (wpload), the one that shows up when clicking "Link" button..
Is there any call like
tinymce.PluginManager.get('pluginName').removeButton(...) ?
More specifically I want to remove Link Options from wplink plugin tinymce version 4.5.6. I saw this call in the plugin code, wonder how I can remove it from my custom WP plugin (dont want to hack the wplink plugin itself)?
editor.addButton( 'wp_link_advanced', {
tooltip: 'Link options',
icon: 'dashicon dashicons-admin-generic',
onclick: function() {
if ( typeof window.wpLink !== 'undefined' ) {
....

You need to create a WP plugin and use the mce_buttons hook to change the list of toolbar buttons that the editor will load.
It would look something like this:
add_filter('mce_buttons', 'remove_link_button', 2000);
function remove_link_button( $buttons ) {
// Remove the toolbar button for the link plugin
$remove = array('link');
return array_diff( $buttons, $remove );
}
I would note that this would note fully remove the link plugin's functionality - it would just remove that toolbar button. The plugin also has right click functionality on links so if you want all the functionality gone you also need to use the tiny_mce_before_init hook to remove the plugin from the list of plugins to be loaded.
Note: There are lots of examples of how to create a WP plugin so I am not going to repeat them here ... the code above would need to go into a WordPress plugin to function properly in WordPress.

Related

How do I get rid of the comments dropdown in the WordPress dashboard?

The code below removes everything I want except for the comments dropdown.
That pesky little icon just won't go away. Is there another method?
// Remove Admin bar links
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo'); // Remove the Wordpress logo
$wp_admin_bar->remove_menu('about'); // Remove the about Wordpress link
$wp_admin_bar->remove_menu('wporg'); // Remove the Wordpress.org link
$wp_admin_bar->remove_menu('documentation'); // Remove the Wordpress documentation link
$wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link
$wp_admin_bar->remove_menu('feedback'); // Remove the feedback link
$wp_admin_bar->remove_menu('comments'); // Remove the comments link
$wp_admin_bar->remove_menu('new-content'); // Remove the content link
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
You can use:
function remove_toolbar_node(\WP_Admin_Bar $wp_admin_bar) {
$wp_admin_bar->remove_node('comments');
}
add_action('admin_bar_menu', 'remove_toolbar_node', 999);
Note that you can use $wp_admin_bar->get_nodes() to get available nodes.
Figured out I have to add: $wp_admin_bar->remove_menu('notes');
That gets rid of the comments icon.

How to reset all fields when adding to WooCommerce Cart

I'm developing a site with WooCommerce and have used the plugin Product Addons to add extra fields of text to the item being purchased (name, email address, phone number, etc). When someone clicks on "Add to Cart", the site currently adds the product to the cart, refreshes the page, but the previous data remains in the fields. I want to reset all the fields and make them empty after the product has been added.
I tried using this function:
( function($) {
$( document.body ).on( 'added_to_cart', function() {
$('input').val(''); }
);
} ) ( jQuery );
Any suggestions?
If the page literally refreshes itself then it is not at all standard. It was done just to update the mini cart at the top right corner of your menu and products are being added through ajax. In this case you can't empty all fields on some event because the page is being refreshed, what you have to do is write you code under document.ready function, perform $.each function on the common class or input and empty the input fields.
Try this action hook in your plugin or theme functions.php file
add_filter( 'woocommerce_checkout_get_value', 'misha_clear_checkout_fields_vals' );
function misha_clear_checkout_fields_vals($input){
return '';
}

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();

How to add page URL to list of pages in WordPress admin panel?

Currently, by default, the following columns appear in the list of pages in the WordPress admin panel:
Title
Author
Comments
Date
and because I have AIO SEO installed:
SEO Title
SEO Description
SEO Keywords
Is there a way to have WordPress also display the URL to the page (at least the part of the URL that is created when the page itself is created)?
The page url is actually already there by default, it's just hiding. When you hover over a page title, several links appear below the title -- edit, quick edit, trash, view. View is the hyperlink to the page, which you can click to view the page, or right click and copy the link address to use elsewhere.
Otherwise, if you are using a custom/child theme, you could add the following to your functions.php file:
add_filter('manage_page_posts_columns', 'my_custom_column', 10);
add_action('manage_page_posts_custom_column', 'add_my_custom_column', 10, 2);
function my_custom_column($defaults) {
$defaults['url'] = 'URL';
return $defaults;
}
function add_my_custom_column($column_name, $post_id) {
if ($column_name == 'url') {
echo get_permalink( $post_id );
}
}
Note: This just creates a text url to your page.
Also note, you do not want to edit your functions.php file directly if you are using a theme you did not create, as it will be overwritten when you update. If you want to add this to an existing theme, I'd suggest looking into child themes.
This is helpful. I would only improve the output slightly by removing the site url and just showing the page. Takes up less space and less to weed through visually.
if ($column_name == 'url') {
$siteURL=get_site_url($post_id);
$link= get_permalink( $post_id );
echo str_replace($siteURL,"",$link);
}

Disable WYSISYG editor in 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.

Resources