[-] How to read a site’s debug information written in a plain text reply

If a client adds their site debug information in the standard forum reply field instead of the debug info field, it’s difficult to read. I’ve seen other supporters reply something like “I wasn’t able to read your debug information, can you resubmit it?” I would like to avoid that. The debug information is a JSON object…there’s nothing proprietary or special about it. Instead of waiting for the client to resubmit it correctly, reformat the data yourself and read everything that would normally be available in the debug information panel.

If you’re not familiar with the JSON format, you can use any JSON editor tool to convert the jumbled text into a more organized display. An online JSON editor tool like jsoneditoronline.org would be perfect. Copy the debug text from the forum reply, then paste it in the left side of the screen. Click the right arrow button between the left and right panels, and the parsed information will be formatted into a data tree on the right side. Use the toggles to expand and contract each key or array item.

Pro tip – with the browser developer tools active, you don’t need another tool. The browser console can interpret JSON and format it for you, right there in the forum.

  1. Copy the debug information text from the forum reply.
  2. Open the browser JavaScript console.
  3. Type debug = then paste the debug text by typing Command + v or CTRL + v
  4. Press Return and the console will return a formatted debug object in the next line.
  5. Click the toggle arrow icon to twirl open the object inspector:
> {core: {…}, plugins: {…}, theme: {…}, extra-debug: {…}}

You have a nicely formatted debug information object right there in the browser console. All the information you would normally see – WordPress, the Server, PHP information, plugins and themes – is available here. It’s faster than waiting for the client to respond, and you don’t even have to leave the forum page or open a new tab to use some external tool.

Remove Content Template and Template Layout metabox from CPT

Problem:
Remove ‘Content Template’ and ‘Template Layout’ widgets/metabox for certain CPT in admin screen (WP post edit screen).

Solution:
Please add this code in your theme’s or child theme’s functions.php file:


add_action( 'admin_head', 'wpv_custom_admin_head', 20);
function wpv_custom_admin_head() {
remove_meta_box( 'wpddl_template', 'book', 'side' ); // replace book with your CPT slug
remove_meta_box( 'views_template', 'book', 'side' ); // replace book with your CPT slug
}

==> Whereas ‘book’ should be replaced with your CPT slug.

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

Nest Menus of CPT’s

This nests some “standalone” WP Menu items into one single Menu. Please be careful as the code snippet is designed for a given Post Type which you need to change of course.
Can be useful to nest els Types Custom Post Type Menu items.

/**
 * Nest some menus of CPT's
 */ 
function register_otgs_custom_submenu_page() {
    add_submenu_page( 'edit.php?post_type=training', __( 'Training Session', 'training' ), __( 'Training Sessions', 'training' ), 'edit_posts', 'edit.php?post_type=training-session' );
	add_submenu_page( 'edit.php?post_type=training', __( 'Add New Tr. Session', 'training' ), __( 'Add New Tr. Session', 'training' ), 'edit_posts', 'post-new.php?post_type=training-session' );
	add_submenu_page( 'edit.php?post_type=training', __( 'Exam', 'training' ), __( 'Exams', 'training' ), 'edit_posts', 'edit.php?post_type=exam' );
	add_submenu_page( 'edit.php?post_type=training', __( 'Add New Exam', 'training' ), __( 'Add New Exam', 'training' ), 'edit_posts', 'post-new.php?post_type=exam' );
}
add_action('admin_menu', 'register_otgs_custom_submenu_page');

Assign ‘n’ posts to 1 term in one shoot

Assign all posts from a CPT to one term at once.

function wpv_assign_all_posts( $atts ){
$a = shortcode_atts( array(
        'post_type' => '',
        'taxonomy' => '',
        'term' => '',
    ), $atts );

$args['post_type'] = $a['post_type'];

    query_posts( $args );

while ( have_posts() ) : the_post();
   wp_set_post_terms( get_the_ID(), $a['term'], $a['taxonomy']);
endwhile;

wp_reset_query();
}
add_shortcode( 'wpv-assign-posts', 'wpv_assign_all_posts' );

It should be called like this: [wpv-assign-posts post_type='employee' taxonomy="gender" term = "Male"]

Delete child posts as soon as its parent is deleted

Deletes all Child Posts as soon a Parent Post is deleted. Always make a backup first, mainly when you are running DELETE queries.

add_action( 'delete_post', 'wpv_delete_child_posts', 10 );

function wpv_delete_child_posts( $pid ) {
    global $wpdb;

    $ids = $wpdb->get_results( "SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wpcf_belongs_company_id' AND meta_value = '".$pid."'" );
 	
    if(isset($ids)){
   foreach ($ids as $key) {
   	wp_delete_post($key->post_id, true);
   }
}

    return true;
}

render [types] ShortCode on back-end

Render Types ShortCodes (without executing them) in the WP Backend

if ( is_admin() ) {
    if ( ! function_exists( 'get_plugins' ) ) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    $plugins = get_plugins();
    foreach( $plugins as $path => $plugin ) {
        if ( 'http://wordpress.org/extend/plugins/types/' != $plugin['PluginURI'] ) {
            continue;
        }
        if ( is_plugin_active($path)) {
            include_once( ABSPATH.'wp-content/plugins/'.plugin_dir_path($path).'embedded/frontend.php');
        }
    }
}