Skip Navigation

[Resuelto] Promp to create a new Layout when Updating my CPT

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How to restrict and display Layout template metabox for admin users only

Solution:
You need to add custom code to your current theme's functions.php file in order to show/hide Layouts template meta box to specific users.

You can use wordpress standard method: remove_meta_box()

For example:

    remove_meta_box( 'wpddl_template', array("artistas"), 'side' ); 

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/promp-to-create-a-new-layout-when-updating-my-cpt/#post-620846

Relevant Documentation:
https://codex.wordpress.org/Function_Reference/remove_meta_box

Este es el foro de soporte técnico para Toolset: un paquete de plugines para el desarrollo de sitios WordPress sin escribir PHP.

Cualquier persona puede leerlo, pero solo los clientes de Toolset pueden publicar en este foro. El soporte de Toolset atiende 6 días a la semana, 19 horas por día.

This topic contains 6 respuestas, has 2 mensajes.

Last updated by Cesar hace 3 años, 7 meses.

Assigned support staff: Minesh.

Autor
Mensajes
#620675

Hi,

Whenever I update my CPT on my site I lost the relationship of the single CPT with my Layout template.

So when I update any of my Custom Post the post disappear because there is no Layout assigned to it. I have to go to the Layout of my CPT> Assign the missing post in order to recover it.

This is an every single time situation so I hope you can check it on the site. I'm sending full access on private

======================
To REPLICATE the issue
======================

1 Go to
*****/wp-admin/post.php?post=453&action=edit
(optional)Check layout is correct

2 Update the post
*****/wp-admin/post.php?post=453&action=edit
3 Check the Layout is lost

3 Go to Layout config
*****/wp-admin/admin.php?page=dd_layouts
Check the CPT is missing and assign the layout to the missed CPT

Thanks

#620803

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - it looks like the issue is from the theme you are using.

I activated the "Toolset Starter" theme to and I can see the correct layout metabox is displayed and correct layout is also assigned.

Please check following screenshot - when you deactivate your theme you will see the same metaboxes on right sidebar while editing your post:
=> hidden link

Could you please confirm that it works with Toolset starter theme as expected.

#620833

Thanks so much for you help,

I removed the following code from function.php on my Child Theme from the Toolset Starter Theme.

The code is based on the code you provide on my last ticket. It was not working so I had to tune it to make it work in my case

Would you mind taking a look? you may found what is causing this estrange behavior
https://toolset.com/es/forums/topic/hide-template-layout-selection-for-non-admin/

If you prefer I can follow this last ticket instead

Thanks again


/***********************************************
 * Remove unecesary tools for non admins
 ***********************************************/
// Remove toolset button
function func_remove_unwanted_toolset_buttons(){
  
    // only remove buttons on back end for non-administrators
    if ( is_admin() && !current_user_can( 'manage_options' ) ) {
  
        // remove the Fields and Views button
        add_filter( 'toolset_editor_add_form_buttons', '__return_false' );
     
        // remove the CRED button
        add_filter( 'toolset_cred_button_before_print', '__return_false' );   
     
        // remove the Access button for all roles 
        add_filter( 'toolset_editor_add_access_button', function(){
  
            global $wp_roles;
            $all_roles = array_keys($wp_roles->roles);
   
            return $all_roles;
        } );
    }
}
add_action( 'init', 'func_remove_unwanted_toolset_buttons' );

// Hide Content Layout editor
add_action( 'admin_init', 'my_admin_init' );
function my_admin_init() {
if(is_admin() && !current_user_can( 'manage_options' )) {
    
      wp_enqueue_style( 'rem-clayour-btn', get_stylesheet_directory_uri() . 'https://cdn.toolset.com/rem-clayout-btn.css' );
	}
}

// Remove Template Layout Box
add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
    remove_meta_box( 'wpddl_template', array("artistas"), 'side' ); // replace with your CPT slug
 
}
#620838

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - it looks like this is the code that hides the Layouts metabox in right sidebar.

// Remove Template Layout Box
add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
    remove_meta_box( 'wpddl_template', array("artistas"), 'side' ); // replace with your CPT slug
  
}

Could you please comment out above code and check if you can see the metabox.

#620844

Yes it does,
I didn't edit this code, is exactly the one you give me with my custom slug
The funny thing is that it was working fine 2 weeks ago on my local machine
I double checked the slug and is fine
Is there anything wrong with the snippet?

#620846

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as I understand you want to display the metabox for admin users - correct? If yes:

Could you please try the following code - or you can change the if condition in following code to display the metabox for only "ADMIN" users.

// Remove Template Layout Box
add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
if(is_admin() && !current_user_can( 'manage_options' )) {
    remove_meta_box( 'wpddl_template', array("artistas"), 'side' ); // replace with your CPT slug
   }
}
#620849

This just solved it for admin and is fine for Author

Could you please point me to the documentation were I can found more of this:

remove_meta_box( 'wpddl_template', array("artistas"), 'side' );

I would like to hide everything from toolset for my author,

I can follow the other ticket
Thanks