Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom button text via shortcode attributes #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions includes/stripe-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ function wp_stripe_shortcode( $atts ) {
}

extract( shortcode_atts(array(
'cards' => 'true'
'cards' => 'true',
'button_text' => $options['stripe_header']
), $atts ) );

if ( $cards === 'true' ) {
$payments = '<div id="wp-stripe-types"></div>';
}

return '<a class="thickbox" id="wp-stripe-modal-button" title="' . esc_attr( $options['stripe_header'] ) . '" href="' . esc_url( $url ) . '"><span>' . esc_html( $options['stripe_header'] ) . '</span></a>' . $payments;
return '<a class="thickbox" id="wp-stripe-modal-button" title="' . esc_attr( $options['stripe_header'] ) . '" href="' . esc_url( $url ) . '"><span>' . esc_html( $button_text ) . '</span></a>' . $payments;

}
add_shortcode( 'wp-stripe', 'wp_stripe_shortcode' );
Expand Down Expand Up @@ -57,7 +58,7 @@ function wp_stripe_shortcode_legacy( $atts ){
* @since 1.0
*
*/
function wp_stripe_charge($amount, $card, $name, $description) {
function wp_stripe_charge($amount, $card, $name, $email, $comment) {

$options = get_option( 'wp_stripe_options' );

Expand All @@ -70,12 +71,14 @@ function wp_stripe_charge($amount, $card, $name, $description) {
'card' => $card,
'amount' => $amount,
'currency' => $currency,
'description' => $options['stripe_description'],
'receipt_email' => $email,
'metadata' => array(
'email' => $email,
'comment' => $comment,
),
);

if ( $description ) {
$charge['description'] = $description;
}

$response = Stripe_Charge::create( $charge );

return $response;
Expand Down Expand Up @@ -124,7 +127,7 @@ function wp_stripe_charge_initiate() {
// Create Charge
try {

$response = wp_stripe_charge( $amount, $card, $name, $stripe_comment );
$response = wp_stripe_charge( $amount, $card, $name, $email, sanitize_text_field( $_POST['wp_stripe_comment']) );

$id = $response->id;
$amount = $response->amount / 100;
Expand Down
14 changes: 12 additions & 2 deletions includes/stripe-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function wp_stripe_options_init() {

add_settings_section( 'wp_stripe_section_main', '', 'wp_stripe_options_header', 'wp_stripe_section' );

add_settings_field( 'stripe_header', 'Payment Form Header', 'wp_stripe_field_header', 'wp_stripe_section', 'wp_stripe_section_main' );
add_settings_field( 'stipe_header', 'Payment Form Header', 'wp_stripe_field_header', 'wp_stripe_section', 'wp_stripe_section_main' );
add_settings_field( 'stripe_description', 'Recipt description', 'wp_stripe_field_description', 'wp_stripe_section', 'wp_stripe_section_main' );
add_settings_field( 'stripe_recent_switch', 'Enable Recent Widget?', 'wp_stripe_field_recent', 'wp_stripe_section', 'wp_stripe_section_main' );
add_settings_field( 'stripe_css_switch', 'Enable Payment Form CSS?', 'wp_stripe_field_css', 'wp_stripe_section', 'wp_stripe_section_main' );
add_settings_field( 'stripe_labels_on', 'Enable Payment Form Labels?', 'wp_stripe_field_labels', 'wp_stripe_section', 'wp_stripe_section_main' );
Expand Down Expand Up @@ -68,6 +69,15 @@ function wp_stripe_field_header () {

<?php }

function wp_stripe_field_description () {

$options = get_option( 'wp_stripe_options' );
$value = $options['stripe_description']; ?>

<input id="setting_api" name="wp_stripe_options[stripe_description]" type="text" size="40" value="<?php echo esc_attr( $value ); ?>" />

<?php }

function wp_stripe_field_recent () {

$options = get_option( 'wp_stripe_options' );
Expand Down Expand Up @@ -418,4 +428,4 @@ function wp_stripe_delete_tests() {
}

}
add_action( 'admin_init', 'wp_stripe_delete_tests');
add_action( 'admin_init', 'wp_stripe_delete_tests');