ID, 'pinType', true );
print('
Enter the pin type
movie
product
recipe
Save the post, after that you will be able to edit the additional parameters
');
switch ($pinType) {
case 'movie':
$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);
$movieForm = '
Enter the title of the movie *
Enter the movie description
Actors:
';
$i = 0;
if (empty($actors)){
$movieForm .= '
Enter an actor
';
}
else {
foreach($actors as $pinActor) {
$movieForm .= '
Enter an actor
';
$i += 1;
}
}
$movieForm .= '
Add actor |
Remove actor
Select a content rating
G - General Audiences
PG - Parental Guidance Suggested
PG-13 — Parents Strongly Cautioned
R — Restricted
NC-17 — No One 17 and Under Admitted
Enter the movie release date
Enter the movie rating
Enter the maximum rating
';
print($movieForm);
break;
case 'product':
$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);
print('
Enter the product name *
Enter the product description
Enter the price *
Select a currency *
USD United States Dollars
EUR Euro
CAD Canada Dollars
GBP United Kingdom Pounds
JPY Japan Yen
CHF Switzerland Francs
DZD Algeria Dinars
ARP Argentina Pesos
AUD Australia Dollars
BSD Bahamas Dollars
BBD Barbados Dollars
BMD Bermuda Dollars
BRR Brazil Real
BGL Bulgaria Lev
CLP Chile Pesos
CNY China Yuan Renmimbi
CYP Cyprus Pounds
CSK Czech Republic Koruna
DKK Denmark Kroner
XCD Eastern Caribbean Dollars
EGP Egypt Pounds
FJD Fiji Dollars
HKD Hong Kong Dollars
HUF Hungary Forint
ISK Iceland Krona
INR India Rupees
IDR Indonesia Rupiah
ILS Israel New Shekels
JMD Jamaica Dollars
JOD Jordan Dinar
KRW Korea (South) Won
LBP Lebanon Pounds
MYR Malaysia Ringgit
MXP Mexico Pesos
NZD New Zealand Dollars
NOK Norway Kroner
PKR Pakistan Rupees
PHP Philippines Pesos
PLZ Poland Zloty
ROL Romania Leu
RUR Russia Rubles
SAR Saudi Arabia Riyal
SGD Singapore Dollars
ZAR South Africa Rand
SDD Sudan Dinar
SEK Sweden Krona
TWD Taiwan Dollars
THB Thailand Baht
TTD Trinidad and Tobago Dollars
TRL Turkey Lira
VEB Venezuela Bolivar
ZMK Zambia Kwacha
Enter the product availability
in stock
pre-order
in store only
online only out of stock
discontinued
Enter the product brand
');
break;
case 'recipe':
$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 );
$recipeForm = '
Enter the recipe name *
Enter the recipe description
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)){
$recipeForm .= '
Enter an ingredient
';
} else {
foreach($ingredients as $pinIngredient) {
$recipeForm .= '
Enter an ingredient
';
$i += 1;
}
}
$recipeForm .= '
Add ingredient |
Remove ingredient
Enter the time it takes to cook it (in minutes)
Enter the number of servings made by this recipe (e.g. "5 servings" or "Serves 4-6" or "Yields 10 burgers")
';
print($recipeForm);
break;
}
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_pinName']);
add_post_meta($post_ID, 'pinName', $pinName, true) or
update_post_meta($post_ID, 'pinName', $pinName);
$pinDescription = sanitize_text_field($_POST['abg_rp_pinDescription']);
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_pinDescription']);
$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_pinName']);
add_post_meta($post_ID, 'pinName', $pinName, true) or
update_post_meta($post_ID, 'pinName', $pinName);
$pinDescription = sanitize_text_field($_POST['abg_rp_pinDescription']);
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;
}