Skip Navigation

[Resolved] Hide button

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 27 replies, has 3 voices.

Last updated by Anonymous 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#569981

Anonymous
download (2).jpg

Hi, I have some questions and I beg your pardon if I will use not proper words, but I don't know the exact names.

1) I would like to hide the button "Campi e viste", except from admin users. So, I want to show it to them but hide it to all other roles (because they don't need it and there is a risk they can make a mess).

2) I want to add new custom buttons instead of that one, linking to external URLs.

3) I want to order the rightern boxes in an order that is visibile to all users by default, a different order from the default wordpress one

#570115
custombutton.jpg

Hey Simone,
Let me help you quickly regarding your questions:

1) I would like to hide the button "Campi e viste", except from admin users. So, I want to show it to them but hide it to all other roles (because they don't need it and there is a risk they can make a mess).

Answer: In Toolset View we have a filter called wpv_filter_public_wpv_add_fields_and_views_button that will control whether the Toolset fields and editor button will be shown. To allow this visible only to administrators while hidden to other user roles, you should add this sample code to your theme functions.php:

add_filter( 'wpv_filter_public_wpv_add_fields_and_views_button', 'wpv_only_show_button_to_admin', 10, 1 );
function wpv_only_show_button_to_admin( $show = true ) {
    if ( !current_user_can( 'manage_options' ) ) {
        //Not administrator
        $show = false;
    }    
    return $show;  
}

I tested the above code and it works.

2) I want to add new custom buttons instead of that one, linking to external URLs.

Answer:

This is not controlled by Toolset. In WordPress core there is a hook already called media_buttons that you can use to add your own custom button. https://developer.wordpress.org/reference/hooks/media_buttons/

So if you want to add custom button to other roles(except administrator) which links to external sites, you can do something like ( add this code to your functions.php):

add_action( 'media_buttons', 'add_media_button' );
function add_media_button() {
    $html = '';
    if ( !current_user_can( 'manage_options' ) ) {
        $html = '<a class="button" href="<em><u>hidden link</u></em>">Go to Google</a>';   
    }
    echo $html;
}

It will add a custom button link visible only to other roles except administrators. See attached screen-shot. The above sample code should work for you as its tested.

3.) I want to order the rightern boxes in an order that is visibile to all users by default, a different order from the default wordpress one

Answer:

This is not a Toolset feature. WordPress and other third party plugins already offer this functionality. To get what you need:

  • Install and activate this plugin:
    https://wordpress.org/plugins/global-meta-box-order/
  • Open any post as administrator.
  • Drag and order the meta box with your computer mouse.
  • And then save the post.
  • The order should be saved and reflected to other user roles not only admin since its saved globally.

I also tested this one and it works.

Please let me know how it goes. Thank you.

#570127

Anonymous

First of all... you're an angel!!!
Many many thanks ????

1) it works as I expected

2) I want to show this custom buttom to everyone, not excluding admin
I edited your code, it's correct?

add_action( 'media_buttons', 'add_media_button' );
function add_media_button() {
    $html = '<a class="button" href="<em><u>hidden link</u></em>" target="_blank">Archivio fotografico di Gruppo</a>';   
    echo $html;
}

Is it also possible to add an icon (as there is one for the media library or for you toolset button for view)?

3) I'm not a coder, so I'm learning WordPress on my own, as an hobby, since I use it to help a non profit organization.
I learned that it's not good to have too many plugins (and I already have tons installed :/) so installing this one, slow down more the site?
It's not a fundamental feature, so if your advice is not to installing it, I won't.
Tell me the truth.
Or if it is possible to achieve this without a plugin.
Or if after removing the plugin, the savings will remain.
Give me your sincere advice ????

#570216

Hi Simone,
Great to hear that! Regarding your remaining questions:

I want to show this custom buttom to everyone, not excluding admin
I edited your code, it's correct?

Answer:

Yes, this is correct:

add_action( 'media_buttons', 'add_media_button' );
function add_media_button() {
    $html = '<a class="button" href="<em><u>hidden link</u></em>" target="_blank">Archivio fotografico di Gruppo</a>';
    echo $html;
}

I'm not a coder, so I'm learning WordPress on my own, as an hobby, since I use it to help a non profit organization.
I learned that it's not good to have too many plugins (and I already have tons installed :/) so installing this one, slow down more the site?

Answer:

The number of plugins does not matter much in terms of performance. It depends on the plug-ins you are using. Some plug-ins are resource intensive , some are not. Good news is, Toolset is optimized for performance so it should not affect performance.

I would suggest though to review other third party plug-ins which you don't really need and deactivate them. There are lot of things you can do to improve speed after you have reviewed all your plugins. Here are as follows:

->Get a powerful hosting -depends on website traffic. If the site traffic is high, the load on the server is high also. This slows down the site. You might be better off with a VPS or dedicated hosting.

->Use a caching plugin like W3TC. This will reduce the number of dynamic PHP calls to the server and speed up your site. With this you can utilize several techniques like page cache, minify ,etc. which will help a lot in terms of performance.
->Use CDN especially if the site audience is worldwide.

There are several nice guides regarding improving WordPress site performance:
https://codex.wordpress.org/WordPress_Optimization
hidden link

Please let me know if all is OK then you can mark this as resolved 🙂 Thanks.

#570218

Regarding your other comments here:

It's not a fundamental feature, so if your advice is not to installing it, I won't.
Tell me the truth.

Answer:

