LLMS_Admin_Post_Table_Instructors::get_views( array $views )

Ensure that the “Mine” view quick link at the top of the table displays the correct number Most of this is based on WordPress core functions found in wp-admin/includes/class-wp-posts-list-table.php


Description Description


Parameters Parameters

$views

(array) (Required) array of view link HTML string


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/post-types/post-tables/class.llms.admin.post.table.instructors.php

	public function get_views( $views ) {

		$post_type = sanitize_text_field( $_GET['post_type'] );

		$current_user_id = get_current_user_id();

		$exclude_states = get_post_stati( array(
			'show_in_admin_all_list' => false,
		) );

		global $wpdb;
		$count = intval( $wpdb->get_var( $wpdb->prepare( "
			SELECT COUNT( 1 )
			FROM $wpdb->posts AS p
			JOIN $wpdb->postmeta AS m
			  ON p.ID = m.post_id
			 AND m.meta_key = '_llms_instructors'
			 AND m.meta_value LIKE %s
			WHERE p.post_type = %s
			  AND p.post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
		", '%' . $this->get_serialized_id( $current_user_id ) . '%', $post_type ) ) );

		$label = sprintf(
			_nx(
				'Mine <span class="count">(%s)</span>',
				'Mine <span class="count">(%s)</span>',
				$count,
				'posts',
				'lifterlms'
			),
			number_format_i18n( $count )
		);

		$url = add_query_arg( array(
			'post_type' => $post_type,
			'author' => $current_user_id,
		), 'edit.php' );

		$class = '';
		if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
			$class = 'class="current"';
		}

		// if mine doesn't already exist in views, we need to add it after "All" manually
		// to preserve the user experience
		if ( ! isset( $views['mine'] ) ) {

			$offset = array_search( 'all', array_keys( $views ) );
			$add = array(
				'mine' => '',
			);
			$views = array_slice( $views, 0, $offset + 1 ) + $add + array_slice( $views, $offset + 1 );

		}

		$views['mine'] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', esc_url( $url ), $class, $label );

		return $views;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.13.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.