ID, 'pinType', true ); print('


Save the post, after that you will be able to edit the additional parameters

'); // Movie form $numDirectors = get_post_meta($post->ID, 'numDirectors', true); $numActors = get_post_meta($post->ID, 'numActors', true); if(empty($numDirectors)) { $numDirectors = 0; } if(empty($numActors)){ $numActors = 0; } $directors = array(); for($i = 0; $i < $numDirectors; $i++){ $directorName = 'pinDirector'.$i; $directors[] = get_post_meta($post->ID, $directorName, true); } $actors = array(); for($i = 0; $i < $numActors; $i++){ $actorName = 'pinActor'.$i; $actors[] = get_post_meta($post->ID, $actorName, true); } $pinName = get_post_meta( $post->ID, 'pinName', true ); $pinDescription = get_post_meta( $post->ID, 'pinDescription', true ); $pinRating = get_post_meta( $post->ID, 'pinRating', true ); $pinRatingMax = get_post_meta( $post->ID, 'pinRatingMax', true ); $pinContent = get_post_meta( $post->ID, 'pinContent', true ); $pinDate = get_post_meta( $post->ID, 'pinDate', true); $pinForm = '



Directors:' ; $i = 0; if (empty($directors)){ $pinForm .= '
'; } else { foreach($directors as $pinDirector) { $pinForm .= '
'; $i += 1; } } $pinForm .= '
Add director Remove director

Actors: '; $i = 0; if (empty($actors)){ $pinForm .= '
'; } else { foreach($actors as $pinActor) { $pinForm .= '
'; $i += 1; } } $pinForm .= '
Add actor | Remove actor





'; //Product form $pinTitle = get_post_meta( $post->ID, 'pinTitle', true ); $pinDescription = get_post_meta( $post->ID, 'pinDescription', true ); $pinAmount = get_post_meta( $post->ID, 'pinAmount', true ); $pinCurrency = get_post_meta( $post->ID, 'pinCurrency', true ); $pinAvailability = get_post_meta( $post->ID, 'pinAvailability', true); $pinBrand = get_post_meta( $post->ID, 'pinBrand', true); $pinForm .= '







'; //Recipe form $numIngredients = get_post_meta($post->ID, 'numIngredients', true); if(empty($numIngredients)) { $numDirectors = 0; } $ingredients = array(); for($i = 0; $i < $numIngredients; $i++){ $ingredient = 'pinIngredient'.$i; $ingredients[] = get_post_meta($post->ID, $ingredient, true); } $pinName = get_post_meta( $post->ID, 'pinName', true ); $pinDescription = get_post_meta( $post->ID, 'pinDescription', true ); $pinTime = get_post_meta( $post->ID, 'pinTime', true ); $pinYield = get_post_meta( $post->ID, 'pinYield', true ); $pinForm .= '



Ingredients (Ingredient name must be written in English, otherwise Pinterest will NOT validate your Rich Pin):
(e.g. "1/3 cup ice" or "1 cup orange juice" or "1/2 banana")' ; $i = 0; if (empty($ingredients)){ $pinForm .= '
'; } else { foreach($ingredients as $pinIngredient) { $pinForm .= '
'; $i += 1; } } $pinForm .= '
Add ingredient | Remove ingredient

(in minutes)


(e.g. "5 servings" or "Serves 4-6" or "Yields 10 burgers")

'; print($pinForm); echo 'Do NOT forget to validate your rich pin at Pin validator'; } /* Saves meta data into the DB */ function abg_rp_save_postdata( $post_id ) { if ( 'page' == $_REQUEST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) return; } else { if ( ! current_user_can( 'edit_post', $post_id ) ) return; } if ( ! isset( $_POST['abg_rp_noncename'] ) || ! wp_verify_nonce( $_POST['abg_rp_noncename'], plugin_basename( __FILE__ ) ) ) return; $post_ID = $_POST['post_ID']; $pinType = sanitize_text_field($_POST['abg_rp_pinType']); add_post_meta($post_ID, 'pinType', $pinType, true) or update_post_meta($post_ID, 'pinType', $pinType); switch ($pinType) { case 'movie': $pinName = sanitize_text_field($_POST['abg_rp_pinMovieName']); add_post_meta($post_ID, 'pinName', $pinName, true) or update_post_meta($post_ID, 'pinName', $pinName); $pinDescription = sanitize_text_field($_POST['abg_rp_pinMovieDescription']); add_post_meta($post_ID, 'pinDescription', $pinDescription, true) or update_post_meta($post_ID, 'pinDescription', $pinDescription); $pinRating = sanitize_text_field($_POST['abg_rp_pinRating']); add_post_meta($post_ID, 'pinRating', $pinRating, true) or update_post_meta($post_ID, 'pinRating', $pinRating); $pinRatingMax = sanitize_text_field($_POST['abg_rp_pinRatingMax']); add_post_meta($post_ID, 'pinRatingMax', $pinRatingMax, true) or update_post_meta($post_ID, 'pinRatingMax', $pinRatingMax); $pinContent = sanitize_text_field($_POST['abg_rp_pinContent']); add_post_meta($post_ID, 'pinContent', $pinContent, true) or update_post_meta($post_ID, 'pinContent', $pinContent); $pinDate = sanitize_text_field($_POST['abg_rp_pinDate']); add_post_meta($post_ID, 'pinDate', $pinDate, true) or update_post_meta($post_ID, 'pinDate', $pinDate); $numDir = $_POST['abg_rp_num_directors']; $j = 0; for($i = 0; $i < $numDir; $i++) { $currentDir = sanitize_text_field($_POST['abg_rp_pinDirector'.$i]); if (!empty($currentDir)){ add_post_meta($post_ID, 'pinDirector'.$i, $currentDir, true) or update_post_meta($post_ID, 'pinDirector'.$i, $currentDir); $j++; } } $numDir = $j; add_post_meta($post_ID, 'numDirectors', $numDir, true) or update_post_meta($post_ID, 'numDirectors', $numDir); $numAct = $_POST['abg_rp_num_actors']; $j = 0; for($i = 0; $i < $numAct; $i++) { $currentAct = sanitize_text_field($_POST['abg_rp_pinActor'.$i]); if (!empty($currentAct)){ add_post_meta($post_ID, 'pinActor'.$i, $currentAct, true) or update_post_meta($post_ID, 'pinActor'.$i, $currentAct); $j++; } } $numAct = $j; add_post_meta($post_ID, 'numActors', $numAct, true) or update_post_meta($post_ID, 'numActors', $numAct); break; case 'product' : $pinTitle = sanitize_text_field($_POST['abg_rp_pinTitle']); $pinDescription = sanitize_text_field($_POST['abg_rp_pinProductDescription']); $pinAmount = $_POST['abg_rp_pinAmount']; $pinCurrency = sanitize_text_field($_POST['abg_rp_pinCurrency']); $pinAvailability = sanitize_text_field($_POST['abg_rp_pinAvailability']); $pinBrand = sanitize_text_field($_POST['abg_rp_pinBrand']); // Do something with $mydata // either using add_post_meta($post_ID, 'pinTitle', $pinTitle, true) or update_post_meta($post_ID, 'pinTitle', $pinTitle); add_post_meta($post_ID, 'pinDescription', $pinDescription, true) or update_post_meta($post_ID, 'pinDescription', $pinDescription); add_post_meta($post_ID, 'pinAmount', $pinAmount, true) or update_post_meta($post_ID, 'pinAmount', $pinAmount); add_post_meta($post_ID, 'pinCurrency', $pinCurrency, true) or update_post_meta($post_ID, 'pinCurrency', $pinCurrency); add_post_meta($post_ID, 'pinAvailability', $pinAvailability, true) or update_post_meta($post_ID, 'pinAvailability', $pinAvailability); add_post_meta($post_ID, 'pinBrand', $pinBrand, true) or update_post_meta($post_ID, 'pinBrand', $pinBrand); break; case 'recipe': $pinName = sanitize_text_field($_POST['abg_rp_pinRecipeName']); add_post_meta($post_ID, 'pinName', $pinName, true) or update_post_meta($post_ID, 'pinName', $pinName); $pinDescription = sanitize_text_field($_POST['abg_rp_pinRecipeDescription']); add_post_meta($post_ID, 'pinDescription', $pinDescription, true) or update_post_meta($post_ID, 'pinDescription', $pinDescription); $pinTime = sanitize_text_field($_POST['abg_rp_pinTime']); add_post_meta($post_ID, 'pinTime', $pinTime, true) or update_post_meta($post_ID, 'pinTime', $pinTime); $pinYield = sanitize_text_field($_POST['abg_rp_pinYield']); add_post_meta($post_ID, 'pinYield', $pinYield, true) or update_post_meta($post_ID, 'pinYield', $pinYield); $numIng = $_POST['abg_rp_num_ingredients']; $j = 0; for($i = 0; $i < $numIng; $i++) { $currentIng = sanitize_text_field($_POST['abg_rp_pinIngredient'.$i]); if (!empty($currentIng)){ add_post_meta($post_ID, 'pinIngredient'.$i, $currentIng, true) or update_post_meta($post_ID, 'pinIngredient'.$i, $currentIng); $j++; } } $numIng = $j; add_post_meta($post_ID, 'numIngredients', $numIng, true) or update_post_meta($post_ID, 'numIngredients', $numIng); break; } } /* Add meta-data to the post */ function abg_rp_add_pin_info() { global $post; if( is_singular() && !is_front_page() && !is_home() && !is_404() && !is_tag()) { // get current post meta data $pinType = get_post_meta($post->ID, 'pinType', true); switch ($pinType) { case 'movie': echo "\n".'
'."\n"; echo ''."\n"; $numDirectors = get_post_meta($post->ID, 'numDirectors', true); $numActors = get_post_meta($post->ID, 'numActors', true); if(empty($numDirectors)) { $numDirectors = 0; } if(empty($numActors)){ $numActors = 0; } $directors = array(); for($i = 0; $i < $numDirectors; $i++){ $directorName = 'pinDirector'.$i; $directors[] = get_post_meta($post->ID, $directorName, true); } $actors = array(); for($i = 0; $i < $numActors; $i++){ $actorName = 'pinActor'.$i; $actors[] = get_post_meta($post->ID, $actorName, true); } $pinName = get_post_meta( $post->ID, 'pinName', true ); $pinDescription = get_post_meta( $post->ID, 'pinDescription', true ); $pinRating = get_post_meta( $post->ID, 'pinRating', true ); $pinRatingMax = get_post_meta( $post->ID, 'pinRatingMax', true ); $pinContent = get_post_meta( $post->ID, 'pinContent', true ); $pinDate = get_post_meta( $post->ID, 'pinDate', true); if ( function_exists('abg_rp_remove_spaces')) $pinDescription = abg_rp_remove_spaces($pinDescription); echo ''."\n"; echo '
'."\n"; echo ''."\n"; echo '

'.$pinName.'

'."\n"; echo ''.$pinDescription.''."\n"; foreach($directors as $pinDirector) { echo '
'."\n"; echo ''.$pinDirector.''."\n"; echo '
'."\n"; } foreach($actors as $pinActor) { echo '
'."\n"; echo ''.$pinActor.''."\n"; echo '
'."\n"; } echo '
'."\n"; echo ''.$pinRating.''."\n"; echo ''.$pinRatingMax.''."\n"; echo '
'."\n"; echo ''."\n"; echo ''."\n"; echo '
'."\n"; echo ''."\n"; echo '
'."\n\n"; break; case 'product': echo "\n".'
'."\n"; echo ''."\n"; $pinTitle = get_post_meta(get_the_ID(),'pinTitle',true); $pinDescription = get_post_meta(get_the_ID(),'pinDescription',true); $pinAmount = get_post_meta(get_the_ID(),'pinAmount',true); $pinCurrency = get_post_meta(get_the_ID(),'pinCurrency',true); $pinAvailability = get_post_meta(get_the_ID(),'pinAvailability',true); $pinBrand = get_post_meta(get_the_ID(),'pinBrand',true); // apply filter if ( function_exists('abg_rp_remove_spaces')) $pinDescription = abg_rp_remove_spaces($pinDescription); echo ''."\n"; echo '
'."\n"; echo ''."\n"; echo ''."\n"; echo ''.$pinDescription.''."\n"; echo ''.$pinBrand.''."\n"; echo '
'."\n"; echo ''.$pinAmount.''."\n"; echo ''."\n"; echo ''."\n"; echo '
'."\n"; echo '
'."\n"; echo ''."\n"; echo '
'."\n"; break; case 'recipe': echo "\n".'
'."\n"; echo ''."\n"; $numIngredients = get_post_meta($post->ID, 'numIngredients', true); if(empty($numIngredients)) { $numIngredients = 0; } $ingredients = array(); for($i = 0; $i < $numIngredients; $i++){ $ingredientName = 'pinIngredient'.$i; $ingredients[] = get_post_meta($post->ID, $ingredientName, true); } $pinName = get_post_meta( $post->ID, 'pinName', true ); $pinDescription = get_post_meta( $post->ID, 'pinDescription', true ); $pinTime = get_post_meta( $post->ID, 'pinTime', true ); $pinYield = get_post_meta( $post->ID, 'pinYield', true ); if ( function_exists('abg_rp_remove_spaces')) $pinDescription = abg_rp_remove_spaces($pinDescription); echo ''."\n"; echo '
'."\n"; echo ''.$pinName.''."\n"; echo ''.$pinDescription.''."\n"; echo ''."\n"; echo ''."\n"; echo ''.$pinYield.''."\n"; foreach($ingredients as $pinIngredient) { echo ''.$pinIngredient.''."\n"; } echo '
'."\n"; echo ''."\n"; echo '
'."\n\n"; break; } } } add_action( 'wp_head', 'abg_rp_add_pin_info', 99); /** * Helpers */ /* Get the current URL */ function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } /* Remove spaces from a string */ function abg_rp_remove_spaces($string) { $result = preg_replace("/\s+/", " ", $string); // remove strip tags and strip shortcodes I already use in get_excerpt_by_id() return $result; }