Skip to content

Commit e27f636

Browse files
committed
Add statuses for snippet scopes. Resolves #23
1 parent 030363a commit e27f636

File tree

2 files changed

+164
-104
lines changed

2 files changed

+164
-104
lines changed

includes/manage/class-list-table.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function __construct() {
3636

3737
/* Determine the status */
3838
$status = 'all';
39-
if ( isset( $_REQUEST['status'] ) && in_array( $_REQUEST['status'], array( 'active', 'inactive', 'recently_activated' ) ) ) {
39+
$statuses = array( 'active', 'inactive', 'recently_activated', 'admin', 'frontend' );
40+
if ( isset( $_REQUEST['status'] ) && in_array( $_REQUEST['status'], $statuses ) ) {
4041
$status = $_REQUEST['status'];
4142
}
4243

@@ -312,6 +313,12 @@ function get_views() {
312313
case 'inactive':
313314
$text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count, 'code-snippets' );
314315
break;
316+
case 'admin':
317+
$text = _n( 'Admin <span class="count">(%s)</span>', 'Admin <span class="count">(%s)</span>', $count, 'code-snippets' );
318+
break;
319+
case 'frontend':
320+
$text = _n( 'Front End <span class="count">(%s)</span>', 'Front End <span class="count">(%s)</span>', $count, 'code-snippets' );
321+
break;
315322
}
316323

317324
$status_links[ $type ] = sprintf( '<a href="%s"%s>%s</a>',
@@ -566,7 +573,9 @@ function prepare_items() {
566573
'active' => array(),
567574
'inactive' => array(),
568575
'recently_activated' => array(),
569-
);
576+
'admin' => array(),
577+
'frontend' => array(),
578+
);
570579

571580
/* Filter snippets by tag */
572581
if ( isset( $_POST['tag'] ) ) {
@@ -603,6 +612,7 @@ function prepare_items() {
603612
update_option( 'recently_activated_snippets', $recently_activated );
604613
}
605614

615+
$scopes_enabled = code_snippets_get_setting( 'general', 'snippet_scope_enabled' );
606616
foreach ( (array) $snippets['all'] as $snippet ) {
607617
/* Filter into individual sections */
608618
if ( $snippet->active ) {
@@ -614,6 +624,15 @@ function prepare_items() {
614624
}
615625
$snippets['inactive'][] = $snippet;
616626
}
627+
628+
if ( $scopes_enabled ) {
629+
630+
if ( '1' == $snippet->scope ) {
631+
$snippets['admin'][] = $snippet;
632+
} elseif ( '2' == $snippet->scope ) {
633+
$snippets['frontend'][] = $snippet;
634+
}
635+
}
617636
}
618637

619638
$totals = array();
@@ -632,9 +651,9 @@ function prepare_items() {
632651
* by getting the user's setting in the Screen Options
633652
* panel.
634653
*/
635-
$sort_by = $screen->get_option( 'per_page', 'option' );
654+
$sort_by = $screen->get_option( 'per_page', 'option' );
636655
$screen_option = $screen->get_option( 'per_page', 'option' );
637-
$per_page = get_user_meta( $user, $screen_option, true );
656+
$per_page = get_user_meta( $user, $screen_option, true );
638657

639658
if ( empty ( $per_page ) || $per_page < 1 ) {
640659
$per_page = $screen->get_option( 'per_page', 'default' );

0 commit comments

Comments
 (0)