Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wpmudev-sls/0eb4d6e64b2c57f30b0aa9f31759e909 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/0eb4d6e64b2c57f30b0aa9f31759e909 to your computer and use it in GitHub Desktop.
Provides a shortcode to add the Pro Sites checkout form in any page
<?php
/*
Plugin Name: Pro Sites - Checkout Shortcode
Plugin URI: https://premium.wpmudev.org/
Description: Provides a shortcode to add the Pro Sites checkout form in any page
Author: Panos Lyrakis @ WPMUDEV
Author URI: https://premium.wpmudev.org/
License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PS_Checkout_Shortcode' ) ) {
class PS_Checkout_Shortcode {
private static $_instance = null;
public static function get_instance() {
if( is_null( self::$_instance ) ){
self::$_instance = new PS_Checkout_Shortcode();
}
return self::$_instance;
}
private function __construct() {
if( ! class_exists('ProSites') ){
return;
}
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_shortcode( 'pro_checkout', array( $this, 'load_checkout_form' ) );
}
public function load_checkout_form( $atts, $content = null ){
global $psts;
return $psts->checkout_output($content);
}
public function enqueue_scripts(){
global $psts, $post;
if ( ! $post instanceof WP_POST || ! has_shortcode( $post->post_content, 'pro_checkout' ) ){
return;
}
$stripe_secret_key = $psts->get_setting( 'stripe_secret_key' );
$stripe_publishable_key = $psts->get_setting( 'stripe_publishable_key' );
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_style( 'proSite-custom-checkout', get_site_url().'/wp-content/plugins/pro-sites/pro-sites-files/css/checkout.css' );
wp_enqueue_style( 'proSite-option-1', get_site_url().'/wp-content/plugins/pro-sites/pro-sites-files/css/pricing-tables/option1.css' );
wp_enqueue_style( 'proSite-custom', get_site_url().'/wp-content/plugins/pro-sites/pro-sites-files/css/plans-pricing.css' );
wp_enqueue_script( 'psts-checkout', $psts->plugin_url . 'js/checkout.js', array( 'jquery' ), $psts->version );
wp_localize_script( 'psts-checkout', 'prosites_checkout', array(
'ajax_url' => ProSites_Helper_ProSite::admin_ajax_url(),
'confirm_cancel' => __( "Please note that if you cancel your subscription you will not be immune to future price increases. The price of un-canceled subscriptions will never go up!\n\nAre you sure you really want to cancel your subscription?\nThis action cannot be undone!", 'psts'),
'button_signup' => __( "Sign Up", 'psts' ),
'button_choose' => __( "Choose Plan", 'psts' ),
'button_chosen' => __( "Chosen Plan", 'psts' ),
'logged_in' => is_user_logged_in(),
'new_blog' => ProSites_Helper_ProSite::allow_new_blog() ? 'true' : 'false'
) );
wp_enqueue_script( 'psts-checkout-2', get_site_url() . '/wp-content/plugins/pro-sites/pro-sites-files/js/tax.js', array( 'jquery' ), time() );
wp_enqueue_script( 'js-stripe', 'https://js.stripe.com/v2/', array( 'jquery' ) );
wp_enqueue_script( 'stripe-token', $psts->plugin_url . 'gateways/gateway-stripe-files/stripe_token.js', array(
'js-stripe',
'jquery'
) );
wp_localize_script( 'stripe-token', 'stripe', array(
'publisher_key' => $stripe_publishable_key,
'name' => __( 'Please enter the full Cardholder Name.', 'psts' ),
'number' => __( 'Please enter a valid Credit Card Number.', 'psts' ),
'expiration' => __( 'Please choose a valid expiration date.', 'psts' ),
'cvv2' => __( 'Please enter a valid card security code. This is the 3 digits on the signature panel, or 4 digits on the front of Amex cards.', 'psts' )
) );
add_action( 'wp_head', array( 'ProSites_Gateway_Stripe', 'checkout_js' ) );
}
}
add_action( 'plugins_loaded', function(){
$GLOBALS['PS_Checkout_Shortcode'] = PS_Checkout_Shortcode::get_instance();
}, 10 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment