MS_Widget_Login

The Membership 2 MS Widget Login class.

Defined (1)

The class is defined in the following location(s).

/app/widget/class-ms-widget-login.php  
  1. class MS_Widget_Login extends WP_Widget { 
  2.  
  3. /** 
  4. * Constructor. 
  5. * Sets up the widgets name etc. 
  6. * @since 1.1.0 
  7. */ 
  8. public function __construct() { 
  9. parent::__construct( 
  10. 'ms_widget_login',  
  11. __( '[Membership2] Login', MS_TEXT_DOMAIN ),  
  12. array( 
  13. 'description' => __( 'Display a Login Form to all guests. Logged-in users will see a Logout link.', MS_TEXT_DOMAIN ),  
  14. ); 
  15.  
  16. /** 
  17. * Outputs the content of the widget. 
  18. * @since 1.1.0 
  19. * @param array $args 
  20. * @param array $instance 
  21. */ 
  22. public function widget( $args, $instance ) { 
  23. $redirect_login = false; 
  24. $redirect_logout = false; 
  25. $shortcode_args = ''; 
  26.  
  27. if ( ! empty( $instance['redirect_login'] ) ) { 
  28. $redirect_login = lib2()->net->expand_url( $instance['redirect_login'] ); 
  29.  
  30. if ( ! empty( $instance['redirect_logout'] ) ) { 
  31. $redirect_logout = lib2()->net->expand_url( $instance['redirect_logout'] ); 
  32.  
  33. if ( ! empty( $instance['shortcode_args'] ) ) { 
  34. $shortcode_args = $instance['shortcode_args']; 
  35.  
  36. echo $args['before_widget']; 
  37.  
  38. if ( ! empty( $instance['title'] ) ) { 
  39. echo $args['before_title']; 
  40. echo apply_filters( 'widget_title', $instance['title'] ); 
  41. echo $args['after_title']; 
  42.  
  43. $scode = sprintf( 
  44. '[%1$s header="no" %2$s %3$s %4$s]',  
  45. MS_Helper_Shortcode::SCODE_LOGIN,  
  46. $redirect_login ? 'redirect_login="' . $redirect_login . '"' : '',  
  47. $redirect_logout ? 'redirect_logout="' . $redirect_logout . '"' : '',  
  48. $shortcode_args 
  49. ); 
  50. echo do_shortcode( $scode ); 
  51.  
  52. echo $args['after_widget']; 
  53.  
  54. /** 
  55. * Outputs the options form on admin 
  56. * @since 1.1.0 
  57. * @param array $instance The widget options 
  58. */ 
  59. public function form( $instance ) { 
  60. $title = __( 'Login', MS_TEXT_DOMAIN ); 
  61. $redirect_login = ''; 
  62. $redirect_logout = ''; 
  63. $shortcode_args = ''; 
  64.  
  65. if ( isset( $instance['title'] ) ) { 
  66. $title = $instance['title']; 
  67.  
  68. if ( isset( $instance['redirect_login'] ) ) { 
  69. $redirect_login = $instance['redirect_login']; 
  70.  
  71. if ( isset( $instance['redirect_logout'] ) ) { 
  72. $redirect_logout = $instance['redirect_logout']; 
  73.  
  74. if ( isset( $instance['shortcode_args'] ) ) { 
  75. $shortcode_args = $instance['shortcode_args']; 
  76.  
  77. $placeholder_login = MS_Model_Pages::get_url_after_login(); 
  78. if ( strlen( $placeholder_login ) > 55 ) { 
  79. $parts = explode( '://', $placeholder_login ); 
  80. $placeholder_login = $parts[0] . '://' . substr( $parts[1], 0, 5 ) . '…' . substr( $parts[1], -38 ); 
  81. $placeholder_logout = MS_Model_Pages::get_url_after_logout(); 
  82. if ( strlen( $placeholder_logout ) > 55 ) { 
  83. $parts = explode( '://', $placeholder_logout ); 
  84. $placeholder_logout = $parts[0] . '://' . substr( $parts[1], 0, 5 ) . '…' . substr( $parts[1], -38 ); 
  85.  
  86. $field_title = array( 
  87. 'id' => $this->get_field_id( 'title' ),  
  88. 'name' => $this->get_field_name( 'title' ),  
  89. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  90. 'title' => __( 'Title:', MS_TEXT_DOMAIN ),  
  91. 'value' => $title,  
  92. 'class' => 'widefat',  
  93. ); 
  94.  
  95. $field_redirect_login = array( 
  96. 'id' => $this->get_field_id( 'redirect_login' ),  
  97. 'name' => $this->get_field_name( 'redirect_login' ),  
  98. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  99. 'title' => __( 'Show this page after login:', MS_TEXT_DOMAIN ),  
  100. 'value' => $redirect_login,  
  101. 'placeholder' => $placeholder_login,  
  102. 'class' => 'widefat',  
  103. ); 
  104.  
  105. $field_redirect_logout = array( 
  106. 'id' => $this->get_field_id( 'redirect_logout' ),  
  107. 'name' => $this->get_field_name( 'redirect_logout' ),  
  108. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  109. 'title' => __( 'Show this page after logout:', MS_TEXT_DOMAIN ),  
  110. 'value' => $redirect_logout,  
  111. 'placeholder' => $placeholder_logout,  
  112. 'class' => 'widefat',  
  113. ); 
  114.  
  115. $field_shortcode_args = array( 
  116. 'id' => $this->get_field_id( 'shortcode_args' ),  
  117. 'name' => $this->get_field_name( 'shortcode_args' ),  
  118. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  119. 'title' => __( 'Shortcode Options:', MS_TEXT_DOMAIN ),  
  120. 'desc' => sprintf( 
  121. __( 'Arguments to pass to the %slogin shortcode%s', MS_TEXT_DOMAIN ),  
  122. sprintf( 
  123. '<a href="%s#ms-membership-login" target="_blank">',  
  124. MS_Controller_Plugin::get_admin_url( 
  125. 'help',  
  126. array( 'tab' => 'shortcodes' ) 
  127. ),  
  128. '</a>' 
  129. ),  
  130. 'value' => $shortcode_args,  
  131. 'placeholder' => 'header="no"',  
  132. 'class' => 'widefat',  
  133. ); 
  134.  
  135. MS_Helper_Html::html_element( $field_title ); 
  136. MS_Helper_Html::html_element( $field_redirect_login ); 
  137. MS_Helper_Html::html_element( $field_redirect_logout ); 
  138. MS_Helper_Html::html_element( $field_shortcode_args ); 
  139.  
  140. /** 
  141. * Processing widget options on save 
  142. * @since 1.1.0 
  143. * @param array $new_instance The new options 
  144. * @param array $old_instance The previous options 
  145. * @return array Updated safe values to be saved. 
  146. */ 
  147. public function update( $new_instance, $old_instance ) { 
  148. $instance = array(); 
  149. $instance['title'] = ''; 
  150. $instance['redirect_login'] = ''; 
  151. $instance['redirect_logout'] = ''; 
  152. $instance['shortcode_args'] = ''; 
  153.  
  154. if ( isset( $new_instance['title'] ) ) { 
  155. $instance['title'] = strip_tags( $new_instance['title'] ); 
  156.  
  157. if ( isset( $new_instance['redirect_login'] ) ) { 
  158. $instance['redirect_login'] = strip_tags( $new_instance['redirect_login'] ); 
  159.  
  160. if ( isset( $new_instance['redirect_logout'] ) ) { 
  161. $instance['redirect_logout'] = strip_tags( $new_instance['redirect_logout'] ); 
  162.  
  163. if ( isset( $new_instance['shortcode_args'] ) ) { 
  164. $instance['shortcode_args'] = strip_tags( $new_instance['shortcode_args'] ); 
  165.  
  166. return $instance;