CPT-onomies Update: Version 1.3 (MULTISITE!)

By | CPT-onomies, Plugins, Uncategorized, WordPress | 3 Comments
Download CPT-onomiesCPT-onomies Documentation

I’m pretty excited about this update and multisite compatibility is the reason why! As someone who manages a pretty vast multisite network, I think WordPress multisite is awesome and hope others find this new functionality useful as well.

But version 1.3 didn’t present itself solely bearing the fruits of multisite. Here’s the full list of improvements:

  • Added multisite custom post type manager.
  • Added setting to assign meta box format, i.e. autocomplete, checklist or dropdown.
  • Added “Show Admin Column” to the CPT-onomy settings.
    • This is a new register_taxonomy() setting as of WordPress 3.5.
    • Before, CPT-onomies added the column itself but will now hook into this new core taxonomy functionality.
    • I will retain backwards compatability for a little while.
  • Deprecated the ability to make the CPT-onomy admin columns sortable in order to align with new, core WP taxonomy admin column functionality.
    • The new core WordPress taxonomy admin columns are not sortable so, therefore, I’ve removed the column sort functionality from the plugin.
  • Deprecated the ‘custom_post_type_onomies_add_cpt_onomy_admin_sortable_column’ filter.
    • Before, you could use this filter to turn off the column sortability. Now, with sorting gone, there’s no need to have the filter.
  • Added support for the “Gravity Forms + Custom Post Types” plugin.
    • This particular feature was commissioned by a user and will allow you to create CPT-onomy relationships when you use a Gravity Forms form to create a custom post type post.
  • Added the ability to only include/assign specific terms by passing term IDs to a filter.
    • Like the previously added “exclude” filter, this filter allows you to designate that you only want specific CPT-onomy term(s) to be allowed to be assigned.
  • Added wp_set_post_terms() to the CPT-onomy class.

Hope you the enjoy the update. I already have ideas for the next round! And, as always, please let me know if you have any questions or find any bugs! Thanks!

CPT-onomies Update: Version 1.2

By | CPT-onomies, Uncategorized, WordPress | No Comments
Download CPT-onomiesCPT-onomies Documentation

To say my life has been crazy the past 6 months would be a very large understatement but CPT-onomies 1.2 is finally here! On top of a few minor bug fixes, here’s what 1.2 brings to the table:

  • Create custom CPT-onomy archive pages with just a few simple lines of code!
  • Added the ability to set a CPT-onomy term description using ‘term_description’ or ‘{$taxonomy}_description’ filter’.
  • Non-public custom post types can now be used as CPT-onomies.
  • Exclude CPT-onomy terms from being listed in the “Assigning CPT-onomy Terms” admin meta box and, therefore, from being assigned to a post.
  • Added numerous filters, allowing you to:
    • Remove “Assigning CPT-onomy Terms” meta boxes from admin
    • Remove CPT-onomy dropdown filters from admin
    • Remove the CPT-onomy column and/or it’s sortability
    • Customize settings by removing options and setting default property values
  • I changed the cpt_onomy.php filename to cpt-onomy.php to match cpt-onomies.php (I’m not really sure why I gave it an underscore to begin with).
  • I, like many others, fixed the $wpdb->prepare() issue.
  • If you use the following CPT-onomy settings, be sure to re-save your settings to fix potential bugs:
    • Capability Type
    • Capabilities -> Read Private Posts

I hope you enjoy the update! And, like always, please let me know if you find any bugs. If you need me anytime soon, I’ll be the one drinking some damn scotch. Until next time, keep up the awesomeness!

How to Define Reserve Slugs for WordPress Posts and Pages

By | Tutorial, WordPress | No Comments

This post was inspired by an answer I posted in the WordPress Stack Exchange.

This is an interesting WordPress problem that could span several scenarios. But let’s say you have a custom post type named ‘songs’ and you defined its slug as ‘songs’ so its archive page URL is http://www.mysite.com/songs.

This is fine and all but a slug used for a custom post type archive page, i.e. ‘songs’, is not saved in the database and is, therefore, not available when you’re creating/editing posts to tell WordPress “NO! The slug ‘songs’ is taken!”. With that said, a user could come along and create a post (or page) with the slug ‘songs’ which would therefore have the same URL as your custom post type archive page: http://www.mysite.com/songs.

So how do you keep users on your site from creating posts with particular slugs, a.k.a. reserve slugs?

It’s pretty simple, actually. Use one, or both, of the following two filters. They hook into WordPress when it’s checking a post’s slug, allowing you to return “true” which tells WordPress that the post slug is bad. If you return “true”, WordPress adds on a suffix, just like it would do if you were trying to use a slug that is already taken.

The first filter, ‘wp_unique_post_slug_is_bad_hierarchical_slug’, is for hierarchical posts and the second filter, ‘wp_unique_post_slug_is_bad_flat_slug’, is for non-hierarchical posts. While both filters provide the post’s $slug and $post_type, the hierarchical filter also provides the ID for the post parent so if the $post_parent is 0, you know this is a “base” post.

add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', 'rachel_carden_is_bad_hierarchical_slug', 10, 4 );
function rachel_carden_is_bad_hierarchical_slug( $is_bad_hierarchical_slug, $slug, $post_type, $post_parent ) {
   // This post has no parent and is a "base" post
   if ( !$post_parent && $slug == 'songs' )
      return true;
   return $is_bad_hierarchical_slug;

add_filter( 'wp_unique_post_slug_is_bad_flat_slug', 'rachel_carden_is_bad_flat_slug', 10, 3 );
function rachel_carden_is_bad_flat_slug( $is_bad_flat_slug, $slug, $post_type ) {
   if ( $slug == 'songs' )
      return true;
   return $is_bad_flat_slug;

These filters can be found in the WordPress function wp_unique_post_slug() in the wp-includes/post.php file.