我已创建并注册了此短代码:
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.
}
}
这是在帖子上插入的短代码:
[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\\u sell\\u price已正确解析,并在帖子中显示765美元。不用担心。但是,product\\u description没有完全解析,只显示20“x16”。未分析参数的其余部分。
我怎样才能解决这个问题?我怀疑转义某些字符有问题,但我不熟悉转义字符。
任何帮助都将不胜感激!
SO网友:James
在痴迷地修补之后,我解决了这个问题。如上所述,这是在帖子中输入的失败快捷码
[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.]
这是一个非常有效的短代码:
[product product_sell_price=$765 product_description=\'20”x16” oil on stretched linen.<br>Varnished for protection and ease of cleaning.<br>Includes the frame as shown and is ready to hang.<br>\']
请注意,单引号是垂直的、非卷曲单引号,而不是标准的卷曲单引号。iPhone/iPad键盘有特定按键的按键选项。点击123键,然后点击#+=键,然后按住键盘上的单引号,您将获得“`”和“选项”。
我希望这能帮助其他人,因为这类问题有时需要几个小时才能解决:)