/** * Construct a new Cuztom Post Type * * @param string|array $name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.1 * */ function __construct($name, $args = array(), $labels = array()) { if (!empty($name)) { // If $name is an array, the first element is the singular name, the second is the plural name if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->args = $args; $this->labels = $labels; $this->add_features = $this->remove_features = array(); // Add to array for uninstall global $nm_uninstall; $nm_uninstall['post_types'][] = $this->name; // Add action to register the post type, if the post type doesnt exist if (!post_type_exists($this->name)) { add_action('init', array(&$this, 'register_post_type')); } } }
/** * Constructs the class with important vars and method calls * If the taxonomy exists, it will be attached to the post type * * @param string $name * @param string $post_type_name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.2 * */ function __construct($name, $post_type_name = null, $args = array(), $labels = array(), $hierarchical) { if (!empty($name)) { $this->post_type_name = $post_type_name; $this->hierarchical = $hierarchical; if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->labels = $labels; $this->args = $args; if ($is_reserved_term = Cuztom::is_reserved_term($this->name)) { echo '<div id="message" class="error"><p>' . $is_reserved_term->get_error_message() . ': <strong>' . $this->name . '</strong></p></div>'; } else { if (!taxonomy_exists($this->name)) { add_action('init', array(&$this, 'register_taxonomy')); } else { add_action('init', array(&$this, 'register_taxonomy_for_object_type')); } if (isset($args['show_column']) && $args['show_column']) { add_filter('manage_' . $this->post_type_name . '_posts_columns', array(&$this, 'add_column')); add_action('manage_' . $this->post_type_name . '_posts_custom_column', array(&$this, 'add_column_content'), 10, 2); add_action('manage_edit-' . $this->post_type_name . '_sortable_columns', array(&$this, 'add_sortable_column'), 10, 2); add_action('restrict_manage_posts', array(&$this, '_post_filter')); add_filter('parse_query', array(&$this, '_post_filter_query')); } } } }
/** * Registers the custom taxonomy with the given arguments * * @author Gijs Jorissen * @since 0.2 * */ function register_taxonomy() { $name = Cuztom::beautify($this->taxonomy_name); $plural = Cuztom::pluralize($name); // Default labels, overwrite them with the given labels. $labels = array_merge(array('name' => _x($plural, 'taxonomy general name', CUZTOM_TEXTDOMAIN), 'singular_name' => _x($name, 'taxonomy singular name', CUZTOM_TEXTDOMAIN), 'search_items' => __('Search ' . $plural, CUZTOM_TEXTDOMAIN), 'all_items' => __('All ' . $plural, CUZTOM_TEXTDOMAIN), 'parent_item' => __('Parent ' . $name, CUZTOM_TEXTDOMAIN), 'parent_item_colon' => __('Parent ' . $name . ':', CUZTOM_TEXTDOMAIN), 'edit_item' => __('Edit ' . $name, CUZTOM_TEXTDOMAIN), 'update_item' => __('Update ' . $name, CUZTOM_TEXTDOMAIN), 'add_new_item' => __('Add New ' . $name, CUZTOM_TEXTDOMAIN), 'new_item_name' => __('New ' . $name . ' Name', CUZTOM_TEXTDOMAIN), 'menu_name' => __($name, CUZTOM_TEXTDOMAIN)), $this->taxonomy_labels); // Default arguments, overwitten with the given arguments $args = array_merge(array('label' => $plural, 'labels' => $labels, "hierarchical" => true, 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, '_builtin' => false), $this->taxonomy_args); register_taxonomy($this->taxonomy_name, $this->post_type_name, $args); }
/** * Register the Post Type * * @author Gijs Jorissen * @since 0.1 * */ function register_post_type() { // Capitilize the words and make it plural $name = Cuztom::beautify($this->post_type_name); $plural = Cuztom::pluralize($name); // We set the default labels based on the post type name and plural. // We overwrite them with the given labels. $labels = array_merge(array('name' => _x($plural, 'post type general name', CUZTOM_TEXTDOMAIN), 'singular_name' => _x($name, 'post type singular name', CUZTOM_TEXTDOMAIN), 'add_new' => _x('Add New', strtolower($name), CUZTOM_TEXTDOMAIN), 'add_new_item' => __('Add New ' . $name, CUZTOM_TEXTDOMAIN), 'edit_item' => __('Edit ' . $name, CUZTOM_TEXTDOMAIN), 'new_item' => __('New ' . $name, CUZTOM_TEXTDOMAIN), 'all_items' => __('All ' . $plural, CUZTOM_TEXTDOMAIN), 'view_item' => __('View ' . $name, CUZTOM_TEXTDOMAIN), 'search_items' => __('Search ' . $plural, CUZTOM_TEXTDOMAIN), 'not_found' => __('No ' . strtolower($plural) . ' found', CUZTOM_TEXTDOMAIN), 'not_found_in_trash' => __('No ' . strtolower($plural) . ' found in Trash', CUZTOM_TEXTDOMAIN), 'parent_item_colon' => '', 'menu_name' => $plural), $this->post_type_labels); // Same principle as the labels. We set some default and overwite them with the given arguments. $args = array_merge(array('label' => $plural, 'labels' => $labels, 'public' => true, 'supports' => array('title', 'editor')), $this->post_type_args); // Register the post type register_post_type($this->post_type_name, $args); }
/** * Construct a new Cuztom Post Type * * @param string|array $name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.1 * */ function __construct($name, $args = array(), $labels = array()) { if (!empty($name)) { // If $name is an array, the first element is the singular name, the second is the plural name if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->args = $args; $this->labels = $labels; $this->add_features = $this->remove_features = array(); add_action('init', array($this, 'register_post_type')); } }
/** * Constructs the class with important vars and method calls * If the taxonomy exists, it will be attached to the post type * * @param string $name * @param string $post_type * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.2 * */ function __construct($name, $post_type = null, $args = array(), $labels = array()) { if (!empty($name)) { $this->post_type = $post_type; if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->labels = $labels; $this->args = $args; // Add to array for uninstall global $nm_uninstall; $nm_uninstall['taxonomies'][] = $this->name; if (!taxonomy_exists($this->name)) { if ($is_reserved_term = Cuztom::is_reserved_term($this->name)) { new Cuztom_Notice($is_reserved_term->get_error_message(), 'error'); } else { add_action('init', array(&$this, 'register_taxonomy')); } } else { add_action('init', array(&$this, 'register_taxonomy_for_object_type')); } if (isset($args['show_admin_column']) && $args['show_admin_column']) { if (get_bloginfo('version') < '3.5') { add_filter('manage_' . $this->post_type . '_posts_columns', array(&$this, 'add_column')); add_action('manage_' . $this->post_type . '_posts_custom_column', array(&$this, 'add_column_content'), 10, 2); } if (isset($args['admin_column_sortable']) && $args['admin_column_sortable']) { add_action('manage_edit-' . $this->post_type . '_sortable_columns', array(&$this, 'add_sortable_column'), 10, 2); } if (isset($args['admin_column_filter']) && $args['admin_column_filter']) { add_action('restrict_manage_posts', array(&$this, '_post_filter')); add_filter('parse_query', array(&$this, '_post_filter_query')); } } } }
/** * Constructs the class with important vars and method calls * If the taxonomy exists, it will be attached to the post type * * @param string $name * @param string $post_type_name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.2 * */ function __construct($name, $post_type_name = null, $args = array(), $labels = array()) { if (!empty($name)) { $this->post_type_name = $post_type_name; if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->labels = $labels; $this->args = $args; if (!taxonomy_exists($this->name)) { add_action('init', array(&$this, 'register_taxonomy')); } else { add_action('init', array(&$this, 'register_taxonomy_for_object_type')); } } }