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
Parameters Parameters
- $views
-
(array) (Required) array of view link HTML string
Return Return
(array)
Source Source
File: includes/admin/post-types/post-tables/class.llms.admin.post.table.instructors.php
public function get_views( $views ) {
$post_type = llms_filter_input_sanitize_string( INPUT_GET, 'post_type' );
$current_user_id = get_current_user_id();
$exclude_states = get_post_stati(
array(
'show_in_admin_all_list' => false,
)
);
global $wpdb;
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Statuses are sanitized.
$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
)
)
);
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
$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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING. |
| 4.5.1 | Use $_GET data instead of $_POST. |
| 3.35.0 | Verify nonces and sanitize $_POST data. |
| 3.24.0 | Unknown. |
| 3.13.0 | Introduced. |