• Resolved kendawes

    (@kendawes)


    I’m getting the following warning in the WP debug.log on my client’s site.

    PHP Warning: Undefined array key “sort” in /home/path/wp-content/plugins/custom-post-type-ui/inc/tools-sections/tools-taxonomies.php on line 172

    The site is currently running PHP 8.0.28. Everything else is all current.

    Any fix in sight?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi,

    Not something that should be taking the site down by any means, so you should be good on that front.

    As a potential quick win, can you edit the taxonomy without actually changing any settings, just edit and save. I’m wondering if that will help remove it from the debug log. Hopefully you don’t have TOO many taxonomies registered where it’d take a long time.

    Hello @tw2113 – love your plugin, been using it for years, thanks for all your efforts to keep it active!

    This issue, however, is affecting my client’s sites’ functionality. The warning message is being output into the PHP code in the “Tools” section.

    It takes the site down when I use the CPTUI export and try to import that into our test or production site, which is a regular and necessary part of development, or when I use the code below this message to auto-export the PHP

    It appears that your code is not parsing the input form properly. I have set the ‘sort’ option to true in the edit form, but after saving, the warning shows up, and the issue still persists when trying to export to PHP code.

    See screenshots at links below:

    Form settings:
    https://drive.google.com/file/d/1rBvCrM0VzsJW1KXY4OlcoZt-rHvkeF4J/view?usp=sharing

    Warning in Output Code:
    https://drive.google.com/file/d/1rCi7nbwszmHxbOW1aXwxCog3ShnzHyle/view?usp=sharing

    Here is a hack that fixes the problem, but then the Form Settings for ‘sort’ (see screenshot above) are still not being saved, nor retrieved:
    https://drive.google.com/file/d/1rFqoF1F5PCOXpIl-SMkz2XhDDqcnVIz0/view?usp=sharing

    Code used to output CPT’s to php file: (just for ref – it happens when manually exporting too)

    <?php
    /**
     * Class and Functions to Sync CPTUI cpt's and tax's to/from a file
     * Version: 1.0.0
     * @package CPTUI_SYNC
     */
    
     // load cpt and taxonomy config.
    define( 'CPTUI_SYNC_PATH', WP_CONTENT_DIR . '/themes/sps-base-theme/cptui' );
    if ( file_exists( CPTUI_SYNC_PATH . '/custom-post-types.php' ) ) {
    	require_once CPTUI_SYNC_PATH . '/custom-post-types.php';
    }
    if ( file_exists( CPTUI_SYNC_PATH . '/custom-taxonomies.php' ) ) {
    	require_once CPTUI_SYNC_PATH . '/custom-taxonomies.php';
    }
    
    
    /**
     * Export custom CPT's on save
     * using the 'custom-post-types-ui' plugin.
     *
     * @return void
     */
    function cptui_sync_export_cpts_json() {
    	if ( function_exists( 'cptui_get_post_type_data' ) ) {
    		$post_type_export_data = cptui_get_post_type_data();
    		$content               = json_encode( $post_type_export_data, JSON_PRETTY_PRINT );
    		$save_path             = CPTUI_SYNC_PATH;
    		try {
    			$result = file_put_contents( $save_path . '/custom-post-types.json', $content );
    		} catch ( Exception $e ) {
    			// do nothing.
    		}
    	}
    }
    add_action( 'cptui_after_update_post_type', 'cptui_sync_export_cpts_json' );
    
    /**
     * Export custom taxonomies on save
     * using the 'custom-post-types-ui' plugin.
     *
     * @return void
     */
    function cptui_sync_export_taxs_json() {
    	if ( function_exists( 'cptui_get_taxonomy_data' ) ) {
    		$taxonomy_export_data = cptui_get_taxonomy_data();
    		$content              = json_encode( $taxonomy_export_data, JSON_PRETTY_PRINT );
    		$save_path            = CPTUI_SYNC_PATH;
    		try {
    			$result = file_put_contents( $save_path . '/custom-taxonomies.json', $content );
    		} catch ( Exception $e ) {
    			// do nothing.
    		}
    	}
    }
    add_action( 'cptui_after_update_taxonomy', 'cptui_sync_export_taxs_json' );
    
    
    /**
     * Export custom CPT's on save
     * using the 'custom-post-types-ui' plugin.
     *
     * @return void
     */
    function cptui_sync_export_cpts_code() {
    	if ( function_exists( 'cptui_get_post_type_code' ) ) {
    		$cptui_post_types = cptui_get_post_type_data();
    		ob_start();
    		cptui_get_post_type_code( $cptui_post_types );
    		// Return the contents of the output buffer.
    		$post_type_export_data = ob_get_contents();
    		// Clean (erase) the output buffer and turn off output buffering.
    		ob_end_clean();
    		$save_path = CPTUI_SYNC_PATH;
    		try {
    			$result = file_put_contents( $save_path . '/custom-post-types.php', "<?php\n" . $post_type_export_data );
    		} catch ( Exception $e ) {
    			// do nothing.
    		}
    	}
    }
    add_action( 'cptui_after_update_post_type', 'cptui_sync_export_cpts_code' );
    
    /**
     * Export custom taxonomies on save
     * using the 'custom-post-types-ui' plugin.
     *
     * @return void
     */
    function cptui_sync_export_taxs_code() {
    	if ( function_exists( 'cptui_get_taxonomy_code' ) ) {
    		$cptui_taxonomies = cptui_get_taxonomy_data();
    		ob_start();
    		cptui_get_taxonomy_code( $cptui_taxonomies );
    		// Return the contents of the output buffer.
    		$taxonomy_export_data = ob_get_contents();
    		// Clean (erase) the output buffer and turn off output buffering.
    		ob_end_clean();
    		$save_path = CPTUI_SYNC_PATH;
    		try {
    			$result = file_put_contents( $save_path . '/custom-taxonomies.php', "<?php\n" . $taxonomy_export_data );
    		} catch ( Exception $e ) {
    			// do nothing.
    		}
    	}
    }
    add_action( 'cptui_after_update_taxonomy', 'cptui_sync_export_taxs_code' );
    
    
    
    
    

    Hope this helps, eager to hear from you!

    Terrance

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    @earthman100 Can you try out this copy of the plugin which has what would essentially be the fix I push out to address this PHP warning?

    https://www.dropbox.com/s/66m1kwo86p294n2/custom-post-type-ui-sort-fix.zip?dl=0

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Warning’ is closed to new replies.