From 9358f6e72a5e081da2c4738c7334bc575a541b50 Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Tue, 5 May 2015 15:28:18 -0700 Subject: [PATCH 1/3] Ensure that built-in taxonomies are registered --- classes/class-awesome-post-type.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/classes/class-awesome-post-type.php b/classes/class-awesome-post-type.php index 929d643..c38d6c9 100644 --- a/classes/class-awesome-post-type.php +++ b/classes/class-awesome-post-type.php @@ -27,8 +27,14 @@ public function __construct( $params ) { // Otherwise, generate messages add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ), 10 ); } + // Ensures that built-in taxonomies are registered for post type + if ( ! empty( $this->args['taxonomies'] ) ) { + foreach ( $this->args['taxonomies'] as $taxonomy_id ) { + register_taxonomy_for_object_type( $taxonomy_id, $this->id ) + } + } } - + // Initialize CPT public function init() { register_post_type( $this->id, $this->args ); From ce765caef5612a9f3d213e57703a2edd9b1aca3e Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Tue, 5 May 2015 15:45:44 -0700 Subject: [PATCH 2/3] Remove trailing whitespace and break lines in docs --- docs/meta-boxes.md | 75 ++++++++++++++++++++++++++++++---------------- docs/post-types.md | 59 ++++++++++++++++++++++++++---------- docs/taxonomies.md | 23 ++++++++------ 3 files changed, 106 insertions(+), 51 deletions(-) diff --git a/docs/meta-boxes.md b/docs/meta-boxes.md index ed320fb..2aad4fd 100644 --- a/docs/meta-boxes.md +++ b/docs/meta-boxes.md @@ -2,7 +2,9 @@ ## General usage -You can create a new taxonomy using the `Awesome_Meta_Box` class, the constructor for which accepts an array of properties. This array accepts a number of various properties. +You can create a new taxonomy using the `Awesome_Meta_Box` class, the +constructor for which accepts an array of properties. This array accepts a +number of various properties. * `id`: required; the ID of the meta box * `title`: required; the displayed title of the meta box @@ -11,7 +13,8 @@ You can create a new taxonomy using the `Awesome_Meta_Box` class, the constructo * `priority`: optional; the priority within the context where the meta box should show (`high`, `core`, `default`, or `low`) * `fields`: optional; an array of data fields that are to be displayed in the meta box -Assuming a new instance of `Awesome_Post_Type` (with an `id` of `movie`) has already been created: +Assuming a new instance of `Awesome_Post_Type` (with an `id` of `movie`) has +already been created: ``` $release_date = new Awesome_Meta_Box( array( @@ -21,12 +24,14 @@ $release_date = new Awesome_Meta_Box( array( 'context' => 'normal', 'priority' => 'high', 'fields' => array() -) ) +) ); ``` ## Fields -As mentioned above, each `Awesome_Meta_Box` instance must have an array of fields, each of which represents a form field in the meta box. This array can any number of field, each of which is itself an array. +As mentioned above, each `Awesome_Meta_Box` instance must have an array of +fields, each of which represents a form field in the meta box. This array can +any number of field, each of which is itself an array. Each field accepts the following properties: @@ -62,12 +67,13 @@ $release_date = new Awesome_Meta_Box( array( 'placeholder' => 'Enter the movie release date here' ) ) -) ) +) ); ``` ### `before` and `after` properties -As briefly mentioned above, the `before` and `after` properties determine what HTML should precede and follow (respectively) any given field. +As briefly mentioned above, the `before` and `after` properties determine what +HTML should precede and follow (respectively) any given field. ``` array( @@ -80,7 +86,8 @@ array( ) ``` -If you'd prefer to set the default `before` and `after` HTML for all fields, modify the static `field_defaults` array. +If you'd prefer to set the default `before` and `after` HTML for all fields, +modify the static `field_defaults` array. ``` Awesome_Meta_Box::$field_defaults['before'] = '' @@ -89,7 +96,8 @@ Awesome_Meta_Box::$field_defaults['after'] = '
' ### Examples -Below are examples of the various input types you can create. For all of these types, Awesome CPT will handle the HTML escaping of values on your behalf. +Below are examples of the various input types you can create. For all of these +types, Awesome CPT will handle the HTML escaping of values on your behalf. #### Text fields (``) @@ -107,28 +115,32 @@ array( ``` array( 'id' => 'review', - 'type' => 'textarea', + 'type' => 'textarea', 'placeholder' => 'Enter a short review of the movie' ) ``` #### Checkboxes (``) -Note that Awesome CPT will automatically add a `hidden` input to allow for the proper saving of the checkbox value. This default unchecked value is `off`. +Note that Awesome CPT will automatically add a `hidden` input to allow for the +proper saving of the checkbox value. This default unchecked value is `off`. ``` array( 'id' => 'supports_3d', - 'type' => 'checkbox', + 'type' => 'checkbox', 'label' => 'Available in 3D?', 'value' => 'on', 'checked' => false ) ``` -The following example will output a list of checkboxes for selecting the languages in which the movie is available. +The following example will output a list of checkboxes for selecting the +languages in which the movie is available. -Note that each field `name` ends in a pair of brackets—this is to ensure the checked values are properly saved. Also note that the example utilizes the `before` and `after` properties to +Note that each field `name` ends in a pair of brackets—this is to ensure the +checked values are properly saved. Also note that the example utilizes the +`before` and `after` properties to ``` array( @@ -166,7 +178,7 @@ array( ``` array( 'id' => 'my_radio_button', - 'type' => 'radio', + 'type' => 'radio', 'label' => 'My Radio Button', 'checked' => false ) @@ -177,7 +189,7 @@ array( ``` array( 'id' => 'my_radio_button', - 'type' => 'radio', + 'type' => 'radio', 'label' => 'My Radio Button', 'src' => get_template_directory_uri() . '/images/myimage.png', 'alt' => 'My Image' @@ -216,9 +228,12 @@ array( ##### Custom options -Instead of passing an array of option arrays, you can also pass a function reference to the `options` property. The referenced function must return an array in the same form as the one above (an array of option arrays). +Instead of passing an array of option arrays, you can also pass a function +reference to the `options` property. The referenced function must return an +array in the same form as the one above (an array of option arrays). -See the example below, which modifies the previous example to dynamically generate a menu of ratings. +See the example below, which modifies the previous example to dynamically +generate a menu of ratings. ``` array( @@ -241,14 +256,15 @@ array( ) ``` -Again, note that the anonymous functions used above are only supported in PHP 5.3 and newer. +Again, note that the anonymous functions used above are only supported in PHP +5.3 and newer. #### Date pickers (``) ``` array( 'id' => 'my_date_picker', - 'type' => 'date', + 'type' => 'date', 'label' => 'My Date Picker', 'value' => '2014-01-01' ) @@ -259,7 +275,7 @@ array( ``` array( 'id' => 'my_color_picker', - 'type' => 'color', + 'type' => 'color', 'label' => 'My Color Picker', 'value' => '#000' ) @@ -267,9 +283,13 @@ array( #### Custom fields -You can also specify custom HTML for your field by passing a function reference to the `populate` property. This allows for dynamic generation of your field to fit your needs (such as querying posts or sending a request). +You can also specify custom HTML for your field by passing a function reference +to the `populate` property. This allows for dynamic generation of your field to +fit your needs (such as querying posts or sending a request). -Note that you still need to specify the field's ID in the field array, though you can access this in your `populate` function for awesome reuse (via the `$field` parameter). +Note that you still need to specify the field's ID in the field array, though +you can access this in your `populate` function for awesome reuse (via the +`$field` parameter). ``` array( @@ -282,15 +302,18 @@ array( ) ``` -Also note that using the `populate` callback will require you to escape the variables you use. +Also note that using the `populate` callback will require you to escape the +variables you use. #### Filters -You can also pass the value of a meta box field through a filter before being saved to the database or displayed in the field. +You can also pass the value of a meta box field through a filter before being +saved to the database or displayed in the field. ##### `save` filter -The meta value will be run through the `save` filter before the meta data is saved to the post object. +The meta value will be run through the `save` filter before the meta data is +saved to the post object. ``` array( @@ -307,7 +330,7 @@ array( ##### `display` filter -The meta value will be run through the `display` filter before being displayed +The meta value will be run through the `display` filter before being displayed ``` array( diff --git a/docs/post-types.md b/docs/post-types.md index 2b63685..57c8f5e 100644 --- a/docs/post-types.md +++ b/docs/post-types.md @@ -2,9 +2,14 @@ ## Basic syntax -You can create a new custom post type using the `PostType` class. The constructor for which accepts an array containing properties specific to Awesome CPT (these include most of the properties documented below). +You can create a new custom post type using the `PostType` class. The +constructor for which accepts an array containing properties specific to Awesome +CPT (these include most of the properties documented below). -Ever post type requires an ID (lowercase letters and underscores only) and the singular and plural variants of the post type name (letters and spaces only). The singular and plural names should be lowercase *in most cases* (special casing is mentioned in the next section). +Ever post type requires an ID (lowercase letters and underscores only) and the +singular and plural variants of the post type name (letters and spaces only). +The singular and plural names should be lowercase *in most cases* (special +casing is mentioned in the next section). ``` $movie = new Awesome_Post_Type( array( @@ -26,11 +31,14 @@ $small_group = new Awesome_Post_Type( array( ) ); ``` -Note that internally, the custom post type is initialized when WordPress is initialized (via the `init` action, with a priority of 10). +Note that internally, the custom post type is initialized when WordPress is +initialized (via the `init` action, with a priority of 10). ## Names -Awesome CPT will automatically generate capitalized and title variants based on the `name` array you provide (using `ucfirst()` and `ucwords()`, respectively). For instance, the above `small_group` post type is equivalent to the following: +Awesome CPT will automatically generate capitalized and title variants based on +the `name` array you provide (using `ucfirst()` and `ucwords()`, respectively). +For instance, the above `small_group` post type is equivalent to the following: ``` $small_group = new Awesome_Post_Type( array( @@ -50,7 +58,9 @@ $small_group = new Awesome_Post_Type( array( ) ); ``` -In most cases, you can let Awesome CPT correctly generate these other name variants. However, for names which require special casing, you may specify these variants yourself. +In most cases, you can let Awesome CPT correctly generate these other name +variants. However, for names which require special casing, you may specify these +variants yourself. ``` $tv_show = new Awesome_Post_Type( array( @@ -72,7 +82,8 @@ $tv_show = new Awesome_Post_Type( array( ## Arguments -Awesome CPT also accepts an array of arguments (the same arguments array passed to `register_post_type`) via the `args` property: +Awesome CPT also accepts an array of arguments (the same arguments array passed +to `register_post_type`) via the `args` property: ``` $movie = new Awesome_Post_Type( array( @@ -89,13 +100,17 @@ $movie = new Awesome_Post_Type( array( ) ); ``` -You can read about these possible arguments via the [WordPress Codex](http://codex.wordpress.org/Function_Reference/register_post_type#Arguments). +You can read about these possible arguments via the [WordPress +Codex](http://codex.wordpress.org/Function_Reference/register_post_type#Arguments). -Note that all Awesome CPT post types are made public by default (in contrast to the normal WordPress default for `public`). +Note that all Awesome CPT post types are made public by default (in contrast to +the normal WordPress default for `public`). ## Labels -CTP Classes will automatically create labels for your post type based on the `name`, `title`, and `cap_name` arrays. For instance, the first `small_group` example will generate the following labels: +CTP Classes will automatically create labels for your post type based on the +`name`, `title`, and `cap_name` arrays. For instance, the first `small_group` +example will generate the following labels: ``` 'name' => 'Small Groups' @@ -132,9 +147,12 @@ $small_group = new Awesome_Post_Type( array( ### Messages -One of the unique features of Awesome CPT is its ability to automatically generate action messages for your post type. These messages appear when you publish, schedule, or update a post. +One of the unique features of Awesome CPT is its ability to automatically +generate action messages for your post type. These messages appear when you +publish, schedule, or update a post. -If you wish to override these messages, Awesome CPT allows you to hook directly into the `post_updated_messages` filter, like so: +If you wish to override these messages, Awesome CPT allows you to hook directly +into the `post_updated_messages` filter, like so: ``` function my_post_updated_messages( $messages ) { @@ -153,7 +171,10 @@ $movie = new Awesome_Post_Type( array( ## Columns -You can add columns to a custom post type's admin screen using the `add_columns()` method. The method accepts an array as its only argument, which in turn accepts a variable number of arrays. Each of these arrays contains properties for each column. +You can add columns to a custom post type's admin screen using the +`add_columns()` method. The method accepts an array as its only argument, which +in turn accepts a variable number of arrays. Each of these arrays contains +properties for each column. The properties of each column include: @@ -187,7 +208,9 @@ $tv_show->add_columns( array( ) ); ``` -Note that the anonymous functions used above are only supported in PHP 5.3 and newer. For older versions, define your function beforehand, and set the `populate` property to the function's name as a string. +Note that the anonymous functions used above are only supported in PHP 5.3 and +newer. For older versions, define your function beforehand, and set the +`populate` property to the function's name as a string. ``` ... @@ -205,7 +228,10 @@ Naturally, you can also reference methods if you are working within a class: ### Sortable columns -To make a column sortable, simply specify the `meta_key` and `orderby` properties for any given column. The value for the `meta_key` property must be the ID of some meta data stored on the post. The `orderby` property is the generic name of the data by which you are sorting (as shown in the page URL). +To make a column sortable, simply specify the `meta_key` and `orderby` +properties for any given column. The value for the `meta_key` property must be +the ID of some meta data stored on the post. The `orderby` property is the +generic name of the data by which you are sorting (as shown in the page URL). ``` array( @@ -217,9 +243,10 @@ array( 'meta_key' => 'gross_income', 'orderby' => 'gross_income', 'numeric' => true -) +); ``` -Setting the `numeric` property's value to `true` will sort the column numerically rather than alphabetically. +Setting the `numeric` property's value to `true` will sort the column +numerically rather than alphabetically. ## [Read about taxonomies](taxonomies.md) diff --git a/docs/taxonomies.md b/docs/taxonomies.md index 340c1db..774741b 100644 --- a/docs/taxonomies.md +++ b/docs/taxonomies.md @@ -2,12 +2,14 @@ ## General usage -You can create a new taxonomy using the `Awesome_Taxonomy` class. The constructor for which accepts two required arguments: +You can create a new taxonomy using the `Awesome_Taxonomy` class. The +constructor for which accepts two required arguments: 1. An array containing properties specific to Awesome CPT (these include most of the properties documented below) 2. The arguments array that is normally passed to WordPress's [`register_taxonomy()`](https://codex.wordpress.org/Function_Reference/register_taxonomy) function -Assuming a new instance of `Awesome_Post_Type` (with an `id` of `movie`) has already been created: +Assuming a new instance of `Awesome_Post_Type` (with an `id` of `movie`) has +already been created: ``` $genre = new Awesome_Taxonomy( array( @@ -16,7 +18,7 @@ $genre = new Awesome_Taxonomy( array( 'singular' => 'genre', 'plural' => 'genres' ), - 'post_types' => array( 'movie' ) + 'post_types' => array( 'movie' ), 'args' => array( 'hierarchical' => true, 'show_admin_column' => true @@ -24,13 +26,17 @@ $genre = new Awesome_Taxonomy( array( ); ``` -As you can see, the `post_types` array should contain the `id` of each post type you want to associate with the taxonomy. +As you can see, the `post_types` array should contain the `id` of each post type +you want to associate with the taxonomy. -Note that internally, the custom taxonomy is initialized when WordPress is initialized (via the `init` action, with a priority of 10). +Note that internally, the custom taxonomy is initialized when WordPress is +initialized (via the `init` action, with a priority of 10). ## Filterable taxonomies -Awesome CPT allows you to easily make any taxonomy filterable via the `filterable` property. Setting its value to `true` will add a dropdown menu to your post type admin screen, from which you can filter your posts by taxonomy. +Awesome CPT allows you to easily make any taxonomy filterable via the +`filterable` property. Setting its value to `true` will add a dropdown menu to +your post type admin screen, from which you can filter your posts by taxonomy. To work off the above example of a `genre` taxonomy: @@ -42,12 +48,11 @@ $genre = new Awesome_Taxonomy( array( 'plural' => 'genres' ), 'post_types' => array( 'movie' ), - 'filterable' => true - ), + 'filterable' => true, 'args' => array( 'hierarchical' => true ) -)l +); ``` ## [Read about meta boxes](meta-boxes.md) From 9fd00df2b0ba554712c1d7663ebaed3bf7a0d388 Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Mon, 25 May 2015 21:11:51 -0700 Subject: [PATCH 3/3] Update year in license --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8722888..176a852 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Awesome CPT -*Copyright 2014 Caleb Evans* + +*Copyright 2015 Caleb Evans* *Licensed under the MIT license* Awesome CPT is a set of classes designed to make coding WordPress custom post