From cf26c2ea9ee3dd653b03fda804133ef48ee04648 Mon Sep 17 00:00:00 2001 From: Vincent Klaiber Date: Tue, 28 Jan 2014 11:44:05 +0100 Subject: [PATCH 1/5] Add .gitattributes to make the package lighter when deploying for production. Running ```composer install --prefer-dist``` will exclude any files and directories specified within .gitattributes. --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e9d9d40 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +/examples export-ignore From e21e5b670b1347c3e2ea2bec03f866572ff3cd8c Mon Sep 17 00:00:00 2001 From: Vincent Klaiber Date: Wed, 29 Jan 2014 14:42:18 +0100 Subject: [PATCH 2/5] Update notes in README, example link was broken. example.php doesn't exist anymore. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e633e2..d0f036c 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ For a full list of icons and the class names to use visit [http://melchoyce.gith ## Notes * The class has no methods for making custom fields for post types, use [Advanced Custom Fields (ACF)](http://advancedcustomfields.com) -* The books example used in the README.md can be found in the [example.php](https://github.com/jjgrainger/wp-custom-post-type-class/blob/master/example.php) +* The books example used in the README.md can be found in the [books-post-type.php](examples/books-post-type.php) * Licensed under the [MIT License](https://github.com/jjgrainger/wp-custom-post-type-class/blob/master/LICENSE) * Maintained under the [Semantic Versioning Guide](http://semver.org) From e076de889a8528cefd07b0cabe1e8891deeb02fc Mon Sep 17 00:00:00 2001 From: Joe Grainger Date: Tue, 4 Feb 2014 10:42:42 +0000 Subject: [PATCH 3/5] allow taxonomies to be sorted with sortable method --- src/CPT.php | 101 +++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/src/CPT.php b/src/CPT.php index 7670da7..6b9f2b8 100644 --- a/src/CPT.php +++ b/src/CPT.php @@ -82,7 +82,7 @@ class CPT { used in add_taxonmy_filters() */ - public $filters; + public $filters; @@ -116,7 +116,7 @@ class CPT { /* @function __contructor(@post_type_name, @options) - + @param mixed $post_type_names The name(s) of the post type, accepts (post type name, slug, plural, singlualr) @param array $options User submitted options */ @@ -125,7 +125,7 @@ function __construct($post_type_names, $options = array()) { // check if post type names is string or array if(is_array($post_type_names)) { - + // add names to object $names = array( 'singular', @@ -144,7 +144,7 @@ function __construct($post_type_names, $options = array()) { // use the user setting $this->$name = $post_type_names[$name]; - + // else generate the name } else { @@ -153,9 +153,9 @@ function __construct($post_type_names, $options = array()) { // generate the name $this->$name = $this->$method(); - + } - + } // else the post type name is only supplied @@ -176,7 +176,7 @@ function __construct($post_type_names, $options = array()) { } // set the user submitted options to the object - $this->options = $options; + $this->options = $options; // register the post type $this->add_action('init', array(&$this, 'register_post_type')); @@ -246,7 +246,7 @@ function set($var, $value) { // write variable and value $this->$var = $value; - + } } @@ -263,7 +263,7 @@ function set($var, $value) { */ function options_merge($defaults, $options) { - + // set the new array as defaults $new_array = $defaults; @@ -272,7 +272,7 @@ function options_merge($defaults, $options) { // foreach new option to be added foreach($options as $key => $value) { - + // if isset in the defaults array if(isset($defaults[$key])) { @@ -310,7 +310,7 @@ function options_merge($defaults, $options) { /* helper function add_action used to create add_action wordpress filter - + see Wordpress Codex http://codex.wordpress.org/Function_Reference/add_action @@ -332,7 +332,7 @@ function add_action($action, $function, $priority = 10, $accepted_args = 1) { /* helper function add_filter used to create add_filter wordpress filter - + see Wordpress Codex http://codex.wordpress.org/Function_Reference/add_filter @@ -390,7 +390,7 @@ function get_slug($name = null) { ucwords capitalize words strtolower makes string lowercase before capitalizing str_replace replace all instances of _ to space - + @param string $name the slug name you want to pluralize @return string the friendly pluralized name */ @@ -401,7 +401,7 @@ function get_plural($name = null) { if(!isset($name)) { $name = $this->post_type_name; - + } // return the plural name @@ -418,7 +418,7 @@ function get_plural($name = null) { ucwords capitalize words strtolower makes string lowercase before capitalizing str_replace replace all instances of _ to space - + @param string $name the slug name you want to unpluralize @return string the friendly singular name */ @@ -429,7 +429,7 @@ function get_singular($name = null) { if(!isset($name)) { $name = $this->post_type_name; - + } // return the string @@ -446,7 +446,7 @@ function get_singular($name = null) { ucwords capitalize words strtolower makes string lowercase before capitalizing str_replace replace all instances of hyphens and underscores to spaces - + @param string $name the name you want to make friendly @return string the human friendly name */ @@ -476,7 +476,7 @@ function get_human_friendly($name = null) { */ function register_post_type() { - + // friendly post type names $plural = $this->plural; $singular = $this->singular; @@ -496,7 +496,7 @@ function register_post_type() { 'search_items' => __('Search ' . $plural), 'not_found' => __('No ' . $plural . ' found'), 'not_found_in_trash' => __('No ' . $plural . ' found in Trash'), - 'parent_item_colon' => __('Parent ' . $singular . ':') + 'parent_item_colon' => __('Parent ' . $singular . ':') ); // default options @@ -535,7 +535,7 @@ function register_taxonomy @param string $taxonomy_name the slug for the taxonomy @param array $options taxonomy options - + see Wordpress codex http://codex.wordpress.org/Function_Reference/register_taxonomy */ @@ -544,7 +544,7 @@ function register_taxonomy($taxonomy_names, $options = array()) { // post type defaults to $this post type if unspecified $post_type = $this->post_type_name; - + // an array of the names required excluding taxonomy_name $names = array( 'singular', @@ -566,7 +566,7 @@ function register_taxonomy($taxonomy_names, $options = array()) { // use user submitted name $$name = $taxonomy_names[$name]; - + // else generate the name } else { @@ -582,13 +582,13 @@ function register_taxonomy($taxonomy_names, $options = array()) { // else if only the taxonomy_name has been supplied } else { - + // create user friendly names $taxonomy_name = $taxonomy_names; $singular = $this->get_singular($taxonomy_name); $plural = $this->get_plural($taxonomy_name); $slug = $this->get_slug($taxonomy_name); - + } // default labels @@ -597,14 +597,14 @@ function register_taxonomy($taxonomy_names, $options = array()) { 'singular_name' => _($singular), 'menu_name' => __($plural), 'all_items' => __('All ' . $plural), - 'edit_item' => __('Edit ' . $singular), + 'edit_item' => __('Edit ' . $singular), 'view_item' => __('View ' . $singular), 'update_item' => __('Update ' . $singular), 'add_new_item' => __('Add New ' . $singular), 'new_item_name' => __('New ' . $singular . ' Name'), 'parent_item' => __('Parent ' . $plural), 'parent_item_colon' => __('Parent ' . $plural .':'), - 'search_items' => __('Search ' . $plural), + 'search_items' => __('Search ' . $plural), 'popular_items' => __('Popular ' . $plural), 'separate_items_with_commas' => __('Seperate ' . $plural . ' with commas'), 'add_or_remove_items' => __('Add or remove ' . $plural), @@ -632,7 +632,7 @@ function register_taxonomy($taxonomy_names, $options = array()) { register_taxonomy($taxonomy_name, $post_type, $options); }); - + } else { // if taxonomy exists, attach exisiting taxonomy to post type @@ -651,7 +651,7 @@ function register_taxonomy($taxonomy_names, $options = array()) { // populate the taxonomy columns with the posts terms $this->add_action('manage_' . $post_type . '_posts_custom_column', array(&$this, 'populate_admin_columns'), 10, 2); - + // add filter select option to admin edit $this->add_action('restrict_manage_posts', array(&$this, 'add_taxonomy_filters')); @@ -662,7 +662,7 @@ function register_taxonomy($taxonomy_names, $options = array()) { /* function add_admin_columns adds columns to the admin edit screen - + function is used with add_action */ @@ -721,7 +721,7 @@ function add_admin_columns($columns) { /* function populate_admin_columns populates custom columns on the admin edit screen - + function is used with add_action */ @@ -781,10 +781,10 @@ function populate_admin_columns($column, $post_id) { break; // if column is for the post ID - case 'post_id' : + case 'post_id' : echo $post->ID; - + break; // if the column is prepended with 'meta_' @@ -801,7 +801,7 @@ function populate_admin_columns($column, $post_id) { break; // if the column is post thumbnail - case 'icon' : + case 'icon' : // create the edit link $link = esc_url(add_query_arg(array('post' => $post->ID, 'action' => 'edit'), 'post.php')); @@ -818,14 +818,14 @@ function populate_admin_columns($column, $post_id) { // display default media image with link echo ''. $post->post_title .''; - + } break; // default case checks if the column has a user function // this is most commonly used for custom fields - default : + default : // if there are user custom columns to populate if(isset($this->custom_populate_columns) && is_array($this->custom_populate_columns)) { @@ -838,7 +838,7 @@ function populate_admin_columns($column, $post_id) { } - } + } break; @@ -851,7 +851,7 @@ function populate_admin_columns($column, $post_id) { /* function filters user function to define which taxonomy filters to display on the admin page - + @param array $filters an array of taxonomy filters to display */ @@ -868,7 +868,7 @@ function filters($filters = array()) { /* function add_taxtonomy_filters creates select fields for filtering posts by taxonomies on admin edit screen - + */ function add_taxonomy_filters() { @@ -917,7 +917,7 @@ function add_taxonomy_filters() { // foreach term create an option field foreach ($terms as $term) { - + // if filtered by this term make it selected if(isset($_GET[$tax_slug]) && $_GET[$tax_slug] === $term->slug) { @@ -948,7 +948,7 @@ function add_taxonomy_filters() { /* function columns user function to choose columns to be displayed on the admin edit screen - + @param array $columns an array of columns to be displayed */ @@ -960,7 +960,7 @@ function columns($columns) { // assign user submitted columns to object $this->columns = $columns; - + } } @@ -991,7 +991,7 @@ function sortable */ function sortable($columns = array()) { - + // assign user defined sortable columns to object variable $this->sortable = $columns; @@ -1064,6 +1064,19 @@ function sort_columns($vars) { // retrieve the meta key from the user submitted array of sortable columns $meta_key = $values[0]; + // if the meta_key is a taxonomy + if(taxonomy_exists($meta_key)) { + + // sort by taxonomy + $key = "taxonomy"; + + } else { + + // else by meta key + $key = "meta_key"; + + } + // if the optional parameter is set and is set to true if(isset($values[1]) && true === $values[1]) { @@ -1112,14 +1125,14 @@ function menu icon function menu_icon($icon = "dashicons-admin-page") { // WP 3.8 changed the icon system to use an icon font. - // http://melchoyce.github.io/dashicons/ + // http://melchoyce.github.io/dashicons/ if(is_string($icon) && stripos($icon, "dashicons") !== FALSE) { $this->options["menu_icon"] = $icon; } else { - // set a default + // set a default $this->options["menu_icon"] = "dashicons-admin-page"; } From 446d70caca25b6ee874f619e19c257c7bf9eeeeb Mon Sep 17 00:00:00 2001 From: Joe Grainger Date: Tue, 4 Feb 2014 10:52:15 +0000 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa35d5e..0b821c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +##### v1.2.0 +* allow taxonomies to be sorted with the `sortable()` method +* use of `.gitattributes` to make package lighter when deploying for production. + ##### v1.1.0 * make repository a composer package From 8b08d448d0e2ef803e43ee98af9b22d92eee25ca Mon Sep 17 00:00:00 2001 From: Joe Grainger Date: Tue, 4 Feb 2014 10:52:31 +0000 Subject: [PATCH 5/5] bump version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0f036c..eb6e8e7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WP Custom Post Type Class v1.1.0 +# WP Custom Post Type Class v1.2.0 A single class to help you build more advanced custom post types quickly.