If Toolset is not used in that site , then you should deactivate it. Because if you activate plug-ins which don't really need, it will consume resources and slows down your site.

Or if it is possible to achieve this without a plugin.Or if after removing the plugin, the savings will remain.

Answer:

It depends. Toolset is supposed to make things easy for developers to create sites. So if you can find ways to do this without Toolset with a simple line of code. It's fine. You can achieve without using this plugin.

Since you are a non-coder, you might be better off with Toolset to simplify site developments. And we are here to help.

If the main issue in this ticket is resolved and you still need help with other things. Please mark this ticket as resolved and create another topic. Thank you!

#570267

Anonymous

Hi, sorry but there was a misunderstanding 🙁


3) I'm not a coder, so I'm learning WordPress on my own, as an hobby, since I use it to help a non profit organization.
I learned that it's not good to have too many plugins (and I already have tons installed :/) so installing this one, slow down more the site?
It's not a fundamental feature, so if your advice is not to installing it, I won't.
Tell me the truth.
Or if it is possible to achieve this without a plugin.
Or if after removing the plugin, the savings will remain.
Give me your sincere advice ????

This answer of mine was referred to your message in which you talked about Global Meta Box Order plugin
Install and activate this plugin:

https://wordpress.org/plugins/global-meta-box-order/
Open any post as administrator.
Drag and order the meta box with your computer mouse.
And then save the post.
The order should be saved and reflected to other user roles not only admin since its saved globally.
I also tested this one and it works.

Could you please remake your answer now? 🙂

#570275

Hi Simone,
OK thanks for clarifying. Yes the Global meta box order plugin is a lightweight plugin and runs only on WordPress backend/admin. You should not have any performance issues with it. So its ok. ????

#570287

Anonymous

Hi, I have a problem.

I installed the plugin and after clicking on activate, it showed me this error

Fatal error: Call to undefined function GlobalMetaBoxOrder\get_current_screen() in /web/htdocs/www.scoutsandamiano.it/home/wp-content/plugins/global-meta-box-order/index.php on line 178

Now I cannot access the wp-admin backend anymore. I had to remove the plugin via ftp

#570308

Hi Simone,
I didn't get that error, probably some files are missing while you are installing it. I suggest to delete it and re-install. Please follow these steps: https://codex.wordpress.org/Managing_Plugins#Installing_Plugins
Once its cleanly installed, it should be working. If its still does not work, I'm enabling private reply so you can enter your site login. I'll check. Thank you.

#570321

Thanks SImone! Unfortunately that is a third party plugin issue. There is already a bug report here with a workaround: https://wordpress.org/support/topic/fatal-error-call-to-undefined-function-globalmetaboxorderget_current_screen/

I applied the workaround and then it works. It's activated now. Can you do some test? If it's still not working for you, please create a ticket here: https://wordpress.org/support/plugin/global-meta-box-order/ so the plugin author will know.

We could not think of any plugin similar like this so its better to get in touch with the plugin author if the issue persist. We could not provide support to this type of plugin according to our support policy: https://toolset.com/toolset-support-policy/ (as this forum is only for Toolset)

I hope all is well now. Cheers. 🙂

#570322

Anonymous

There is something still not working.
I logged in as wp_7925865 / aQays9qFJU, that is the first admin user, changed something, saved, and even the changes for him after reloading disappeared.

Anyway, the most important thing I would do, it to place the featured media meta box not on the rightern side, but central, over the title meta box.
I found this solution: https://wordpress.stackexchange.com/questions/33063/how-to-change-default-position-of-wp-meta-boxes
but it put the featured media meta box central, but at the bottom.
How can I do this?

#570335

Anonymous

Thanks

#570434

Anonymous
image.jpeg

Hi, I resolved the problem with this code

add_action('do_meta_boxes', 'wpse33063_move_meta_box');
function wpse33063_move_meta_box(){
    remove_meta_box( 'postimagediv', 'post', 'side' );
    add_meta_box('postimagediv', __('Immagine di copertina'), 'post_thumbnail_meta_box', 'post', 'top', 'high');
}


add_action('edit_form_after_title', function() {
  global $post, $wp_meta_boxes;
  do_meta_boxes(get_current_screen(), 'top', $post);
  unset($wp_meta_boxes[get_post_type($post)]['top']);
});

It worked since some time ago, but now no more 🙁

#570442

Anonymous

And also this is not working anymore

add_action('after_setup_theme', 'remove_post_format', 15);
function remove_post_format() {
  if ( !current_user_can( 'manage_options' ) ) {
        //Not administrator
        remove_theme_support('post-formats');
    } 
  
}
#570712

Dear Simone,

Emerson is not available currently.

There are lots of questions in this thread, I am bit lost, can we handle them one by one?
Q1) changed something, saved, and even the changes for him after reloading disappeared
https://toolset.com/forums/topic/hide-button/#post-570322
This is abnormal, in case there is other compatibility problem in your website, I suggest you try these:
1) Deactivate other plugins (except Types plugin) and switch to wordpress default theme 2017, and test again

2) Enable PHP debug mode, copy and paste the debug logs here, we need to know if there is any PHP error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/
PHP Debugging
To enable PHP debugging in WordPress, edit your wp-config.php file and add the following:
PHP Debugging in WP
ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

3) If the problem still persists, please provide a database dump file(ZIP file) of your website in below "Private message box", also describe detail steps for how and where I can see the problem, I need to duplicate same problem and debug it in my localhos. thanks

For other new questions, please create new thread for the new questions, that will help other users to find the answers.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.