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.6' ); 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 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 ) ) { return '

' . __( 'There are no plans associated with the Team Manager role.', 'sportspress' ) . '

'; } 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 ) ) { return '

' . __( 'There are no plans associated with the Player role.', 'sportspress' ) . '

'; } 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'] ) { ?>

  • 'sp_team', 'name' => 'sp_team', 'values' => 'ID', 'show_option_none' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Team', 'sportspress' ) ), 'class' => 'widefat', ); sp_dropdown_pages( $args ); ?>
  • __( 'Members', 'sportspress' ), 'team' => __( 'Teams', 'sportspress' ), 'player' => __( 'Players', 'sportspress' ), ); ?>