membershipleveltext

Addon Name: Membership Widget Description: Membership widgets Author: Barry (Incsub) Author URI: http://caffeinatedb.com.

Defined (1)

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

/app_old/membershipincludes/addons/member.widget.php  
  1. class membershipleveltext extends WP_Widget { 
  2.  
  3. function membershipleveltext() { 
  4.  
  5. $locale = apply_filters( 'membership_locale', get_locale() ); 
  6. $mofile = membership_dir( "membershipincludes/languages/membership-$locale.mo" ); 
  7.  
  8. if ( file_exists( $mofile ) ) 
  9. load_textdomain( 'membership', $mofile ); 
  10.  
  11. $widget_ops = array( 'classname' => 'membershipleveltext', 'description' => __('Membership Level Text', 'membership') ); 
  12. $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'membershipleveltext'); 
  13. $this->WP_Widget( 'membershipleveltext', __('Membership Level Text', 'membership'), $widget_ops, $control_ops ); 
  14.  
  15. function widget( $args, $instance ) { 
  16.  
  17. extract( $args ); 
  18.  
  19. // build the check array 
  20. $defaults = array( 
  21. 'title' => '',  
  22. 'content' => '',  
  23. 'level' => 'none' 
  24. ); 
  25.  
  26. foreach($defaults as $key => $value) { 
  27. if(isset($instance[$key])) { 
  28. $defaults[$key] = $instance[$key]; 
  29.  
  30. extract($defaults); 
  31.  
  32. $show = false; 
  33.  
  34. switch($level) { 
  35.  
  36. case 'none': if(!is_user_logged_in() || !current_user_is_member()) { 
  37. $show = true; 
  38. break; 
  39.  
  40. default: if(current_user_on_level($level)) { 
  41. $show = true; 
  42. break; 
  43.  
  44.  
  45. if($show) { 
  46. echo $before_widget; 
  47. $title = apply_filters('widget_title', $title ); 
  48.  
  49. if ( !empty($title) ) { 
  50. echo $before_title . $title . $after_title; 
  51.  
  52. echo do_shortcode($content); 
  53.  
  54. echo $after_widget; 
  55.  
  56.  
  57. function update( $new_instance, $old_instance ) { 
  58. $instance = $old_instance; 
  59.  
  60. $defaults = array( 
  61. 'title' => '',  
  62. 'content' => '',  
  63. 'level' => 'none' 
  64. ); 
  65.  
  66. foreach ( $defaults as $key => $val ) { 
  67. $instance[$key] = $new_instance[$key]; 
  68.  
  69. if ( !current_user_can('unfiltered_html') ) { 
  70. $instance['content'] = stripslashes( wp_filter_post_kses( addslashes($instance['content']) ) ); // wp_filter_post_kses() expects slashed 
  71.  
  72. return $instance; 
  73.  
  74. function get_membership_levels() { 
  75.  
  76. global $wpdb; 
  77.  
  78. $sql = $wpdb->prepare( "SELECT * FROM " . membership_db_prefix($wpdb, 'membership_levels') . " WHERE level_active = %d", 1 ); 
  79.  
  80. return $wpdb->get_results($sql); 
  81.  
  82.  
  83. function form( $instance ) { 
  84.  
  85. $defaults = array( 
  86. 'title' => '',  
  87. 'content' => '',  
  88. 'level' => 'none' 
  89. ); 
  90. $instance = wp_parse_args( (array) $instance, $defaults ); 
  91.  
  92. extract($instance); 
  93.  
  94. ?> 
  95. <p> 
  96. <?php _e('Show the content below if the user is on the following level:', 'membership'); ?> 
  97. </p> 
  98. <p> 
  99. <select name='<?php echo $this->get_field_name( 'level' ); ?>' id='<?php echo $this->get_field_id( 'level' ); ?>'> 
  100. <option value='none' <?php selected($level, 'none'); ?>><?php _e('Non-member or not logged in', 'membership'); ?></option> 
  101. <?php 
  102. $levels = $this->get_membership_levels(); 
  103.  
  104. foreach($levels as $alevel) { 
  105. ?> 
  106. <option value='<?php echo $alevel->id; ?>' <?php selected($level, $alevel->id); ?>><?php echo $alevel->level_title; ?></option> 
  107. <?php 
  108. ?> 
  109. </select> 
  110. </p> 
  111. <p> 
  112. <?php _e('Title', 'membership'); ?><br/> 
  113. <input type='text' class='widefat' name='<?php echo $this->get_field_name( 'title' ); ?>' id='<?php echo $this->get_field_id( 'title' ); ?>' value='<?php echo esc_attr(stripslashes($instance['title'])); ?>' /> 
  114. </p> 
  115. <p> 
  116. <?php _e('Content', 'membership'); ?><br/> 
  117. <textarea class='widefat' name='<?php echo $this->get_field_name( 'content' ); ?>' id='<?php echo $this->get_field_id( 'content' ); ?>' rows='5' cols='40'><?php echo stripslashes($instance['content']); ?></textarea> 
  118. </p> 
  119. <?php