From ba8105278eaf021bf84955a6fdb92b4fe3059367 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 21 Dec 2015 15:37:50 -0500 Subject: [PATCH] Updates for the plugin Mainly adding some basic function comment for docs. Adding defines --- index.php | 279 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 202 insertions(+), 77 deletions(-) diff --git a/index.php b/index.php index cec3482..016136b 100644 --- a/index.php +++ b/index.php @@ -9,49 +9,69 @@ * License: GPLv2 */ +define( 'MICHSCI_POST_TYPE', 'miproduct' ); +define( 'MICHSCI_PRODUCT_SINGLE', 'Product' ); +define( 'MICHSCI_PRODUCT_PLURAL', 'Products' ); +define( 'MICHSCI_CATEGORY_NAME', 'michsci_category' ); +define( 'MICHSCI_CATEGORY_SLUG', 'michsci-category' ); +define( 'MICHSCI_CATEGORY_SINGLE', 'Category'); +define( 'MICHSCI_CATEGORY_PLURAL', 'Categories'); +define( 'MICHSCI_TAG_NAME', 'michsci_tag' ); +define( 'MICHSCI_TAG_SLUG', 'michsci-tag' ); +define( 'MICHSCI_TAG_SINGLE', 'Tag' ); +define( 'MICHSCI_TAG_PLURAL', 'Tags' ); + // Register Custom Post Type +/** + * michsci_custom_post_type + * + * Setup of the Wordpress Custom Post Type + * + * @access public + * @return void + */ function michsci_custom_post_type() { $labels = array( - 'name' => _x( 'Products', 'Post Type General Name', 'michsci' ), - 'singular_name' => _x( 'Product', 'Post Type Singular Name', 'michsci' ), - 'menu_name' => __( 'Products', 'michsci' ), - 'name_admin_bar' => __( 'Products', 'michsci' ), - 'archives' => __( 'Product Archives', 'michsci' ), - 'parent_item_colon' => __( 'Parent Item:', 'michsci' ), - 'all_items' => __( 'All Items', 'michsci' ), - 'add_new_item' => __( 'Add New Item', 'michsci' ), - 'add_new' => __( 'Add New', 'michsci' ), - 'new_item' => __( 'New Item', 'michsci' ), - 'edit_item' => __( 'Edit Item', 'michsci' ), - 'update_item' => __( 'Update Item', 'michsci' ), - 'view_item' => __( 'View Item', 'michsci' ), - 'search_items' => __( 'Search Item', 'michsci' ), - 'not_found' => __( 'Not found', 'michsci' ), - 'not_found_in_trash' => __( 'Not found in Trash', 'michsci' ), - 'featured_image' => __( 'Featured Image', 'michsci' ), - 'set_featured_image' => __( 'Set featured image', 'michsci' ), - 'remove_featured_image' => __( 'Remove featured image', 'michsci' ), - 'use_featured_image' => __( 'Use as featured image', 'michsci' ), - 'insert_into_item' => __( 'Insert into item', 'michsci' ), - 'uploaded_to_this_item' => __( 'Uploaded to this item', 'michsci' ), - 'items_list' => __( 'Items list', 'michsci' ), - 'items_list_navigation' => __( 'Items list navigation', 'michsci' ), - 'filter_items_list' => __( 'Filter items list', 'michsci' ), + 'name' => _x( MICHSCI_PRODUCT_PLURAL, 'Post Type General Name' ), + 'singular_name' => _x( MICHSCI_PRODUCT_SINGLE, 'Post Type Singular Name' ), + 'menu_name' => __( MICHSCI_PRODUCT_PLURAL ), + 'name_admin_bar' => __( MICHSCI_PRODUCT_PLURAL ), + 'archives' => __( MICHSCI_PRODUCT_SINGLE . ' Archives' ), + 'parent_item_colon' => __( 'Parent Item:' ), + 'all_items' => __( 'All Items' ), + 'add_new_item' => __( 'Add New Item' ), + 'add_new' => __( 'Add New' ), + 'new_item' => __( 'New Item' ), + 'edit_item' => __( 'Edit Item' ), + 'update_item' => __( 'Update Item' ), + 'view_item' => __( 'View Item' ), + 'search_items' => __( 'Search Item' ), + 'not_found' => __( 'Not found' ), + 'not_found_in_trash' => __( 'Not found in Trash' ), + 'featured_image' => __( 'Featured Image' ), + 'set_featured_image' => __( 'Set featured image' ), + 'remove_featured_image' => __( 'Remove featured image' ), + 'use_featured_image' => __( 'Use as featured image' ), + 'insert_into_item' => __( 'Insert into item' ), + 'uploaded_to_this_item' => __( 'Uploaded to this item' ), + 'items_list' => __( 'Items list' ), + 'items_list_navigation' => __( 'Items list navigation' ), + 'filter_items_list' => __( 'Filter items list' ), ); $rewrite = array( - 'slug' => 'miproduct', + 'slug' => MICHSCI_POST_TYPE, 'with_front' => false, 'pages' => false, 'feeds' => false, ); $args = array( - 'label' => __( 'Product', 'michsci' ), - 'description' => __( 'Custom Products', 'michsci' ), + 'label' => __( MICHSCI_PRODUCT_SINGLE ), + 'description' => __( 'Custom ' . MICHSCI_PRODUCT_PLURAL ), 'labels' => $labels, - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ), + 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, @@ -68,27 +88,36 @@ function michsci_custom_post_type() { 'capability_type' => 'page' ); - register_post_type( 'miproduct', $args ); - register_taxonomy_for_object_type( 'michsci_category', 'miproduct' ); + register_post_type( MICHSCI_POST_TYPE, $args ); + register_taxonomy_for_object_type( MICHSCI_CATEGORY_NAME, MICHSCI_POST_TYPE ); + register_taxonomy_for_object_type( MICHSCI_TAG_NAME, MICHSCI_POST_TYPE ); } +/** + * michsci_taxonomies + * + * Setup of the Taxonomies for the post type + * + * @access public + * @return void + */ function michsci_taxonomies() { - // Product Categories + // Categories $labels = array( - 'name' => _x( 'Category', 'taxonomy general name'), - 'singular_name' => _x( 'Category', 'taxonomy singular name'), - 'search_items' => __( 'Search Categories'), - 'all_items' => __( 'All Categories'), - 'parent_item' => __( 'Parent Category'), - 'parent_item_colon' => __( 'Parent Category'), - 'edit_item' => __( 'Edit Category'), - 'update_item' => __( 'Update Category'), - 'add_new_item' => __( 'Add New Category'), - 'new_item_name' => __( 'New Category Name'), - 'menu_name' => __( 'Product Category'), + 'name' => _x( MICHSCI_CATEGORY_NAME, 'taxonomy general name'), + 'singular_name' => _x( MICHSCI_CATEGORY_NAME, 'taxonomy singular name'), + 'search_items' => __( 'Search ' . MICHSCI_CATEGORY_PLURAL), + 'all_items' => __( 'All ' . MICHSCI_CATEGORY_PLURAL), + 'parent_item' => __( 'Parent ' . MICHSCI_CATEGORY_SINGLE), + 'parent_item_colon' => __( 'Parent ' . MICHSCI_CATEGORY_SINGLE), + 'edit_item' => __( 'Edit ' . MICHSCI_CATEGORY_SINGLE), + 'update_item' => __( 'Update ' . MICHSCI_CATEGORY_SINGLE), + 'add_new_item' => __( 'Add New ' . MICHSCI_CATEGORY_SINGLE), + 'new_item_name' => __( 'New ' . MICHSCI_CATEGORY_SINGLE . ' Name'), + 'menu_name' => __( 'Product ' . MICHSCI_CATEGORY_SINGLE ), ); $capabilities = array( @@ -99,8 +128,8 @@ function michsci_taxonomies() ); $args = array( - 'label' => __('Categories'), - 'rewrite' => array( 'slug' => 'mitag' ), + 'label' => __(MICHSCI_CATEGORY_PLURAL), + 'rewrite' => array( 'slug' => MICHSCI_CATEGORY_SLUG ), 'capabilities' => $capabilities, 'public ' => true, 'show_in_quick_edit' => true, @@ -109,24 +138,24 @@ function michsci_taxonomies() ); register_taxonomy( - 'michsci_category', - 'miproduct', + MICHSCI_CATEGORY_NAME, + MICHSCI_POST_TYPE, $args ); - // Product Tags + // Tags $labels = array( - 'name' => _x( 'Tag', 'taxonomy general name'), - 'singular_name' => _x( 'Tag', 'taxonomy singular name'), - 'search_items' => __( 'Search Tags'), - 'all_items' => __( 'All Tags'), - 'parent_item' => __( 'Parent Tag'), - 'parent_item_colon' => __( 'Parent Tag'), - 'edit_item' => __( 'Edit Tag'), - 'update_item' => __( 'Update Tag'), - 'add_new_item' => __( 'Add New Tag'), - 'new_item_name' => __( 'New Tag Name'), - 'menu_name' => __( 'Product Tag'), + 'name' => _x( MICHSCI_TAG_SINGLE, 'taxonomy general name'), + 'singular_name' => _x( MICHSCI_TAG_SINGLE, 'taxonomy singular name'), + 'search_items' => __( 'Search ' . MICHSCI_TAG_PLURAL), + 'all_items' => __( 'All ' . MICHSCI_TAG_PLURAL), + 'parent_item' => __( 'Parent ' . MICHSCI_TAG_SINGLE), + 'parent_item_colon' => __( 'Parent ' . MICHSCI_TAG_SINGLE), + 'edit_item' => __( 'Edit ' . MICHSCI_TAG_SINGLE), + 'update_item' => __( 'Update ' . MICHSCI_TAG_SINGLE), + 'add_new_item' => __( 'Add New ' . MICHSCI_TAG_SINGLE), + 'new_item_name' => __( 'New ' . MICHSCI_TAG_SINGLE . ' Name'), + 'menu_name' => __( 'Product ' . MICHSCI_TAG_SINGLE), ); $capabilities = array( @@ -137,8 +166,8 @@ function michsci_taxonomies() ); $args = array( - 'label' => __('Tags'), - 'rewrite' => array( 'slug' => 'mitag' ), + 'label' => __(MICHSCI_TAG_PLURAL), + 'rewrite' => array( 'slug' => MICHSCI_TAG_SLUG ), 'capabilities' => $capabilities, 'public ' => true, 'show_in_quick_edit' => true, @@ -147,12 +176,20 @@ function michsci_taxonomies() ); register_taxonomy( - 'michsci_tag', - 'miproduct', + MICHSCI_TAG_NAME, + MICHSCI_POST_TYPE, $args ); } +/** + * michsci_taxonomy_filter_restrict_manage_posts + * + * This will setup the Filter for the Custom taxonomies. + * + * @access public + * @return void + */ function michsci_taxonomy_filter_restrict_manage_posts() { global $typenow; @@ -180,6 +217,15 @@ function michsci_taxonomy_filter_restrict_manage_posts() add_action( 'restrict_manage_posts', 'michsci_taxonomy_filter_restrict_manage_posts' ); +/** + * michsci_taxonomy_filter_post_type_request + * + * Filter the post request for the Taxonomy Filter + * + * @param mixed $query + * @access public + * @return void + */ function michsci_taxonomy_filter_post_type_request( $query ) { global $pagenow, $typenow; @@ -204,6 +250,14 @@ add_filter( 'parse_query', 'michsci_taxonomy_filter_post_type_request' ); add_action( 'init', 'michsci_taxonomies' ); add_action( 'init', 'michsci_custom_post_type' ); +/** + * michsci_set_admin_columns + * + * Setup of the list columns + * + * @access public + * @return void + */ function michsci_set_admin_columns() { add_filter( 'manage_edit-miproduct_columns', 'michsci_admin_edit_columns' ); @@ -212,17 +266,35 @@ function michsci_set_admin_columns() add_action( 'admin_init', 'michsci_set_admin_columns' ); +/** + * michsci_admin_edit_columns + * + * Setup of the edit columns. This will create the headers for each column. + * + * @param mixed $columns + * @access public + * @return void + */ function michsci_admin_edit_columns($columns) { $columns = array( 'cb' => '', - 'title' => 'Product Title', - 'michproduct_col_cat' => 'Category', - 'michproduct_col_tag' => 'Tag' + 'title' => MICHSCI_PRODUCT_SINGLE . ' Title', + 'michproduct_col_cat' => MICHSCI_CATEGORY_SINGLE, + 'michproduct_col_tag' => MICHSCI_TAG_SINGLE ); return $columns; } +/** + * michsci_admin_custom_columns + * + * This will generate the column data for eaoch record. + * + * @param mixed $column + * @access public + * @return void + */ function michsci_admin_custom_columns($column) { global $post; @@ -255,6 +327,16 @@ function michsci_admin_custom_columns($column) } } +/** + * michsci_shortcode + * + * Add shortcode function. This will call the correct function based on the + * front end search. + * + * @param mixed $atts + * @access public + * @return void + */ function michsci_shortcode($atts) { extract( shortcode_atts( array( 'limit' => '10' ), $atts ) ); @@ -280,11 +362,19 @@ function michsci_shortcode($atts) return $output; } +/** + * michsci_get_terms_dropdown + * + * Generate the taxonomy drop down select + * + * @access public + * @return void + */ function michsci_get_terms_dropdown() { - $taxonomyName = "michsci_category"; + $taxonomyName = MICHSCI_CATEGORY_NAME; $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'name', 'hide_empty' => false)); - $output =""; // get parent categories foreach ($parent_terms as $parent){ @@ -292,20 +382,20 @@ function michsci_get_terms_dropdown() // get children of each category $child_terms = get_terms($taxonomyName, array('child_of' => $parent->term_id, 'orderby' => 'name', 'hide_empty' => false)); $output .= ''; foreach($child_terms as $child){ $grandchildren = get_terms($taxonomyName, array('child_of' => $child->term_id, 'orderby' => 'name', 'hide_empty' => false)); $output .= ''; // foreach($grandchildren as $grandchild){ // $output .= ''; @@ -317,6 +407,14 @@ function michsci_get_terms_dropdown() } +/** + * michsci_list_products + * + * Create a list of products. + * + * @access public + * @return void + */ function michsci_list_products() { global $wpdb, $wp; @@ -325,8 +423,8 @@ function michsci_list_products() 'post_type' => 'miproduct' ); - $misch_category = ( isset( $_REQUEST['michsci_category'] ) ) - ? filter_var( $_REQUEST['michsci_category'] ) + $misch_category = ( isset( $_REQUEST[MICHSCI_CATEGORY_NAME] ) ) + ? filter_var( $_REQUEST[MICHSCI_CATEGORY_NAME] ) : false; if ($misch_category) { @@ -334,7 +432,7 @@ function michsci_list_products() 'relation' => 'AND' ); $args['tax_query'][] = array( - 'taxonomy' => 'michsci_category', + 'taxonomy' => MICHSCI_CATEGORY_NAME, 'field' => 'id', 'terms' => $misch_category ); @@ -346,7 +444,7 @@ function michsci_list_products() $iterator = 1; foreach ( $products as $product ) { - $productTerms = wp_get_post_terms( $product->ID, 'michsci_category', 'name' ); + $productTerms = wp_get_post_terms( $product->ID, MICHSCI_CATEGORY_NAME, 'name' ); $pTerm = $productTerms[0]; $product->term = $pTerm->name; $product->end = false; @@ -362,11 +460,20 @@ function michsci_list_products() include 'views/list_products.php'; return; } +/** + * michsci_list_categories + * + * Create a list of categories. + * + * @param bool $cat_id + * @access public + * @return void + */ function michsci_list_categories( $cat_id = null ) { global $wpdb, $wp; - $taxonomy = 'michsci_category'; + $taxonomy = MICHSCI_CATEGORY_NAME; $args = array( 'hide_empty' => true, 'pad_counts' => true @@ -398,6 +505,15 @@ function michsci_list_categories( $cat_id = null ) return; } +/** + * michsci_show_product + * + * Create a product detail page. + * + * @param mixed $prod_id + * @access public + * @return void + */ function michsci_show_product($prod_id) { global $wpdb, $wp; @@ -405,11 +521,20 @@ function michsci_show_product($prod_id) include 'views/product_detail.php'; return; } +/** + * michsci_show_category + * + * Create a product detail page. + * + * @param mixed $cat_id + * @access public + * @return void + */ function michsci_show_category($cat_id) { global $wpdb, $wp; $term = get_terms( - 'michsci_category', + MICHSCI_CATEGORY_NAME, array( 'child_of' => $cat_id, 'hide_empty' => true, -- 2.17.1