| @@ -1,73 +1,159 @@ | ||
| 1 | 1 | <?php |
| 2 | -add_action('widgets_init', 'uwp_init_register_widget'); | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 3 | 5 | |
| 4 | -function uwp_init_register_widget() { | |
| 6 | +/** | |
| 7 | + * UsersWP register widget. | |
| 8 | + * | |
| 9 | + * @since 1.0.0 | |
| 10 | + */ | |
| 11 | +class UWP_Register_Widget extends WP_Super_Duper { | |
| 5 | 12 | |
| 6 | - register_widget("UWP_Register_Widget"); | |
| 13 | + /** | |
| 14 | + * Register the registration widget with WordPress. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + public function __construct() { | |
| 7 | 18 | |
| 8 | -} | |
| 19 | + $options = array( | |
| 20 | + 'textdomain' => 'userswp', | |
| 21 | + 'block-icon' => 'admin-site', | |
| 22 | + 'block-category' => 'widgets', | |
| 23 | + 'block-keywords' => "['userswp','register']", | |
| 24 | + 'class_name' => __CLASS__, | |
| 25 | + 'base_id' => 'uwp_register', | |
| 26 | + 'name' => __( 'UWP > Register', 'userswp' ), | |
| 27 | + 'widget_ops' => array( | |
| 28 | + 'classname' => 'uwp-register-class bsui', | |
| 29 | + 'description' => esc_html__( 'Displays register form.', 'userswp' ), | |
| 30 | + ), | |
| 31 | + 'arguments' => array( | |
| 32 | + 'id' => array( | |
| 33 | + 'title' => __( 'Form', 'userswp' ), | |
| 34 | + 'desc' => __( 'Select form.', 'userswp' ), | |
| 35 | + 'type' => 'select', | |
| 36 | + 'options' => uwp_get_register_forms_dropdown_options(), | |
| 37 | + 'default' => 1, | |
| 38 | + 'desc_tip' => true, | |
| 39 | + 'advanced' => false | |
| 40 | + ), | |
| 41 | + 'limit' => array( | |
| 42 | + 'title' => __( 'Display form having IDs', 'userswp' ), | |
| 43 | + 'desc' => __( 'Enter comma separeted IDs to show limited forms', 'userswp' ), | |
| 44 | + 'type' => 'text', | |
| 45 | + 'desc_tip' => true, | |
| 46 | + 'default' => '', | |
| 47 | + 'advanced' => true | |
| 48 | + ), | |
| 49 | + 'title' => array( | |
| 50 | + 'title' => __( 'Widget title', 'userswp' ), | |
| 51 | + 'desc' => __( 'Enter widget title.', 'userswp' ), | |
| 52 | + 'type' => 'text', | |
| 53 | + 'desc_tip' => true, | |
| 54 | + 'default' => '', | |
| 55 | + 'advanced' => true | |
| 56 | + ), | |
| 57 | + 'form_title' => array( | |
| 58 | + 'title' => __( 'Form Title', 'userswp' ), | |
| 59 | + 'desc' => __( 'Enter the form title (or "0" for no title)', 'userswp' ), | |
| 60 | + 'type' => 'text', | |
| 61 | + 'desc_tip' => true, | |
| 62 | + 'default' => '', | |
| 63 | + 'placeholder' => __( 'Register', 'userswp' ), | |
| 64 | + 'advanced' => true | |
| 65 | + ), | |
| 66 | + 'redirect_to' => array( | |
| 67 | + 'type' => 'text', | |
| 68 | + 'title' => __( 'Redirect to:', 'userswp' ), | |
| 69 | + 'desc' => __( 'Enter the url you want to redirect after register.', 'userswp' ), | |
| 70 | + 'placeholder' => '', | |
| 71 | + 'default' => '', | |
| 72 | + 'desc_tip' => true, | |
| 73 | + 'advanced' => true | |
| 74 | + ), | |
| 75 | + 'design_style' => array( | |
| 76 | + 'title' => __( 'Design Style', 'userswp' ), | |
| 77 | + 'desc' => __( 'The design style to use.', 'userswp' ), | |
| 78 | + 'type' => 'select', | |
| 79 | + 'options' => array( | |
| 80 | + "" => __( 'default', 'userswp' ), | |
| 81 | + "bootstrap" => __( 'Style 1', 'userswp' ), | |
| 82 | + ), | |
| 83 | + 'default' => '', | |
| 84 | + 'desc_tip' => true, | |
| 85 | + 'advanced' => true | |
| 86 | + ), | |
| 87 | + 'css_class' => array( | |
| 88 | + 'type' => 'text', | |
| 89 | + 'title' => __( 'Extra class:', 'userswp' ), | |
| 90 | + 'desc' => __( 'Give the wrapper an extra class so you can style things as you want.', 'userswp' ), | |
| 91 | + 'placeholder' => '', | |
| 92 | + 'default' => '', | |
| 93 | + 'desc_tip' => true, | |
| 94 | + 'advanced' => true, | |
| 95 | + ), | |
| 96 | + ) | |
| 9 | 97 | |
| 10 | -class UWP_Register_Widget extends WP_Super_Duper { | |
| 98 | + ); | |
| 11 | 99 | |
| 12 | - public function __construct() { | |
| 100 | + parent::__construct( $options ); | |
| 101 | + } | |
| 13 | 102 | |
| 14 | - $options = array( | |
| 15 | - 'textdomain' => 'userswp', | |
| 16 | - 'block-icon' => 'admin-site', | |
| 17 | - 'block-category'=> 'widgets', | |
| 18 | - 'block-keywords'=> "['userswp','register']", | |
| 19 | - 'class_name' => __CLASS__, | |
| 20 | - 'base_id' => 'uwp_register', | |
| 21 | - 'name' => __('UWP > Register','userswp'), | |
| 22 | - 'widget_ops' => array( | |
| 23 | - 'classname' => 'uwp-register-class', | |
| 24 | - 'description' => esc_html__('Displays register form.','userswp'), | |
| 25 | - ), | |
| 26 | - 'arguments' => array( | |
| 27 | - 'title' => array( | |
| 28 | - 'title' => __( 'Register widget title', 'userswp' ), | |
| 29 | - 'desc' => __( 'Enter register widget title.', 'userswp' ), | |
| 30 | - 'type' => 'text', | |
| 31 | - 'desc_tip' => true, | |
| 32 | - 'default' => '', | |
| 33 | - 'advanced' => false | |
| 34 | - ), | |
| 35 | - ) | |
| 103 | + /** | |
| 104 | + * The Super block output function. | |
| 105 | + * | |
| 106 | + * @param array $args | |
| 107 | + * @param array $widget_args | |
| 108 | + * @param string $content | |
| 109 | + * | |
| 110 | + * @return mixed|string|bool | |
| 111 | + */ | |
| 112 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { | |
| 36 | 113 | |
| 37 | - ); | |
| 114 | + if ( is_user_logged_in() && ! is_admin() ) { | |
| 115 | + return false; | |
| 116 | + } | |
| 38 | 117 | |
| 39 | - parent::__construct( $options ); | |
| 40 | - } | |
| 118 | + $defaults = array( | |
| 119 | + 'form_title' => __( 'Register', 'userswp' ), | |
| 120 | + 'css_class' => 'border-0', | |
| 121 | + 'redirect_to' => '', | |
| 122 | + ); | |
| 41 | 123 | |
| 42 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { | |
| 124 | + /** | |
| 125 | + * Parse incoming $args into an array and merge it with $defaults | |
| 126 | + */ | |
| 127 | + $args = wp_parse_args( $args, $defaults ); | |
| 43 | 128 | |
| 44 | - if (is_user_logged_in()) { | |
| 45 | - return; | |
| 46 | - } | |
| 129 | + if(isset($_REQUEST['user_type']) && !empty($_REQUEST['user_type'])){ | |
| 130 | + $args['id'] = uwp_get_form_id_by_type(sanitize_text_field($_REQUEST['user_type'])); | |
| 131 | + } | |
| 47 | 132 | |
| 48 | - ob_start(); | |
| 133 | + if(isset($_REQUEST['uwp_form_id']) && !empty($_REQUEST['uwp_form_id'])){ | |
| 134 | + $args['id'] = absint($_REQUEST['uwp_form_id']); | |
| 135 | + } | |
| 49 | 136 | |
| 50 | - echo '<div class="uwp_widgets uwp_widget_register">'; | |
| 137 | + ob_start(); | |
| 51 | 138 | |
| 52 | - $temp_obj = new UsersWP_Templates(); | |
| 139 | + echo '<div class="uwp_widgets uwp_widget_register">'; | |
| 53 | 140 | |
| 54 | - $template = $temp_obj->uwp_locate_template('register'); | |
| 141 | + $design_style = ! empty( $args['design_style'] ) ? esc_attr( $args['design_style'] ) : uwp_get_option( "design_style", 'bootstrap' ); | |
| 142 | + $template = $design_style ? $design_style . "/register.php" : "register.php"; | |
| 55 | 143 | |
| 56 | - echo '<div class="uwp_page">'; | |
| 144 | + echo '<div class="uwp_page wpbs">'; | |
| 57 | 145 | |
| 58 | - if ($template) { | |
| 59 | - include($template); | |
| 60 | - } | |
| 146 | + uwp_get_template( $template, $args ); | |
| 61 | 147 | |
| 62 | - echo '</div>'; | |
| 148 | + echo '</div>'; | |
| 63 | 149 | |
| 64 | - echo '</div>'; | |
| 150 | + echo '</div>'; | |
| 65 | 151 | |
| 66 | - $output = ob_get_contents(); | |
| 152 | + if(!wp_doing_ajax()){ | |
| 153 | + uwp_password_strength_inline_js(); | |
| 154 | + } | |
| 67 | 155 | |
| 68 | - ob_end_clean(); | |
| 156 | + return ob_get_clean(); | |
| 69 | 157 | |
| 70 | - return trim($output); | |
| 71 | - | |
| 72 | - } | |
| 158 | + } | |
| 73 | 159 | } |