Removing Portfolio CPT renders WP_LIST_TABLE useless with Debug on

I am using the code from this link to remove the Portfolio CPT:
https://theme.co/apex/forum/t/completely-disable-portfolio-cpt/29371

Here is the code:

function delete_post_type() {
	unregister_post_type( 'x-portfolio' );
	unregister_taxonomy( 'portfolio-tag' );
	unregister_taxonomy( 'portfolio-category' );
}
add_action('init','delete_post_type', 9999);

This works, but when I have DEBUG on while developing It renders the WP_LIST_TABLES pretty much unusable for POSTS, PAGES, & CPTs.

Here are a couple screen grabs of the tables:

I get that it is just a notice so its not a big deal, but I can’t work in these sections like this. Do you have any thoughts on how to fix this while in development with debug on?

Hello @designerken,

Thanks for writing in!

The code that worked for you unregisters the portfolio post type. I have tested it in my local testing server while the debug is on. I wasn’t able to replicate the issue on my end. I did not get the same PHP notices as what you are having. Do you have any other contents in your child theme’s functions.php file? You may have a piece of code that is causing it. I would love to check your child theme and look for it. If you can give me a WP access that would be great. You can insert your WP credentials in a secure note. To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Best Regards.

Hi @RueNel

Correct I am trying to remove the portfolio post type as my sites don’t either need it or I can create my own, and the code works great for doing that.

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to Pro in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
//   01. Enqueue Parent Stylesheet
//   02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );



// Additional Functions
// =============================================================================

function delete_post_type() {
	unregister_post_type( 'x-portfolio' );
	unregister_taxonomy( 'portfolio-tag' );
	unregister_taxonomy( 'portfolio-category' );
}
add_action('init','delete_post_type', 9999);

There is nothing else in my child theme’s function file. Also this is in my local environment so unfortunately there is nothing that I can give you access to check out.

I am using:

MAMP PRO v 5.3
PHP 7.2.14
WP 5.2.2
X/PRO 2.5.5
Mac OS 10.13.6

I have tried using various versions of PHP and they all give the notice and ruin the list tables with DEBUG on.

Hi @designerken,

They are notices and not warnings so you could ignore them (most of them). Plus, you have removed a post type in which the codes are dependent so it’s only normal to get notices for unavailable variable or parameters. That only disable the post type but not the codes, hence, if you really wish to remove the entire feature then you don’t have to add that code, but you must remove the entire code from the theme’s core which we can’t recommend.

Notices may appear or may not appear depending on your PHP error reporting setting, if you wish to disable the notices since it can’t be ignored then please check this https://aristath.github.io/blog/wp-hide-php-errors

Thanks!

Hi @Rad

I agree with just ignoring them, as stated in my original post I mention that they are notices and not a big deal. But that isn’t the issue. The issue is that it renders the tables unreadable.

Looking at the code that is called I found it easier to add the function back to my functions.php file and comment out portions that was returning the error. (see code below)

Your team should really move out the portfolio feature and add it back in as a plug-in, but that is a different topic all together: Feature Request: Remove Portfolio Functionality .

// Entry Class
// =============================================================================

if ( ! function_exists( 'x_portfolio_entry_classes' ) ) :
  function x_portfolio_entry_classes( $classes ) {

    // GLOBAL $post;
    // $terms = wp_get_object_terms( $post->ID, 'portfolio-category' );
   // foreach ( $terms as $term ) {
      // $classes[] = 'x-portfolio-' . md5( $term->slug );
    // }
    return $classes;

  }
  add_filter( 'post_class', 'x_portfolio_entry_classes' );
endif;

Hi @designerken,

Yes, it’s added as a feature request but unfortunately, I couldn’t implement such feature as a workaround and noted.

But for now, please remove the codes that you think is triggering the notices, but it may break it more. Or disable the notices as previously recommended so it wouldn’t hinder viewing the tables.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.