WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] register_taxonomy() producing error with multisite admins (17 posts)

  1. David Bisset
    Member
    Posted 3 years ago #

    Greetings. I'm fairly new to custom taxonomies but in using register_taxonomy(), I find it fairly straightforward.

    Problem: Have a clean WordPress 3.1 Multi-Site (no plugins activated). Added this code into functions.php for my theme:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Confirmed that I was able to access the "Product Categories" taxonomy via the network admin. Then created a new blog with a new admin user. Logged into that child blog as the child blog's admin, and when attempting to click on "Product Categories" I get the WordPress error:

    "Cheat'n huh?"

    I'm not clear why this works for the network admin on the primary blog but not for the admin of the child blog. I've looked at register_taxonomy() in the codex and not seeing any setting that might effect this. It's also interesting to note that i'm able to create the custom taxonomy items in the add/edit screen of my custom post type.

    Any ideas or thoughts?

  2. And you're using the same theme on the child blog?

    have you tried registering the custom posts stuff in mu-plugins instead of the theme functions file?

  3. Michael Bishop

    Posted 3 years ago #

    You might need to set the capabilities arg, it defaults to none.

  4. Michael Bishop

    Posted 3 years ago #

    I see you set capability_type. I don't see that in the arguments. I see capability, and the options are manage_terms, edit_terms, delete_terms, or assign_terms.

    Strictly guessing here.

  5. David Bisset
    Member
    Posted 3 years ago #

    @andrea_r - yes, i'm using the same theme in both the main blog and the child blog.

    @miklb - good guess, but i tried a variety of different capabilities settings (I am passing in an array according to the codex, right?) but to no avail. Variations included:

    register_taxonomy("Product Categories", array("campaign"), array("hierarchical" => true, "label" => "Product Categories", "singular_label" => "Product Category", "capabilities" => array('manage_terms'), "rewrite" => array( 'slug' => 'product' )));
    
    register_taxonomy("Product Categories", array("campaign"), array("hierarchical" => true, "label" => "Product Categories", "singular_label" => "Product Category", "capabilities" => array('manage_terms','edit_terms','delete_terms','assign_terms'), "rewrite" => array( 'slug' => 'product' )));

    I exchanged 'terms' for 'categories' since I see in the codex there are terms to pass in for both.

  6. Michael Bishop

    Posted 3 years ago #

    ah, yes, probably is manage_categories.

    Darn, I really suspected it was a role/capability issue too. Bug?

  7. David Bisset
    Member
    Posted 3 years ago #

    @andrea_r - sorry but to be clear... are you proposing creating a mu-plugins folder in wp-content and throwing this custom code in there?

    I did that just now. I took the code out of functions.php in my theme file and placed it in a new file (custom-tax.php) in a newly created mu-plugins folder.

    Unfort. now this statement (which i made more simple for troubleshooting purposes here):

    register_taxonomy("Product Categories", array("campaign"));

    Is producing this error in the backend on any page load:

    Fatal error: Call to a member function add_rewrite_tag() on a non-object in /home/content/04/7653004/html/wp-includes/taxonomy.php on line 333

    Full code is below for the file, in case i'm missing something.
    http://pastebin.com/a0LEhFtn

    Edit: Removed embedded code and replaced w/ pastebin. :)

  8. Michael Bishop

    Posted 3 years ago #

    Something must be wonky with the user or theme you are testing with, as I just pasted your code as is in twentyten on a test 3.1.1 install and was able to create a new campaign with a regular site admin on a child site.

    Are you sure that user has the admin role for the child site?

  9. David Bisset
    Member
    Posted 3 years ago #

    @miklb - Yes, the user was created at the same time the child blog was (via the WordPress Network Admin 'add site' function).

    I can start another blog and do this from twentyten, although literally i'm working with an exact duplicate of it. But worth another try. But let's be clear - the problem isn't that I wasn't able to create a new campaign/post-type, it's when I attempt to go to the 'product categories' custom tax screen is where i get the error.

  10. Michael Bishop

    Posted 3 years ago #

    Ignore me. I see where you are getting that error, when you try to click post tags.

  11. David Bisset
    Member
    Posted 3 years ago #

    @milkb - To confirm, you are seeing the "cheat'n huh?" wordpress error as well?

  12. Michael Bishop

    Posted 3 years ago #

    Yes. With a normal site admin on a child site with your code, when I click Product Categories, I get the "Cheatin' uh?" screen.

  13. Michael Bishop

    Posted 3 years ago #

    I will note I've managed to be able to create/add new categories from the actual Campaigns edit/add new screens. Just can't access them from the menu item.

  14. Michael Bishop

    Posted 3 years ago #

    And I can confirm this is a probably a bug in 3.1, as I used similar code in a 3.0.4 install and it works.

    Code I used in a 3.1.1 environment and the 3.0.4 install http://pastebin.com/PAVsgabx

  15. Curtiss Grymala
    Member
    Posted 3 years ago #

    I'm not sure why this issue exists, but it has to do with the fact that your taxonomy name (the first parameter in the register_taxonomy() function) uses capital letters. Although it's not documented (and is most likely a bug), the taxonomy name can only include lowercase letters, hyphens and underscores.

    Therefore, change this line:

    register_taxonomy('Product_Categories',array('campaign'), array(

    to:

    register_taxonomy('product_categories',array('campaign'), array(

    and it will work.

    EDIT - It appears to be related to, though not exactly the same, as the bug reported at http://core.trac.wordpress.org/ticket/16600

    EDIT AGAIN - Just noticed that it is mentioned in the Codex article, but it's not extremely obvious. The following quote is currently in the description section of the codex article:

    In particular, capital letters should be avoided ()This was allowed in 3.0, but not enforced until 3.1 with the "Cheatin'" error).

  16. David Bisset
    Member
    Posted 3 years ago #

    @Curtiss,

    Yep that did it. Many thanks! I should have tried that - literally tried almost everything else. Hopefully someone make a note of that in the codex (maybe me!).

    So in summary if you use register_taxonomy(), keep your name in LOWERCASE letters, hyphens, and underscores.

    Thanks again @Curtiss, @andrea_r, and @miklb.

  17. Michael Bishop

    Posted 3 years ago #

    heh, I thought about the space and underscore, but not the lowercase.

    At least it was a good exercise for my upcoming project.

Topic Closed

This topic has been closed to new replies.

About this Topic