Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Nov 28, 2015
2 parents 749ddc1 + b29c69e commit c508e0b
Show file tree
Hide file tree
Showing 13 changed files with 806 additions and 241 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig (http://editorconfig.org)

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Files generated by OS
.DS_Store
360 changes: 339 additions & 21 deletions LICENSE.txt
100755 → 100644

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Awesome CPT

*Copyright 2015 Caleb Evans*
*Licensed under the MIT license*
*Released under the GNU General Public License v2.0*

Awesome CPT is a set of classes designed to make coding WordPress custom post
types incredibly easy and flexible.
Expand Down
26 changes: 13 additions & 13 deletions awesome-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
* Description: The easiest and most flexible way to code custom post types in WordPress
* Author: Caleb Evans
* Author URI: http://calebevans.me/
* Version: 1.0.2
* License: MIT
* Version: 1.1.0
* License: GNU General Public License v2.0
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

// Define path to AwesomeCPT directory
if ( ! defined( 'AWESOME_CPT_DIR' ) ) {
define( 'AWESOME_CPT_DIR', dirname( __FILE__ ) );
}
// Define constant indicating the existence of AwesomeCPT
// The AWESOME_CPT constant indicates whether Awesome CPT has been loaded
if ( ! defined( 'AWESOME_CPT' ) ) {

define( 'AWESOME_CPT_DIR', dirname( __FILE__ ) );
define( 'AWESOME_CPT', true );
}

// Import AwesomeCPT classes
require_once AWESOME_CPT_DIR . '/classes/class-awesome-base-type.php';
require_once AWESOME_CPT_DIR . '/classes/class-awesome-post-type.php';
require_once AWESOME_CPT_DIR . '/classes/class-awesome-taxonomy.php';
require_once AWESOME_CPT_DIR . '/classes/class-awesome-meta-box.php';
// Import AwesomeCPT classes
require_once AWESOME_CPT_DIR . '/classes/class-awesome-base-type.php';
require_once AWESOME_CPT_DIR . '/classes/class-awesome-post-type.php';
require_once AWESOME_CPT_DIR . '/classes/class-awesome-taxonomy.php';
require_once AWESOME_CPT_DIR . '/classes/class-awesome-meta-box.php';

}
54 changes: 39 additions & 15 deletions classes/class-awesome-base-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,87 @@
// Base class for post types, taxonomies, and meta boxes
abstract class Awesome_Base_Type {

// Base constructor for CPTs and taxonomies
// The base constructor is only called for post types and taxonomies
public function __construct( $params, $arg_defaults ) {

$this->merge_params( $params );

// Merge argument defaults into arguments array
if ( empty( $this->args ) ) {
$this->args = $arg_defaults;
} else {
$this->args = array_merge( $arg_defaults, $this->args );
}

$this->add_names();
$default_labels = $this->create_labels();
// If labels were passed in parameters

if ( ! empty( $this->args['labels'] ) ) {
// Merge labels with defaults
// Merge labels with defaults if custom labels were supplied
$this->args['labels'] = array_merge( $default_labels, $this->args['labels'] );
} else {
// Otherwise, use default labels
$this->args['labels'] = $default_labels;
}
// If contextual help function is given
if ( ! empty( $this->contextual_help ) ) {
// Add contextual help to type
add_action( 'contextual_help', array( $this, 'contextual_help' ), 10, 3 );

// Add contextual help menus to page if provided
if ( ! empty( $this->help_menus ) ) {
add_action( 'admin_head', array( $this, 'add_help_menu', ), 10 );
}

}

// Add contextual help for type
public function contextual_help( $contextual_help, $screen_id, $screen ) {
// If contextual help callback was given
if ( $this->contextual_help ) {
// Call function
call_user_func_array( $this->contextual_help, array( $contextual_help, $screen_id, $screen ) );
// Adds the contextual help menu assigned to the current screen
public function add_help_menu() {

$screen = get_current_screen();

foreach ( $this->help_menus as $help_menu ) {

if ( $screen->id === $help_menu['screen'] ) {

foreach ( $help_menu['tabs'] as $tab ) {
$screen->add_help_tab( $tab );
}

if ( ! empty( $help_menu['sidebar'] ) ) {
$screen->set_help_sidebar( $help_menu['sidebar'] );
}

}

}

}

// Merge params into class instance
// Merges params into class instance
public function merge_params( $params ) {

foreach ( $params as $param_name => $param_value ) {
$this->$param_name = $param_value;
}

}

// Compute other name variants for the type
// Computes other name variants for the type
public function add_names() {

// Construct title from the given name
if ( empty( $this->title ) ) {
$this->title = array(
'singular' => ucwords( $this->name['singular'] ),
'plural' => ucwords( $this->name['plural'] ),
);
}

// Construct capitalized name from the given name
if ( empty( $this->cap_name ) ) {
$this->cap_name = array(
'singular' => ucfirst( $this->name['singular'] ),
'plural' => ucfirst( $this->name['plural'] ),
);
}

}

}
Loading

0 comments on commit c508e0b

Please sign in to comment.