Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Add new custom post type => Fatal Error #239

Closed
BioSs54 opened this issue Oct 9, 2017 · 4 comments
Closed

Add new custom post type => Fatal Error #239

BioSs54 opened this issue Oct 9, 2017 · 4 comments

Comments

@BioSs54
Copy link

BioSs54 commented Oct 9, 2017

Can you reproduce this issue on default Wordpress theme (eg Storefront)?

No, custom type are not init

Can you reproduce this issue when all other plugins are disabled except WooCommerce, Polylang and Hyyan WooCommerce Polylang Integration?

Cant test

What product versions and settings are you using when this issue occurs?

  • PHP: 7.0
  • WordPress: 4.8.2
  • WooCommerce: 3.2.0
  • Polylang: free
  • Hyyan WooCommerce Polylang Integration: 1.0.3
  • Browser: Chrome 61

Steps to Reproduce

  1. Go to admin custom post
  2. Add new
  3. FATAL ERROR

My custom type fonction

register_post_type('presse',
        array(
            'labels' => array(
                'name' => __( 'Presse' ),
                'singular_name' => __( 'Presse' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'esprit/presse', 'with_front' => false),
            'show_in_nav_menus' => true,
            'exclude_from_search' => true,
            'show_in_menu' => true,
            'supports' => array('title', 'custom-fields', 'taxonomy'),
            'menu_icon'   => 'dashicons-book',
            )
    );

What Happened Instead

Fatal error: Uncaught TypeError: Argument 2 passed to Hyyan\WPI\Product\Variable::duplicateVariations() must be an instance of WP_Post, null given, called in /var/www/develop/public/wp-includes/class-wp-hook.php on line 298 and defined in /var/www/develop/public/wp-content/plugins/woo-poly-integration/src/Hyyan/WPI/Product/Variable.php:57 Stack trace: #0 /var/www/develop/public/wp-includes/class-wp-hook.php(298): Hyyan\WPI\Product\Variable->duplicateVariations(0, NULL, false) #1 /var/www/develop/public/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #2 /var/www/develop/public/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /var/www/develop/public/wp-includes/post.php(3510): do_action('save_post', 0, NULL, false) #4 /var/www/develop/public/wp-admin/includes/post.php(607): wp_insert_post(Array) #5 /var/www/develop/public/wp-admin/post-new.php(83): get_default_post_to_edit('presse', true) #6 {main} thrown in /var/www/develop/public/wp-content/plugins/woo-poly-integration/src/Hyyan/WPI/Product/Variable.php on line 57

@Jon007
Copy link
Contributor

Jon007 commented Oct 9, 2017

your custom post should derive from WP_Post, many plugins including this one hook save_post and this hook is expecting to receive a WP_Post as defined in WordPress. If the post is not of the relevant type it will exit without taking any action.

How are you triggering save_post and Is there a problem with the post you are trying to save?

do_action('save_post', 0, NULL, false)

the standard wp_insert_post() saves the post and gets the ID from the insert before proceeding to call:

	/**
	 * Fires once a post has been saved.
	 *
	 * @since 1.5.0
	 *
	 * @param int     $post_ID Post ID.
	 * @param WP_Post $post    Post object.
	 * @param bool    $update  Whether this is an existing post being updated or not.
	 */
	do_action( 'save_post', $post_ID, $post, $update );

If there is an error on save the code bails and doesn't get this far, so in normal use this would never get called with zero and null... are you triggering this action in a different way?

At least I have plenty of custom post types and not seen this type of problem.

@hyyan
Copy link
Owner

hyyan commented Oct 24, 2017

@BioSs54 is this still a problem?

@BioSs54
Copy link
Author

BioSs54 commented Oct 24, 2017

I solved problem by a reset of all plugins. My bad, sorry. :(

@Jon007
Copy link
Contributor

Jon007 commented Oct 24, 2017

close the issue then..

@Jon007 Jon007 closed this as completed Oct 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants