function help_notes_available( ) {
		
		$helpnote_post_types = array( );
		
		$role_based_help_notes = RBHN_Role_Based_Help_Notes::get_instance( ); 
			
		// check if no help notes are selected.
		$help_note_post_types =  get_option( 'rbhn_post_types' );

		if ( ! array_filter( ( array ) $help_note_post_types ) && ! get_option( 'rbhn_general_enabled' ) )
			return false;

		//if the current user has the role of an active Help Note.
		if ( array_filter( ( array ) $help_note_post_types ) ) {	
			foreach( $help_note_post_types as $array ) {
				foreach( $array as $active_role=>$active_posttype ) {
					if ( $role_based_help_notes->help_notes_current_user_has_role( $active_role ) ) {
						$helpnote_post_types[] = $active_posttype;
					}				
				}
			}	
		}   

		// General Help Notes
		$my_query = new WP_Query( array(
			'post_type'     => array( 'h_general' ),
			) );

		if ( $my_query->have_posts( ) ) {
			$helpnote_post_types[] = 'h_general';
			}
			
		wp_reset_postdata( );
		
		

		$helpnote_post_types = array_filter( $helpnote_post_types );
		if ( ! empty( $helpnote_post_types ) ) {
			return $helpnote_post_types;
		} else {
			return false;
		}
	}
	/**
	 * Front-end display of widget.
	 *
	 * @see WP_Widget::widget( )
	 *
	 * @param array $args     Widget arguments.
	 * @param array $instance Saved values from database.
	 */	 
	public function widget( $args, $instance ) {
	
		$role_based_help_notes = RBHN_Role_Based_Help_Notes::get_instance( );

       // drop out if not a single Help Note page or Help Hote Archive page.
       // or the General Help Note Type
       $show_widget_help_notes = $role_based_help_notes->active_help_notes( );
       $exclude_help_notes = array( 'h_general' );
       $show_widget_help_notes = array_diff( $show_widget_help_notes, $exclude_help_notes );
       
        if ( ! in_array( get_post_type( ),  $show_widget_help_notes ) )
            return; 

		$post_type = get_post_type( );
		$help_note_object = get_post_type_object( $post_type );
		$help_note_name = $help_note_object->labels->menu_name;
		
		if ( empty( $instance['title'] ) ) {
			$title = sprintf( _x( '%1$s Topics', 'the topics tag cloud for a single role' , 'role-based-help-notes-text-domain' ), $help_note_name );
		} else {
			$title = $instance['title'];
		}
		
		echo $args['before_widget'];
		if ( ! empty( $title ) )
			echo $args['before_title'] . $title . $args['after_title'];
 /*       
		if ( $title )
			echo $before_title . $title . $after_title;
*/
		echo '<div class="tagcloud">';

		wp_tag_cloud( apply_filters( 'rbhn_tag_cloud_widget_args', array( 'taxonomy' => $post_type . 'topics' ) ) );

		echo "</div>";

		echo $args['after_widget'];
	}
示例#3
0
	/**
	 * field_help_notes_taxonomy_option 
	 *
	 * @param array of arguments to pass the option name to render the form field.
	 * @access public
	 * @return void
	 */
	public function field_help_notes_taxonomy_options( array $args  ) {
		$option   = $args['option'];
		
		//  loop through the site roles and create a custom post for each
		global $wp_roles;
		$role_based_help_notes = RBHN_Role_Based_Help_Notes::get_instance( );
		$value = get_option( $option['name'] );
		
		if ( ! isset( $wp_roles ) ) {
			$wp_roles = new WP_Roles( );
		}

		$roles = $wp_roles->get_names( );
		unset( $wp_roles );
		
		?><ul><?php 
		asort( $roles );
		foreach( $roles as $role_key=>$role_name )
		{
			$id = sanitize_key( $role_key );
			
			$post_type_name = $role_based_help_notes->clean_post_type_name( $role_key );
			$role_active = $this->rbhn_role_active( $role_key, ( array ) $value )

			// Render the output  
			?> 
			<li><label>
			<input type='checkbox'  
				id="<?php echo esc_html( "help_notes_{$id}" ) ; ?>" 
				name="<?php echo esc_html( $option['name'] ); ?>[][<?php echo esc_html( $role_key ) ; ?>]"
				value="<?php echo esc_attr( $post_type_name )	; ?>"<?php checked( $role_active ); ?>
			>
			<?php echo esc_html( $role_name ) . " <br/>"; ?>	
			</label></li>
			<?php 
		}?></ul><?php 
		if ( ! empty( $option['desc'] ) )
			echo ' <p class="description">' . esc_html( $option['desc'] ) . '</p>';		
	}
	/**
	 * Front-end display of widget.
	 *
	 * @see WP_Widget::widget( )
	 *
	 * @param array $args     Widget arguments.
	 * @param array $instance Saved values from database.
	 */
	public function widget( $args, $instance ) {
	
		$role_based_help_notes = RBHN_Role_Based_Help_Notes::get_instance( );

       // drop out if not a single Help Note page or Help Hote Archive page.
       // or the General Help Note Type
       $show_widget_help_notes = $role_based_help_notes->active_help_notes( );
       $exclude_help_notes = array( 'h_general' );
       $show_widget_help_notes = array_diff( $show_widget_help_notes, $exclude_help_notes );
       
        if ( ! in_array( get_post_type( ),  $show_widget_help_notes ) || is_archive( ) )
            return; 

		$post_type = get_post_type( );
		$help_note_object = get_post_type_object( $post_type );
		$help_note_name = $help_note_object->labels->menu_name;
		
		if ( empty( $instance['title'] ) ) {
			$title = sprintf( __( '%1$s Line-up', 'role-based-help-notes-text-domain' ), $help_note_name );
		} else {
			$title = $instance['title'];
		}
		
		echo $args['before_widget'];
		if ( ! empty( $title ) )
			echo $args['before_title'] . $title . $args['after_title'];
        
		// Find the users of the role based on the post type in use
		$post_type = get_post_type( );
    	$help_note_role = $role_based_help_notes->help_notes_role( $post_type );
        $users = get_users( Array( 'role' => $help_note_role ) );

		/* If users were found. */
		if ( !empty( $users ) ) {
            
			echo '<ul class="xoxo users">';

			/* Loop through each available user, creating a list item with a link to the user's archive. */
			foreach ( $users as $user ) {

				$url_found = '';
				$user_id = $user->ID;

                $my_query = new WP_Query( array(
                    'author'        => $user_id,
                    'post_type'     => get_post_types( array( 'public' => true ) ),
                    'post_status'   => 'publish',
					) );

				if ( $my_query->have_posts( ) ) {
					$url_found = get_author_posts_url( $user_id, $user->user_nicename );
				}

				$url = apply_filters( 'rbhn_author_url', $url_found , $user_id );	

				$class = "user-{$user->ID}";
				if ( is_author( $user->ID ) )
					$class .= ' current-user';

				if ( ! empty( $url ) ) {
					echo "<li class='{$class}'><a href='{$url}' title='" . esc_attr( $user->display_name ) . "'>{$user->display_name}</a></li>\n";
				} else {
					echo "<li class='{$class}'>{$user->display_name}</li>\n";		
				}
			}

			echo '</ul>';
		}

		echo $args['after_widget'];
		wp_reset_postdata( );
	}
	/**
     * Creates or returns an instance of this class.
     *
     * @return   A single instance of this class.
     */
    public static function get_instance( ) {
 
        if ( null == self::$instance ) {
            self::$instance = new self;
        }
        return self::$instance;
    }
	/**
	 * rbhn_clean_inactive_capabilties function.
	 *
	 * @access public
	 * @return void
	 */
	public static function rbhn_clean_inactive_capabilties( ) {

		// collect an array of all inactive Help Note Post Types an remove capabilities
		$post_types_array = get_option( 'rbhn_post_types' );  
		
		$role_based_help_notes = RBHN_Role_Based_Help_Notes::get_instance( );
		$active_roles = $role_based_help_notes->help_notes_role( );

		// Find capabilities already built.
		$caps_options = get_option( 'rbhn_caps_created' );
		if ( ! empty( $caps_options ) ) {
			foreach( $caps_options as $cap_built ) {

				// capabilities have been built so stop further re-builds.
				if ( $cap_built && ! in_array( $cap_built, $active_roles ) ) {

					// clean up the capabilities 
					self::rbhn_role_caps_cleanup( $cap_built );
					
					// remove the removed $cap_built from the built capabilities array 
					$caps_options = array_diff( $caps_options, array( $cap_built ) );
					update_option( 'rbhn_caps_created', $caps_options ); 
				}	
			}
		}
	}