From 199a0d7fb0f953fe3052d01f4263e0d5c47cec35 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 28 Dec 2015 12:05:53 -0500 Subject: [PATCH] Adding the meto fields for Features and Related Products These have the editor in them as well --- index.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index b3a3e51..f765e28 100644 --- a/index.php +++ b/index.php @@ -85,7 +85,8 @@ function michsci_custom_post_type() { 'exclude_from_search' => false, 'publicly_queryable' => true, 'rewrite' => $rewrite, - 'capability_type' => 'page' + 'capability_type' => 'page', + 'register_meta_box_cb' => 'michsci_add_metaboxes' ); register_post_type( MICHSCI_POST_TYPE, $args ); @@ -94,6 +95,104 @@ function michsci_custom_post_type() { } +/** + * michsci_add_metaboxes + * + * Add the meta fields + * + * @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 Products', 'miproduct_related_products', MICHSCI_POST_TYPE, 'normal', 'high'); +} + +/** + * miproduct_features + * + * Add field for the features + * + * @access public + * @return void + */ +function miproduct_features() +{ + global $post; + + // Noncename needed to verify where the data originated + $nonce = wp_create_nonce( 'miproductmeta-meta-noncename' ); + echo ''; + // 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 + ) ); +} + +/** + * miproduct_related_products + * + * Adds the field for related product + * + * @access public + * @return void + */ +function miproduct_related_products() +{ + global $post; + + // Noncename needed to verify where the data originated + //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 + ) ); +} + +/** + * miproduct_save_meta + * + * Saves the meta fields for the product + * + * @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_features'] ); + update_post_meta( $post->ID, 'miproduct_features', $features ); + update_post_meta( $post->ID, 'miproduct_related_products', $related_products ); + +} + +add_action( 'save_post', 'miproduct_save_meta' ); + /** * michsci_taxonomies * -- 2.17.1