I have created this shortcode and registered it:
function product_paypal_button_display($atts){
//Make the PayPal variables available downstream.
global $wpdb;
global $product_paypal_sandbox_url;
global $product_paypal_live_url;
global $product_paypal_sandbox_merchant_id;
global $product_paypal_live_merchant_id;
//Get post id for auction from post where auction is inserted. Used in SQL queries to find bids, id's buy status for painting and id's the painting in the PayPal button url params and returned Instant Payment Notification.
$product_postid = get_the_id();
//Creates djw_products table in database if it doesn't exist.
$table = $wpdb->prefix . "djw_products";
$charset_collate = $wpdb->get_charset_collate();
$sql ="CREATE TABLE IF NOT EXISTS `$table` (
`id` mediumint(15) NOT NULL AUTO_INCREMENT,
`post_id` mediumint(15) NOT NULL,
`description` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB AUTO_INCREMENT=10
DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
//SHORTCODE ATTRIBUTE PROCESSING BEGINS HERE
//Create allowed attributes for the shortcode and set their defaults.
$parsed_atts = shortcode_atts( array(
'product_sell_price' => '150',
'product_description' => ''
), $atts);
//Parse the attributes passed from the shortcode for use downstream. Use default where no attribute was passed. Ignore any passed attribute not specified above.
$product_sell_price = $parsed_atts['product_sell_price'];
$product_description = $parsed_atts['product_description'];
//Check wp_postmeta table meta_key column for buy_status set from PayPal IPN action. The meta_value is set to 1 if the buy_status key exists for this post.
$product_buy_status = get_post_meta( get_the_ID(), 'buy_status', true );
//Get Post title for use in PayPal button url variables. Assign to variable.
$product_title = get_the_title();
//Get the permalink of this post for use in setting post-auction visit to post.
$product_permalink = get_the_permalink();
//Display PayPal button and price for product.
if(!$product_buy_status == 1){
$product_paypal_form_output = '';//clear the output before loading the form.
//HTML FOR PAYMENT AND PAYPAL BUTTON BEGINS HERE.
$product_paypal_form_output .= '<div style="min-width: 280px; background-color: #ffffff; outline: 1px solid #ffffff; outline-offset: 4px; text-align: center; padding: 1.2em 0em .75em 0em; margin: 0px 8px 40px 8px;"><h4>This painting is available<br><h2>' . $product_sell_price . '</h2></h4><br>' . $product_description . '<br>Use your credit/debit card at PayPal<br><strong>Easy, safe, and secure</strong><br><br>';//Form container.
//Begin form.
//SET FORM ACTION for testing or live PayPal IPN condition.
$product_paypal_form_output .= '<form action="' . $product_paypal_sandbox_url . '" method="post" name="paypal_form">';
// $product_paypal_form_output .= '<form action="' . $product_paypal_live_url . '" method="post" name="paypal_form">';
$product_paypal_form_output .= '<input type="hidden" name="business" value="' . $product_paypal_sandbox_merchant_id . '">';//Value is PayPal sandbox merchant account identifier to avoid using email address identifier.
// $product_paypal_form_output .= '<input type="hidden" name="business" value="' . $product_paypal_live_merchant_id . '">';//Value is PayPal live merchant account identifier to avoid using email address identifier.
$product_paypal_form_output .= '<input type="hidden" name="cmd" value="_xclick">';
$product_paypal_form_output .= '<input type="hidden" name="item_name" value="' . $product_title . '">';//post title (name of painting) sent to PayPal as item name.
$product_paypal_form_output .= '<input type="hidden" name="item_number" value="' . $product_postid . '">';//post id is sent to PayPal as item number.
$product_paypal_form_output .= '<input type="hidden" name="amount" value="' . $product_sell_price . '">';//price for product.
$product_paypal_form_output .= '<input type="hidden" name="no_shipping" value="1">';//shipping free.
$product_paypal_form_output .= '<input type="hidden" name="currency_code" value="USD">';//U.S. $
$product_paypal_form_output .= '<input type="hidden" name="cancel_return" value="https://www.donwest.gallery/cancel/">';//return url if user cancels payment by clicking "return to merchant" link at PayPal.
$product_paypal_form_output .= '<input type="hidden" name="return" value="https://www.donwest.gallery/thank-you/">';//return url if user completes transaction.
$product_paypal_form_output .= '<input type="image" src="https://paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" name="submit">';//link to PayPal button graphic.
$product_paypal_form_output .= '</form>';//end form.
$product_paypal_form_output .= '</div>';//end form container.
return $product_paypal_form_output;//put it on the screen.
}
//If the product has been purchased then display sold status and show no PayPal button.
if($buy_status == 1){
$buy_status_output = '';//clear the output before loading status.
$buy_status_output .= '<div style="background-color: #ffffff; outline: 1px solid #ffffff; outline-offset: 4px; text-align: center; padding: 1.2em 1.2em 0em 1.2em; margin: 1.2em auto 0em; display: table;"><h4>••• Purchased •••</h4></div>';
return $buy_status_output;//put it on the screen.
}
}
This is the shortcode inserted on the post:
[product product_sell_price=$765 product_description=20”x16” oil on stretched linen. Varnished for protection and ease of cleaning. Includes the frame as shown and is ready to hang.]
The problem: product_sell_price is correctly parsed and displays $765 in the post. No worries with that. However, product_description is not parsing completely and only displays 20”x16”. The rest of the parameter is not being parsed.
How can I fix this? I suspect it’s an issue with escaping some characters but I am unfamiliar with escaping characters.
Any assistance would be greatly appreciated!
"
, soproduct_description="20”x16” oil bla …"
. WP is trying to handle input that doesn't adhere to this standard, but as you can see, there are limitations.20\”x16\”
.