• Resolved stereoscott

    (@stereoscott)


    We have a plugin that creates it’s own custom post type. This post type has a custom rewrite slug.

    When activating this Custom Post Type Maker plugin, it overrides our other post type rewrite rules and breaks the other post type. Deactivating the plugin fixes the issue, but it would be great if this plugin was compatible with others.

    Here is an example. This post type shows up in the plugin’s list of other custom post types, but the rewrite rules are not in the global rewrite array.

    register_post_type( 'our_custom_post_type',
            array(
              'labels' => array(
                'name' => __( 'Custom Name' ),
                'singular_name' => __( 'Custom Name' )
              ),
              'public' => true,
              'rewrite' => array('slug' => 'custom-slug', 'with_front' => false),
              'hierarchical' => false,
              'capability_type' => 'post',
              'has_archive' => false,
              'publicly_queryable' => true,
              'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')
            )
          );

    http://wordpress.org/extend/plugins/custom-post-type-maker/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Jorn Bakhuys

    (@jornbakhuys)

    Hi Scott,

    This of course is something that should not happen.

    At this moment I have no clue what could cause this bug, since the plugin only registers post types, and does not overwrite or unregisters any other settings.

    Just to point out the obvious, does you already registered post type have the same name as a post type you registered through the plugin?
    And do they both have different rewrite slugs?

    Thanks for pointing out this bug. If you have any other information that could point out what the reason of this bug could be, please let me know. In the meantime I will look into it.

    Thread Starter stereoscott

    (@stereoscott)

    Thanks Jorn, I’ve been exploring this issue myself. I wonder if it has something to do with the order in which the plugins are loaded.

    A simple way to reproduce the issue would be to create a super simple plugin with a generic custom post type, activate it, and see if the rewrite rules work. I’ve done just that. Here is the plugin file:

    <?php
    /*
    Plugin Name: Custom Post Type Test
    Author: Scott Meves
    Version: 1.0
    */
    
    //avoid direct calls to this file, because now WP core and framework has been used
    if ( !function_exists('add_action') ) {
    header('Status: 403 Forbidden');
    header('HTTP/1.1 403 Forbidden');
    exit();
    }
    
    if ( !class_exists( 'PostTypeTest' ) ) {
      class PostTypeTest {
    
        function PostTypeTest() {
          register_post_type( 'custom_post_type',
            array(
              'labels' => array(
                'name' => __( 'Custom Name' ),
                'singular_name' => __( 'Singular Name' )
              ),
              'public' => true,
              'rewrite' => array('slug' => 'custom-url-here', 'with_front' => false),
              'hierarchical' => false,
              'capability_type' => 'post',
              'has_archive' => false,
              'publicly_queryable' => true,
              'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')
            )
          );
        }
      } // end class
      // Initiate the plugin
      add_action("init", "PostTypeTestInit");
      function PostTypeTestInit() {
        global $the_customPostType;
        $the_customPostType = new PostTypeTest();
      }
    }

    When I add this simple plugin, and deactivate the “Custom Post Type Maker” plugin, and then re-save the permalink settings / flush the rewrite rules… sure enough my custom rewrite rule works just fine (“/custom-url-here/…”).

    But if I activate the “Custom Post Type Maker” plugin again, the other custom post type rules disappear.

    Thread Starter stereoscott

    (@stereoscott)

    By the way, I’ve been using a plugin to output the rewrite rules in a friendly way in the admin area to help with debugging. http://wordpress.org/extend/plugins/monkeyman-rewrite-analyzer/

    Hi,

    I think what I’m experiencing has got something to do with this same problem. After activating “Custom Post Type Maker” plugin, most of the “Polylang” rewrite rules disappear. The only one that stays intact is the one with no other rules associated, ie. plain “/%lang%”.

    Deactivating and activating “Polylang” or re-saving WP permalink settings does not fix the problem until “Custom Post Type Maker” has been deactivated agan.

    Plugin Author Jorn Bakhuys

    (@jornbakhuys)

    Hi guys,

    Thanks for the updates. I will look into this tonight. Due to limited spare time I will need to work on a quick-fix for this so at least the plugin is usable again.

    Sorry for the inconvenience.

    I’ve switched over to “WCK Post Type Creator” for now.
    What might be of your intrest about that particular plugin is that it has the same problem — as do most others actually — but in this case re-saving WP permalink settings will fix the rules. Just thought you might want to compare the code to get some more ideas as to what might be going on here.

    Other than this strange issue “Custom Post Type Maker” is in my opinion far superior to other similar plugins and I will gladly switch back soon. 🙂

    Plugin Author Jorn Bakhuys

    (@jornbakhuys)

    Hi Scott and Ahto,

    I have tried to replicate the problem.
    I have installed the test plugin file you have provided, and also installed the monkeyman-rewrite-analyzer.
    The weird thing is, everything seems to be working fine at my end.

    I can generate a custom post type post through your plugin code and reach it at the front-end, with Custom Post Type Maker activated. Also rewriting / flushing the permalink structure does not create problems.

    Unfortunately this makes fixing the problem very hard for me. So if you guys have any other clues, they are more then welcome, so I can have a look at it.

    Thanks again for your help.

    I was having the same issue but I think I got it sorted out.

    I commented out these lines in the plugin:
    // flush permalink structure
    global $wp_rewrite;
    $wp_rewrite->flush_rules();

    Then I deactivate & reactivated the plugin and then I saved the permalinks.

    Now both this plugin and my other plugins which have their own custom post type seem to work.

    Plugin Author Jorn Bakhuys

    (@jornbakhuys)

    This issue got sorted in the latest version (0.1.3)

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Overwrites other post type rewrite rules’ is closed to new replies.