Add WordPay integration
This commit is contained in:
@@ -64,6 +64,22 @@ class SportsPress_User_Registration {
|
||||
'checkboxgroup' => 'start',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Add a team name field to signup form', 'sportspress' ),
|
||||
'id' => 'sportspress_registration_team_input',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Add a team selector to signup form', 'sportspress' ),
|
||||
'id' => 'sportspress_registration_team_select',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Create player profiles for new users', 'sportspress' ),
|
||||
'id' => 'sportspress_registration_add_player',
|
||||
@@ -85,16 +101,35 @@ class SportsPress_User_Registration {
|
||||
$last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : '';
|
||||
?>
|
||||
<p>
|
||||
<label for="first_name"><?php _e( 'First Name', 'themeboy' ) ?><br />
|
||||
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" size="25" /></label>
|
||||
<label for="first_name"><?php _e( 'First Name', 'sportspress' ) ?><br />
|
||||
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" size="25" /></label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="last_name"><?php _e( 'Last Name', 'themeboy' ) ?><br />
|
||||
<input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr( wp_unslash( $last_name ) ); ?>" size="25" /></label>
|
||||
<label for="last_name"><?php _e( 'Last Name', 'sportspress' ) ?><br />
|
||||
<input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr( wp_unslash( $last_name ) ); ?>" size="25" /></label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( 'sportspress_registration_team_select', 'no' ) ) {
|
||||
?>
|
||||
<p>
|
||||
<label for="sp_team"><?php _e( 'Team', 'sportspress' ) ?><br />
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'values' => 'ID',
|
||||
'show_option_none' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'property' => 'style="width:100%;height:36px;margin-bottom:16px"',
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
wp_nonce_field( 'submit_team', 'sp_register_form_player' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +153,27 @@ class SportsPress_User_Registration {
|
||||
}
|
||||
}
|
||||
|
||||
// Add team from team name
|
||||
if ( isset( $_POST['sp_register_form_team'] ) && wp_verify_nonce( $_POST['sp_register_form_team'], 'submit_team_name' ) ) {
|
||||
if ( ! empty( $_POST['team_name'] ) ) {
|
||||
$team_name = trim( $_POST['team_name'] );
|
||||
$post['post_type'] = 'sp_team';
|
||||
$post['post_title'] = $team_name;
|
||||
$post['post_author'] = $user_id;
|
||||
$post['post_status'] = 'draft';
|
||||
$id = wp_insert_post( $post );
|
||||
}
|
||||
}
|
||||
|
||||
// Save team
|
||||
if ( isset( $_POST['sp_register_form_player'] ) && wp_verify_nonce( $_POST['sp_register_form_player'], 'submit_team' ) ) {
|
||||
if ( ! empty( $_POST['sp_team'] ) ) {
|
||||
$team = trim( $_POST['sp_team'] );
|
||||
if ( $team <= 0 ) $team = 0;
|
||||
update_user_meta( $user_id, 'sp_team', $team );
|
||||
}
|
||||
}
|
||||
|
||||
// Add player
|
||||
if ( 'yes' === get_option( 'sportspress_registration_add_player', 'no' ) ) {
|
||||
if ( ! sizeof( $parts ) && ! empty( $_POST['user_login'] ) ) {
|
||||
@@ -129,8 +185,13 @@ class SportsPress_User_Registration {
|
||||
$post['post_type'] = 'sp_player';
|
||||
$post['post_title'] = trim( $name );
|
||||
$post['post_author'] = $user_id;
|
||||
$post['post_status'] = 'publish';
|
||||
$post['post_status'] = 'draft';
|
||||
$id = wp_insert_post( $post );
|
||||
|
||||
if ( isset( $team ) && $team ) {
|
||||
update_post_meta( $id, 'sp_team', $team );
|
||||
update_post_meta( $id, 'sp_current_team', $team );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
239
modules/sportspress-wordpay.php
Normal file
239
modules/sportspress-wordpay.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: SportsPress WordPay
|
||||
Plugin URI: http://themeboy.com/
|
||||
Description: Add team and player registration shortcodes to WordPay.
|
||||
Author: ThemeBoy
|
||||
Author URI: http://themeboy.com/
|
||||
Version: 2.3
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'SportsPress_WordPay' ) ) :
|
||||
|
||||
/**
|
||||
* Main SportsPress WordPay Class
|
||||
*
|
||||
* @class SportsPress_WordPay
|
||||
* @version 2.3
|
||||
*/
|
||||
class SportsPress_WordPay {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// Define constants
|
||||
$this->define_constants();
|
||||
|
||||
// Shortcode
|
||||
add_action( 'init', array( $this, 'add_shortcodes' ) );
|
||||
add_action( 'wpay_register_form_after_fields', array( $this, 'form_field' ) );
|
||||
|
||||
// Editor
|
||||
add_filter( 'wordpay_shortcodes', array( $this, 'editor_shortcodes' ) );
|
||||
add_filter( 'wordpay_tinymce_strings', array( $this, 'editor_strings' ) );
|
||||
|
||||
// Widgets
|
||||
add_action( 'wordpay_after_widget_register_form', array( $this, 'widget_form' ), 10, 2 );
|
||||
add_filter( 'wordpay_widget_register_update', array( $this, 'widget_update' ), 10, 2 );
|
||||
add_filter( 'wordpay_widget_register_shortcode', array( $this, 'widget_shortcode' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define constants.
|
||||
*/
|
||||
private function define_constants() {
|
||||
if ( !defined( 'SP_WORDPAY_VERSION' ) )
|
||||
define( 'SP_WORDPAY_VERSION', '2.3' );
|
||||
|
||||
if ( !defined( 'SP_WORDPAY_URL' ) )
|
||||
define( 'SP_WORDPAY_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
if ( !defined( 'SP_WORDPAY_DIR' ) )
|
||||
define( 'SP_WORDPAY_DIR', plugin_dir_path( __FILE__ ) );
|
||||
}
|
||||
/**
|
||||
* Add team and player registration shortcodes.
|
||||
*/
|
||||
public static function add_shortcodes() {
|
||||
add_shortcode( 'wpay-register-team', array( $this, 'register_team' ) );
|
||||
add_shortcode( 'wpay-register-player', array( $this, 'register_player' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Team registration shortcode.
|
||||
*/
|
||||
public static function register_team( $atts = array() ) {
|
||||
$args = array(
|
||||
'post_type' => 'wpay-subscription',
|
||||
'post_status' => 'active',
|
||||
'posts_per_page' => 500,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'wpay_subscription_plan_user_role',
|
||||
'value' => 'sp_team_manager',
|
||||
),
|
||||
),
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
$plans = get_posts( $args );
|
||||
|
||||
if ( empty( $plans ) ) {
|
||||
_e( 'There are no plans associated with the Team Manager role.', 'sportspress' );
|
||||
return;
|
||||
}
|
||||
|
||||
return self::register_form( $atts, 'team', $plans );
|
||||
}
|
||||
|
||||
/**
|
||||
* Player registration shortcode.
|
||||
*/
|
||||
public static function register_player( $atts = array() ) {
|
||||
$args = array(
|
||||
'post_type' => 'wpay-subscription',
|
||||
'post_status' => 'active',
|
||||
'posts_per_page' => 500,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'wpay_subscription_plan_user_role',
|
||||
'value' => 'sp_player',
|
||||
),
|
||||
),
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
$plans = get_posts( $args );
|
||||
|
||||
if ( empty( $plans ) ) {
|
||||
_e( 'There are no plans associated with the Player role.', 'sportspress' );
|
||||
return;
|
||||
}
|
||||
|
||||
return self::register_form( $atts, 'player', $plans );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration form template.
|
||||
*/
|
||||
public static function register_form( $atts = array(), $context = '', $plans = array() ) {
|
||||
|
||||
$atts = shortcode_atts( array(
|
||||
'plans_position' => 'bottom',
|
||||
'selected' => '',
|
||||
), $atts );
|
||||
|
||||
$atts['subscription_plans'] = implode( ',', $plans );
|
||||
|
||||
$atts['context'] = $context;
|
||||
|
||||
$shortcode = '[wpay-register';
|
||||
|
||||
foreach ( $atts as $key => $value ) {
|
||||
$shortcode .= ' ' . $key . '="' . esc_attr( $value ) . '"';
|
||||
}
|
||||
|
||||
$shortcode .= ']';
|
||||
|
||||
return do_shortcode( $shortcode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add field to registration form.
|
||||
*/
|
||||
public static function form_field( $atts = array() ) {
|
||||
if ( 'team' == $atts['context'] ) {
|
||||
?>
|
||||
<li class="wpay-field">
|
||||
<label for="wpay_team_name"><?php _e( 'Team Name', 'sportspress' ); ?></label>
|
||||
<input id="wpay_team_name" name="team_name" type="text" value="">
|
||||
</li>
|
||||
<?php
|
||||
wp_nonce_field( 'submit_team_name', 'sp_register_form_team' );
|
||||
} elseif ( 'player' == $atts['context'] ) {
|
||||
?>
|
||||
<li class="wpay-field">
|
||||
<label for="sp_team"><?php _e( 'Team', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'values' => 'ID',
|
||||
'show_option_none' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'class' => 'widefat',
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
wp_nonce_field( 'submit_team', 'sp_register_form_player' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add shortcodes to editor.
|
||||
*/
|
||||
public static function editor_shortcodes( $shortcodes = array() ) {
|
||||
$shortcodes[] = 'register_team';
|
||||
$shortcodes[] = 'register_player';
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add strings to editor.
|
||||
*/
|
||||
public static function editor_strings( $strings = array() ) {
|
||||
$strings['register_team'] = __( 'Register Team', 'sportspress' );
|
||||
$strings['register_player'] = __( 'Register Player', 'sportspress' );
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add selector to widget form.
|
||||
*/
|
||||
public static function widget_form( $widget, $instance = array() ) {
|
||||
$contexts = array(
|
||||
'' => __( 'Members', 'sportspress' ),
|
||||
'team' => __( 'Teams', 'sportspress' ),
|
||||
'player' => __( 'Players', 'sportspress' ),
|
||||
);
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $widget->get_field_id('context'); ?>"><?php _e( 'For:', 'sportspress' ); ?></label>
|
||||
<select id="<?php echo $widget->get_field_id('context'); ?>" name="<?php echo $widget->get_field_name('context'); ?>">
|
||||
<?php foreach ( $contexts as $value => $label ) { ?>
|
||||
<option value="<?php echo $value; ?>" <?php selected( $value, sp_array_value( $instance, 'context' ) ); ?>><?php echo $label; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Update widget form.
|
||||
*/
|
||||
public static function widget_update( $instance = array(), $new_instance = array() ) {
|
||||
$instance['context'] = strip_tags($new_instance['context']);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify widget shortcode.
|
||||
*/
|
||||
public static function widget_shortcode( $shortcode = '[wpay-register]', $instance = array() ) {
|
||||
if ( ! empty( $instance['context'] ) && in_array( $instance['context'], array( 'team', 'player' ) ) ) {
|
||||
$shortcode = str_replace( 'wpay-register', 'wpay-register-' . $instance['context'], $shortcode );
|
||||
}
|
||||
return $shortcode;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
if ( get_option( 'sportspress_load_wordpay_module', 'yes' ) == 'yes' ) {
|
||||
new SportsPress_WordPay();
|
||||
}
|
||||
Reference in New Issue
Block a user