ThemeFuse / Unyson

A WordPress framework that facilitates the development of WP themes
http://unyson.io
922 stars 218 forks source link

Wordpress Page has post_type with Unyson activated #496

Closed pnpetroff closed 9 years ago

pnpetroff commented 9 years ago

I registered new custom post type in a plugin like this:

$labels = array(
            'name'               => _x( 'Custom Posts', 'post type general name', 'post_type' ),
            'singular_name'      => _x( 'Cusom Post', 'post type singular name', 'post_type' ),
            'menu_name'          => _x( 'Custom Posts', 'admin menu', 'post_type' ),
            'name_admin_bar'     => _x( 'Custom Posts', 'add new on admin bar', 'post_type' ),
            'add_new'            => _x( 'Add New', 'post_type', 'post_type' ),
            'add_new_item'       => __( 'New Cusom Post', 'post_type' ),
            'new_item'           => __( 'New Cusom Post', 'post_type' ),
            'edit_item'          => __( 'Edit Cusom Post', 'post_type' ),
            'view_item'          => __( 'View Cusom Post', 'post_type' ),
            'all_items'          => __( 'All Custom Posts', 'post_type' ),
            'search_items'       => __( 'Search Custom Posts', 'post_type' ),
            'not_found'          => __( 'No customposts found.', 'post_type' ),
            'not_found_in_trash' => __( 'No customposts found in Trash.', 'post_type' )
        );

        $args = array(
            'labels'              => $labels,
            'public'              => true,
            'exclude_from_search' => true,
            'show_in_nav_menus'   => true,
            'show_in_menu'        => true,
            'query_var'           => true,
            'rewrite'             => array( 'slug' => 'post_type' ),
            'capability_type'     => 'post',
            'hierarchical'        => false,
            'menu_position'       => null,
            'supports'            => array( 'title', 'editor' )
            );

        register_post_type( 'post_type', $args );

And with Unyson installed and activated I'm seeing my (default wordpress) Pages have this custom post type. It's permalink also have the post type slug. When I disable my plugin and open a Page for editing it gives

 Notice: Trying to get property of non-object in site-name\wp-admin\includes\post.php on line 1223

Writing print_r($post->post_type); on line 1196 in posts.php gives me the custom post type name in the page editor. Tried resetting the Permalinks but the error still stays. I'm also running flush_rewrite_rules(); when my plugin is activated or disabled.

Disabling Unyson fixes the problem..

pnpetroff commented 9 years ago

Anyone? Ideas?

llemurya commented 9 years ago

@pe6o can you one by one disable the Unyson extensions that you have enable in order to localize from what extension you have this problem, because when you disable the whole plugin , you disable all extensions, here is an screenshot that explain how to disable extensions.

pnpetroff commented 9 years ago

@llemurya It's happening with the Page Builder extension.The moment I enable it, in the URL of the page is inserted the post type before its slug.

llemurya commented 9 years ago

@pe6o you trying this with the last version of the page builder, builder? Please download it from this page, and pay attention if you have the latest version of the Unyson that is v2.2.8, please test it and say if bug remains?

pnpetroff commented 9 years ago

Yes, I'm using the latest version.

Strange things are happening..

I disabled the custom post type plugin, enabled Unyson with Page Builder and whatever Page I click on, it has the same title. The custom post type slug is removed from the permalink of the page but holy goly look at this screenshot!

It gives the same errors (notices) when I try to add new page.

llemurya commented 9 years ago

@pe6o can you see other third party plugins maybe they cause your errors? please disable one by one and give us an answer.

pnpetroff commented 9 years ago

There is nothing enabled except for Unyson. Not the only way to remove those errors is either to disable Unyson or enable the custom post type plugin and Unyson.

I stripped all the functionality of the plugin and left only the post type register. It uses the known Wordpress Plugin Boilerplate - here is a link.

llemurya commented 9 years ago

@pe6o I tested and for me it works, but WordPress have an strange behavior because you name your custom post type post_type I think this naming is improper , it can cause name collision in the WordPress, as a proof you can see this video , pay attention when the post type is named post_type the pages didn't show but their exists. If it helps, please close the issue.

pnpetroff commented 9 years ago

It's strange, the example I gave you is with book post_type.

Okay, I found the culprit. It's directly connected to my solution trying to implement prepopulated multi select field - https://github.com/ThemeFuse/Unyson/issues/456#issuecomment-93731176

I was passing the non-existent (when the plugin is not installed) custom post type to the helper function that is populating my selection array. Implemented a post_type_exists check and now it works.

This issue was not connected with the framework... I'm really sorry for the lost time.

pnpetroff commented 9 years ago

Okay, the bug is back and I managed to target it. When I create the array population function ( in options.php of the shortcode or hooks.php of the theme, it doesn't matter) the post type slug is attached in the URL of the page.

Here is a link to the page builder shortcode -https://www.dropbox.com/s/dxqhrbpq0xsalzj/addable-shortcode.zip?dl=0 Open its options.php to see the function, you can try putting it in hooks.php.

Install also the plugin with the custom post type books (as the array have to be populated with booksposts) and then try to create new Page, you should get the bug.

llemurya commented 9 years ago

@pe6o see this answer at the issue and this link , because I downloaded the source from dropbox and I saw that you you make an WP_Query object but you didn't reset to normal flow the global $post please read answers because I think it is the same problem.I'am waiting for your response.

pnpetroff commented 9 years ago

Whoa, why is $post changed and wp_reset_postdata() is not resetting it?

I implemented the solution and now it works. Can't understand why the global $post stayed changed..