-
-
Save skmezanul/cdd92d5a1b2f0adf52d5072a2006c06e to your computer and use it in GitHub Desktop.
Provides a shortcode to add the Pro Sites checkout form in any page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This is great! But, I have no idea what to do with this code. Do I just upload it onto the wordpress site and it integrates with Pro Sites? I am not a programmer but this is something that could be a very big help for me