Skip Navigation

[Résolu] Disable the Add Media button for WYSIWYG user fields.

This support ticket is created Il y a 6 années et 7 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Auteur
Publications
#769111

Hello is it possible to disable the Add Media button for User Edit forms that contain Custom user fields of the type WYSIWYG?

For post forms, there is a checkbox to turn on/of this button, but not for user forms.

Regards,
Herre

#772183

Hi, you can add this custom code to your theme's functions.php file to deactivate the "Add Media" button on any page of your site:

function remove_toolset_buttons(){

    // $post not available with init hook
    $postID = url_to_postid( $_SERVER['REQUEST_URI'] , '_wpg_def_keyword', true );
    $target_pages = array( 123, 456 ); // Edit for pages with CRED forms

    if ( in_array( $postID, $target_pages ) ) {
        // remove the Fields and Views button
        add_filter( 'toolset_editor_add_media_button', function() {
          $roles = array();
          return $roles;
        } );
    }
}
add_action( 'init', 'remove_toolset_buttons' );

Replace 123, 456 with a comma-separated list of post IDs that contain the CRED form or forms.

#775522

That piece of code didn't work for the add media button. Also not when adding the user role in the roles array. I can see you've copied and pasted the code from an example to remove the types & Views button. I was already using that code for that purpose.

But the ... add_filter( 'toolset_editor_add_media_button'... has no influence whatsoever.

I've also tried: add_filter( 'toolset_editor_add_media_button', '__return_false' ); ... also no luck...

On WPMUDEV i've found an example: remove_action( 'media_buttons', 'media_buttons' ); ... that seems to do the trick....

Any pro's / con's for using that option?

An other solution for me would be... converting the WYSIWYG editor into an textarea input. Is there a script to use a textarea?

The field i'm having troubles with is the user bio field. In the WordPress Backend this is a textarea field (standard wp user field), but CRED seems to render it as an WYSIWYG field.

#779141

Sorry for the misinformation, I thought I had tested that yesterday but I must have overlooked something. As far as the remove_action, it's a nuclear approach that would affect all media buttons on a page, so you should be aware it may have a larger than intended scope.

I don't have a script that will convert the native WP bio (description) field to a standard textarea, but I can help suppress the button in the WYSIWYG editor. I tried a different approach today and it seems to be working in my local tests. Instead of using a hook, you can add CSS just for this form:

#wp-cred_user_form_1234_1_description-media-buttons .button.insert-media {
 display:none; 
}

Add this CSS to the CRED form editor CSS panel and change 1234 to match the numeric ID of this form.

#803660

Thx Cristian,
This solution is okay for now... although it would be great to have it as an feature to disable the media button for user WYSIWYG fields.

The hidden rule can easily be reverted by using the inspector i'm afraid. So inventive people can still upload 😉

On of the other issues is, when using the Add Media button, all images can be selected instead of only the users images. Maybe that is a setting in access?

Regards,
Herre

#804647

There's no setting in Access that limits the ability to view Media posts by author, but WordPress offers a filter that may be useful:

add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' );

function wpb_show_current_user_attachments( $query ) {
    $user_id = get_current_user_id();
    if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
') ) {
        $query['author'] = $user_id;
    }
    return $query;
}

You may adjust the conditional as needed to allow certain Users Access all Media Library items.