From: Steve Sutton Date: Tue, 21 Jun 2016 14:15:25 +0000 (-0400) Subject: phpcbf X-Git-Tag: v0.0.1~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=a1f936bd96683f7c3f911e39d593d1d7c0287e63;p=WP-Plugins%2Ffrance-tours.git phpcbf --- diff --git a/index.php b/index.php index 3a79d1c..e7afa2b 100644 --- a/index.php +++ b/index.php @@ -14,8 +14,8 @@ 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_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' ); @@ -32,66 +32,66 @@ define( 'MICHSCI_TAG_PLURAL', 'Tags' ); */ function michsci_custom_post_type() { - $labels = array( - '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' => MICHSCI_POST_TYPE, - 'with_front' => false, - 'pages' => false, - 'feeds' => false, - ); - - $args = array( - 'label' => __( MICHSCI_PRODUCT_SINGLE ), - 'description' => __( 'Custom ' . MICHSCI_PRODUCT_PLURAL ), - 'labels' => $labels, - 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ), - 'hierarchical' => true, - 'public' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_position' => 5, - 'menu_icon' => 'dashicons-lightbulb', - 'show_in_admin_bar' => true, - 'show_in_nav_menus' => true, - 'can_export' => true, - 'has_archive' => true, - 'exclude_from_search' => false, - 'publicly_queryable' => true, - 'rewrite' => $rewrite, - 'capability_type' => 'page', - 'register_meta_box_cb' => 'michsci_add_metaboxes' - ); - - 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 ); + $labels = array( + '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' => MICHSCI_POST_TYPE, + 'with_front' => false, + 'pages' => false, + 'feeds' => false, + ); + + $args = array( + 'label' => __( MICHSCI_PRODUCT_SINGLE ), + 'description' => __( 'Custom ' . MICHSCI_PRODUCT_PLURAL ), + 'labels' => $labels, + 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ), + 'hierarchical' => true, + 'public' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 5, + 'menu_icon' => 'dashicons-lightbulb', + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => true, + 'can_export' => true, + 'has_archive' => true, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'rewrite' => $rewrite, + 'capability_type' => 'page', + 'register_meta_box_cb' => 'michsci_add_metaboxes', + ); + + 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 ); } @@ -103,10 +103,9 @@ function michsci_custom_post_type() { * @access public * @return void */ -function michsci_add_metaboxes() -{ - add_meta_box('miproduct_features', 'Features', 'miproduct_features', MICHSCI_POST_TYPE, 'normal', 'high'); - add_meta_box('miproduct_related_products', 'Related Files', 'miproduct_related_products', MICHSCI_POST_TYPE, 'normal', 'high'); +function michsci_add_metaboxes() { + add_meta_box( 'miproduct_features', 'Features', 'miproduct_features', MICHSCI_POST_TYPE, 'normal', 'high' ); + add_meta_box( 'miproduct_related_products', 'Related Files', 'miproduct_related_products', MICHSCI_POST_TYPE, 'normal', 'high' ); } /** @@ -117,22 +116,21 @@ function michsci_add_metaboxes() * @access public * @return void */ -function miproduct_features() -{ - global $post; - - // get the features for the post - $features = get_post_meta( $post->ID, 'miproduct_features', true ); - // output field - wp_editor( $features, 'features', array( - 'wpautop' => true, - 'media_buttons' => false, - 'textarea_name' => 'miproduct_features', - 'teeny' => false, - 'editor_height' => 300, - 'quicktags' => false, - 'tinymce' => true - ) ); +function miproduct_features() { + global $post; + + // get the features for the post + $features = get_post_meta( $post->ID, 'miproduct_features', true ); + // output field + wp_editor( $features, 'features', array( + 'wpautop' => true, + 'media_buttons' => false, + 'textarea_name' => 'miproduct_features', + 'teeny' => false, + 'editor_height' => 300, + 'quicktags' => false, + 'tinymce' => true, + ) ); } /** @@ -143,25 +141,24 @@ function miproduct_features() * @access public * @return void */ -function miproduct_related_products() -{ - global $post; - - // Noncename needed to verify where the data originated - $nonce = wp_create_nonce( 'miproductmeta-meta-noncename' ); - echo ''; - // get the features for the post - $related_products = get_post_meta( $post->ID, 'miproduct_related_products', true ); - // output field - wp_editor( $related_products, 'related_products', array( - 'wpautop' => true, - 'media_buttons' => false, - 'textarea_name' => 'miproduct_related_products', - 'teeny' => false, - 'editor_height' => 300, - 'quicktags' => false, - 'tinymce' => true - ) ); +function miproduct_related_products() { + global $post; + + // Noncename needed to verify where the data originated + $nonce = wp_create_nonce( 'miproductmeta-meta-noncename' ); + echo ''; + // get the features for the post + $related_products = get_post_meta( $post->ID, 'miproduct_related_products', true ); + // output field + wp_editor( $related_products, 'related_products', array( + 'wpautop' => true, + 'media_buttons' => false, + 'textarea_name' => 'miproduct_related_products', + 'teeny' => false, + 'editor_height' => 300, + 'quicktags' => false, + 'tinymce' => true, + ) ); } /** @@ -172,19 +169,18 @@ function miproduct_related_products() * @access public * @return void */ -function miproduct_save_meta() -{ - global $post; - if (!wp_verify_nonce( $_POST['miproductmeta-meta-noncename'], 'miproductmeta-meta-noncename' )) { - return $post->ID; - } - if ( !current_user_can( 'edit_post', $post->ID ) ) { - return $post->ID; - } - $features = filter_var( $_POST['miproduct_features'] ); - $related_products = filter_var( $_POST['miproduct_related_products'] ); - update_post_meta( $post->ID, 'miproduct_features', $features ); - update_post_meta( $post->ID, 'miproduct_related_products', $related_products ); +function miproduct_save_meta() { + global $post; + if ( ! wp_verify_nonce( $_POST['miproductmeta-meta-noncename'], 'miproductmeta-meta-noncename' ) ) { + return $post->ID; + } + if ( ! current_user_can( 'edit_post', $post->ID ) ) { + return $post->ID; + } + $features = filter_var( $_POST['miproduct_features'] ); + $related_products = filter_var( $_POST['miproduct_related_products'] ); + update_post_meta( $post->ID, 'miproduct_features', $features ); + update_post_meta( $post->ID, 'miproduct_related_products', $related_products ); } @@ -198,84 +194,83 @@ add_action( 'save_post', 'miproduct_save_meta' ); * @access public * @return void */ -function michsci_taxonomies() -{ - - // Categories - $labels = array( - '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( - 'manage_terms' => 'manage_categories', - 'edit_terms' => 'manage_categories', - 'delete_terms' => 'manage_categories', - 'assign_terms' => 'edit_posts', - ); - - $args = array( - 'label' => __(MICHSCI_CATEGORY_PLURAL), - 'rewrite' => array( 'slug' => MICHSCI_CATEGORY_SLUG ), - 'capabilities' => $capabilities, - 'public ' => true, - 'show_in_quick_edit' => true, - 'show_in_admin_column' => true, - 'hierarchical' => true - ); - - register_taxonomy( - MICHSCI_CATEGORY_NAME, - MICHSCI_POST_TYPE, - $args - ); - - // Tags - $labels = array( - '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( - 'manage_terms' => 'manage_categories', - 'edit_terms' => 'manage_categories', - 'delete_terms' => 'manage_categories', - 'assign_terms' => 'edit_posts', - ); - - $args = array( - 'label' => __(MICHSCI_TAG_PLURAL), - 'rewrite' => array( 'slug' => MICHSCI_TAG_SLUG ), - 'capabilities' => $capabilities, - 'public ' => true, - 'show_in_quick_edit' => true, - 'show_in_admin_column' => true, - 'hierarchical' => false - ); - - register_taxonomy( - MICHSCI_TAG_NAME, - MICHSCI_POST_TYPE, - $args - ); +function michsci_taxonomies() { + + // Categories + $labels = array( + '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( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'manage_categories', + 'delete_terms' => 'manage_categories', + 'assign_terms' => 'edit_posts', + ); + + $args = array( + 'label' => __( MICHSCI_CATEGORY_PLURAL ), + 'rewrite' => array( 'slug' => MICHSCI_CATEGORY_SLUG ), + 'capabilities' => $capabilities, + 'public ' => true, + 'show_in_quick_edit' => true, + 'show_in_admin_column' => true, + 'hierarchical' => true, + ); + + register_taxonomy( + MICHSCI_CATEGORY_NAME, + MICHSCI_POST_TYPE, + $args + ); + + // Tags + $labels = array( + '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( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'manage_categories', + 'delete_terms' => 'manage_categories', + 'assign_terms' => 'edit_posts', + ); + + $args = array( + 'label' => __( MICHSCI_TAG_PLURAL ), + 'rewrite' => array( 'slug' => MICHSCI_TAG_SLUG ), + 'capabilities' => $capabilities, + 'public ' => true, + 'show_in_quick_edit' => true, + 'show_in_admin_column' => true, + 'hierarchical' => false, + ); + + register_taxonomy( + MICHSCI_TAG_NAME, + MICHSCI_POST_TYPE, + $args + ); } /** @@ -286,29 +281,28 @@ function michsci_taxonomies() * @access public * @return void */ -function michsci_taxonomy_filter_restrict_manage_posts() -{ - global $typenow; - - $post_types = get_post_types( array( '_builtin' => false ) ); - - if ( in_array( $typenow, $post_types ) ) { - $filters = get_object_taxonomies( $typenow ); - - foreach ( $filters as $tax_slug ) { - $tax_obj = get_taxonomy( $tax_slug ); - wp_dropdown_categories( array( - 'show_option_all' => __( 'Show All ' . $tax_obj->label ), - 'taxonomy' => $tax_slug, - 'name' => $tax_obj->name, - 'orderby' => 'name', - 'selected' => ( isset( $_GET[$tax_slug] ) ), - 'hierarchical' => $tax_obj->hierarchical, - 'show_count' => false, - 'hide_empty' => true - ) ); - } - } +function michsci_taxonomy_filter_restrict_manage_posts() { + global $typenow; + + $post_types = get_post_types( array( '_builtin' => false ) ); + + if ( in_array( $typenow, $post_types ) ) { + $filters = get_object_taxonomies( $typenow ); + + foreach ( $filters as $tax_slug ) { + $tax_obj = get_taxonomy( $tax_slug ); + wp_dropdown_categories( array( + 'show_option_all' => __( 'Show All ' . $tax_obj->label ), + 'taxonomy' => $tax_slug, + 'name' => $tax_obj->name, + 'orderby' => 'name', + 'selected' => ( isset( $_GET[ $tax_slug ] ) ), + 'hierarchical' => $tax_obj->hierarchical, + 'show_count' => false, + 'hide_empty' => true, + ) ); + } + } } add_action( 'restrict_manage_posts', 'michsci_taxonomy_filter_restrict_manage_posts' ); @@ -322,22 +316,21 @@ add_action( 'restrict_manage_posts', 'michsci_taxonomy_filter_restrict_manage_po * @access public * @return void */ -function michsci_taxonomy_filter_post_type_request( $query ) -{ - global $pagenow, $typenow; - - if ( 'edit.php' == $pagenow ) { - $filters = get_object_taxonomies( $typenow ); - foreach ( $filters as $tax_slug ) { - $var = &$query->query_vars[$tax_slug]; - - if ( isset( $var ) ) { - $term = get_term_by( 'id', $var, $tax_slug ); - - $var = $term->slug; - } - } - } +function michsci_taxonomy_filter_post_type_request( $query ) { + global $pagenow, $typenow; + + if ( 'edit.php' == $pagenow ) { + $filters = get_object_taxonomies( $typenow ); + foreach ( $filters as $tax_slug ) { + $var = &$query->query_vars[ $tax_slug ]; + + if ( isset( $var ) ) { + $term = get_term_by( 'id', $var, $tax_slug ); + + $var = $term->slug; + } + } + } } add_filter( 'parse_query', 'michsci_taxonomy_filter_post_type_request' ); add_action( 'init', 'michsci_taxonomies' ); @@ -350,10 +343,9 @@ add_action( 'init', 'michsci_custom_post_type' ); * @access public * @return void */ -function michsci_set_admin_columns() -{ - add_filter( 'manage_edit-miproduct_columns', 'michsci_admin_edit_columns' ); - add_action( 'manage_miproduct_posts_custom_column', 'michsci_admin_custom_columns' ); +function michsci_set_admin_columns() { + add_filter( 'manage_edit-miproduct_columns', 'michsci_admin_edit_columns' ); + add_action( 'manage_miproduct_posts_custom_column', 'michsci_admin_custom_columns' ); } add_action( 'admin_init', 'michsci_set_admin_columns' ); @@ -367,15 +359,14 @@ add_action( 'admin_init', 'michsci_set_admin_columns' ); * @access public * @return void */ -function michsci_admin_edit_columns($columns) -{ - $columns = array( - 'cb' => '', - 'title' => MICHSCI_PRODUCT_SINGLE . ' Title', - 'michproduct_col_cat' => MICHSCI_CATEGORY_SINGLE, - 'michproduct_col_tag' => MICHSCI_TAG_SINGLE - ); - return $columns; +function michsci_admin_edit_columns( $columns ) { + $columns = array( + 'cb' => '', + 'title' => MICHSCI_PRODUCT_SINGLE . ' Title', + 'michproduct_col_cat' => MICHSCI_CATEGORY_SINGLE, + 'michproduct_col_tag' => MICHSCI_TAG_SINGLE, + ); + return $columns; } /** @@ -387,36 +378,35 @@ function michsci_admin_edit_columns($columns) * @access public * @return void */ -function michsci_admin_custom_columns($column) -{ - global $post; - - switch ($column) { - case 'michproduct_col_cat': - $product_cats = get_the_terms( $post->ID, 'michsci_category' ); - $product_cats_html = array(); - if ( $product_cats ) { - foreach ( $product_cats as $product_cat ) { - array_push( $product_cats_html, $product_cat->name ); - } - echo implode( $product_cats_html, ', ' ); - } else { - _e( 'None', 'themeforce' ); - } - break; - case 'michproduct_col_tag': - $product_tags = get_the_terms( $post->ID, 'michsci_tag' ); - $product_tags_html = array(); - if ( $product_tags ) { - foreach ( $product_tags as $product_tag ) { - array_push( $product_tags_html, $product_tag->name ); - } - echo implode($product_tags_html, ', ' ); - } else { - _e( 'None', 'themeforce' ); - } - break; - } +function michsci_admin_custom_columns( $column ) { + global $post; + + switch ( $column ) { + case 'michproduct_col_cat': + $product_cats = get_the_terms( $post->ID, 'michsci_category' ); + $product_cats_html = array(); + if ( $product_cats ) { + foreach ( $product_cats as $product_cat ) { + array_push( $product_cats_html, $product_cat->name ); + } + echo implode( $product_cats_html, ', ' ); + } else { + _e( 'None', 'themeforce' ); + } + break; + case 'michproduct_col_tag': + $product_tags = get_the_terms( $post->ID, 'michsci_tag' ); + $product_tags_html = array(); + if ( $product_tags ) { + foreach ( $product_tags as $product_tag ) { + array_push( $product_tags_html, $product_tag->name ); + } + echo implode( $product_tags_html, ', ' ); + } else { + _e( 'None', 'themeforce' ); + } + break; + } } /** @@ -429,57 +419,56 @@ function michsci_admin_custom_columns($column) * @access public * @return void */ -function michsci_shortcode($atts) -{ - extract( shortcode_atts( array( 'limit' => '10' ), $atts ) ); - ob_start(); - - if ( isset($atts['cat']) ) { - if ($prodCategory = get_term_by( 'slug', $atts['cat'], MICHSCI_CATEGORY_NAME ) ) { - if(!isset($_REQUEST[MICHSCI_CATEGORY_NAME])){ - $_REQUEST[MICHSCI_CATEGORY_NAME] = $prodCategory->term_id; - } - $cat_id = $prodCategory->term_id; - } - } - $term = get_term_by("id", $_REQUEST[MICHSCI_CATEGORY_NAME],"michsci_category"); - $name = $term->name; - - if(!$name){ - $name = "ALL PRODUCTS"; - } - global $wp; - echo '
- Search Products
'; - echo michsci_get_terms_dropdown($cat_id); - echo '
'; - if ( $product_id = filter_var( $_REQUEST['product'], FILTER_VALIDATE_INT ) ) { - michsci_show_product($product_id); - } else if ( $cat_id = filter_var( $_REQUEST['category'], FILTER_VALIDATE_INT ) ) { - michsci_list_categories($cat_id); - } else if ( !$catid_id && !$product_id ) { -// $text_query = $_REQUEST['tsearch']; - $text_query = filter_var($_REQUEST['tsearch'], FILTER_SANITIZE_STRING); -// strip_tags($text_query); - if(isset($_REQUEST['tsearch'])){ - setcookie("search", "true",time()+2, "/" ); - } else { - setcookie("search", "null",time()+2, "/" ); - } - michsci_list_products($text_query); - michsci_list_categories(); - } - - $output = ob_get_contents(); - ob_end_clean(); - return $output; + if ( $product_id = filter_var( $_REQUEST['product'], FILTER_VALIDATE_INT ) ) { + michsci_show_product( $product_id ); + } else if ( $cat_id = filter_var( $_REQUEST['category'], FILTER_VALIDATE_INT ) ) { + michsci_list_categories( $cat_id ); + } else if ( ! $catid_id && ! $product_id ) { + // $text_query = $_REQUEST['tsearch']; + $text_query = filter_var( $_REQUEST['tsearch'], FILTER_SANITIZE_STRING ); + // strip_tags($text_query); + if ( isset( $_REQUEST['tsearch'] ) ) { + setcookie( 'search', 'true',time() + 2, '/' ); + } else { + setcookie( 'search', 'null',time() + 2, '/' ); + } + michsci_list_products( $text_query ); + michsci_list_categories(); + } + + $output = ob_get_contents(); + ob_end_clean(); + return $output; } /** @@ -490,68 +479,65 @@ function michsci_shortcode($atts) * @access public * @return void */ -function michsci_get_terms_dropdown($cat_id) -{ -// $test = $_REQUEST['tsearch']; -// $filterTest = filter_var($test, FILTER_SANITIZE_STRING); -// echo $filterTest; - - - $taxonomyName = MICHSCI_CATEGORY_NAME; - if($cat_id){ - $main = get_term($cat_id, MICHSCI_CATEGORY_NAME); - $cats_child = get_term_children($cat_id, $taxonomyName); - $output =""; - } else { - - $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'name', 'hide_empty' => false)); - $terms = get_terms($taxonomyName, array('orderby' => 'name', 'hide_empty' => false)); - - $output =""; } - return $output; +function michsci_get_terms_dropdown( $cat_id ) { + // $test = $_REQUEST['tsearch']; + // $filterTest = filter_var($test, FILTER_SANITIZE_STRING); + // echo $filterTest; + $taxonomyName = MICHSCI_CATEGORY_NAME; + if ( $cat_id ) { + $main = get_term( $cat_id, MICHSCI_CATEGORY_NAME ); + $cats_child = get_term_children( $cat_id, $taxonomyName ); + $output = "'; + } else { + + $parent_terms = get_terms( $taxonomyName, array( 'parent' => 0, 'orderby' => 'name', 'hide_empty' => false ) ); + $terms = get_terms( $taxonomyName, array( 'orderby' => 'name', 'hide_empty' => false ) ); + + $output = "'; } + return $output; } @@ -563,61 +549,60 @@ function michsci_get_terms_dropdown($cat_id) * @access public * @return void */ -function michsci_list_products($text_query) -{ - global $wpdb, $wp; - - $cat = get_term($cat_id, MICHSCI_CATEGORY_NAME); - $args = array( - 'posts_per_page' => -1, - 'post_type' => 'miproduct', - 's' => $text_query -// 'meta_query' => array( -// array( -// 'key' => 'post_title', -// 'value' => $text_query, -// 'compare' => 'LIKE' -// ) -// ) - // add meta query here - ); - $misch_category = ( isset( $_REQUEST[MICHSCI_CATEGORY_NAME] ) ) - ? filter_var( $_REQUEST[MICHSCI_CATEGORY_NAME] ) - : false; - - if ($misch_category) { - $args['tax_query'] = array( - 'relation' => 'AND' - ); - $args['tax_query'][] = array( - 'taxonomy' => MICHSCI_CATEGORY_NAME, - 'field' => 'id', - 'terms' => $misch_category - ); - } - - $products = get_posts( $args ); - $totalProducts = count( $products ); - $current_url = esc_url( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ); - $iterator = 1; - - foreach ( $products as $product ) { - $productTerms = wp_get_post_terms( $product->ID, MICHSCI_CATEGORY_NAME, 'name' ); - $pTerm = $productTerms[0]; - $product->term = $pTerm->name; - $product->end = false; - if ( $iterator == $totalProducts ) { - $product->end = true; - } - $cat->href = "?michsci_category="; - $product->href = $current_url - . ( ( strpos( $current_url, '?' ) ) ? '&' : '?' ) - . "product=" . $product->ID; - ++$iterator; - } - //echo '
' . print_r($products, true) . '
'; - include 'views/list_products.php'; - return; +function michsci_list_products( $text_query ) { + global $wpdb, $wp; + + $cat = get_term( $cat_id, MICHSCI_CATEGORY_NAME ); + $args = array( + 'posts_per_page' => -1, + 'post_type' => 'miproduct', + 's' => $text_query, + // 'meta_query' => array( + // array( + // 'key' => 'post_title', + // 'value' => $text_query, + // 'compare' => 'LIKE' + // ) + // ) + // add meta query here + ); + $misch_category = ( isset( $_REQUEST[ MICHSCI_CATEGORY_NAME ] ) ) + ? filter_var( $_REQUEST[ MICHSCI_CATEGORY_NAME ] ) + : false; + + if ( $misch_category ) { + $args['tax_query'] = array( + 'relation' => 'AND', + ); + $args['tax_query'][] = array( + 'taxonomy' => MICHSCI_CATEGORY_NAME, + 'field' => 'id', + 'terms' => $misch_category, + ); + } + + $products = get_posts( $args ); + $totalProducts = count( $products ); + $current_url = esc_url( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ); + $iterator = 1; + + foreach ( $products as $product ) { + $productTerms = wp_get_post_terms( $product->ID, MICHSCI_CATEGORY_NAME, 'name' ); + $pTerm = $productTerms[0]; + $product->term = $pTerm->name; + $product->end = false; + if ( $iterator == $totalProducts ) { + $product->end = true; + } + $cat->href = '?michsci_category='; + $product->href = $current_url + . ( ( strpos( $current_url, '?' ) ) ? '&' : '?' ) + . 'product=' . $product->ID; + ++$iterator; + } + // echo '
' . print_r($products, true) . '
'; + include 'views/list_products.php'; + return; } /** * michsci_list_categories @@ -628,40 +613,38 @@ function michsci_list_products($text_query) * @access public * @return void */ -function michsci_list_categories( $cat_id = null ) -{ - global $wpdb, $wp; - - $taxonomy = MICHSCI_CATEGORY_NAME; - $args = array( - 'hide_empty' => false, - 'pad_counts' => true - ); - if ( $cat_id ) { - $args['child_of'] = $cat_id; - } else { - $args['parent'] = 0; - } - $taxonomy_terms = get_terms( $taxonomy, $args ); - - - $totalTerms = count( $taxonomy_terms); - $current_url = esc_url( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ); - $iterator = 1; - - foreach ( $taxonomy_terms as $term) { - $term->end = false; - if ( $iterator == $totalTerms) { - $term->end = true; - } - $term->href .= //$current_url -// ( ( strpos( $current_url, '?' ) ) ? '&' : '?' ) - "?michsci_category=" . $term->term_id; - ++$iterator; - } - - include 'views/list_categories.php'; - return; +function michsci_list_categories( $cat_id = null ) { + global $wpdb, $wp; + + $taxonomy = MICHSCI_CATEGORY_NAME; + $args = array( + 'hide_empty' => false, + 'pad_counts' => true, + ); + if ( $cat_id ) { + $args['child_of'] = $cat_id; + } else { + $args['parent'] = 0; + } + $taxonomy_terms = get_terms( $taxonomy, $args ); + + $totalTerms = count( $taxonomy_terms ); + $current_url = esc_url( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ); + $iterator = 1; + + foreach ( $taxonomy_terms as $term ) { + $term->end = false; + if ( $iterator == $totalTerms ) { + $term->end = true; + } + $term->href .= // $current_url + // ( ( strpos( $current_url, '?' ) ) ? '&' : '?' ) + '?michsci_category=' . $term->term_id; + ++$iterator; + } + + include 'views/list_categories.php'; + return; } /** @@ -673,12 +656,11 @@ function michsci_list_categories( $cat_id = null ) * @access public * @return void */ -function michsci_show_product($prod_id) -{ - global $wpdb, $wp; - $product = get_post( $prod_id ); - include 'views/product_detail.php'; - return; +function michsci_show_product( $prod_id ) { + global $wpdb, $wp; + $product = get_post( $prod_id ); + include 'views/product_detail.php'; + return; } /** * michsci_show_category @@ -689,21 +671,20 @@ function michsci_show_product($prod_id) * @access public * @return void */ -function michsci_show_category($cat_id) -{ - global $wpdb, $wp; - $term = get_terms( - MICHSCI_CATEGORY_NAME, - array( - 'child_of' => $cat_id, - 'hide_empty' => true, - //'parent' => $catid_id, - //'hierarchical' => false - ) - ); - echo '
' . print_r( $term, true ) . '
'; - include 'views/category_detail.php'; - return; +function michsci_show_category( $cat_id ) { + global $wpdb, $wp; + $term = get_terms( + MICHSCI_CATEGORY_NAME, + array( + 'child_of' => $cat_id, + 'hide_empty' => true, + // 'parent' => $catid_id, + // 'hierarchical' => false + ) + ); + echo '
' . print_r( $term, true ) . '
'; + include 'views/category_detail.php'; + return; } add_shortcode( 'michproducts', 'michsci_shortcode' );