| 1 |
<?php |
| 2 |
/** |
| 3 |
* HTML for the Manage Snippets page. |
| 4 |
* |
| 5 |
* @package Code_Snippets |
| 6 |
* @subpackage Views |
| 7 |
* |
| 8 |
* @var Manage_Menu $this |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Code_Snippets; |
| 12 |
|
| 13 |
/* Bail if accessed directly */ |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
$types = array_merge( [ 'all' => __( 'All Snippets', 'code-snippets' ) ], code_snippets()->get_types() ); |
| 19 |
|
| 20 |
$current_type = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : 'all'; |
| 21 |
$current_type = isset( $types[ $current_type ] ) ? $current_type : 'all'; |
| 22 |
|
| 23 |
?> |
| 24 |
|
| 25 |
<div class="wrap"> |
| 26 |
<h1> |
| 27 |
<?php |
| 28 |
esc_html_e( 'Snippets', 'code-snippets' ); |
| 29 |
|
| 30 |
$this->page_title_actions( code_snippets()->is_compact_menu() ? [ 'add', 'import', 'settings' ] : [ 'add', 'import' ] ); |
| 31 |
|
| 32 |
$this->list_table->search_notice(); |
| 33 |
?> |
| 34 |
</h1> |
| 35 |
|
| 36 |
<?php $this->print_messages(); ?> |
| 37 |
|
| 38 |
<h2 class="nav-tab-wrapper" id="snippet-type-tabs"> |
| 39 |
<?php |
| 40 |
|
| 41 |
foreach ( $types as $type_name => $label ) { |
| 42 |
|
| 43 |
if ( $type_name === $current_type ) { |
| 44 |
printf( '<a class="nav-tab nav-tab-active" data-type="%s">', esc_attr( $type_name ) ); |
| 45 |
} else { |
| 46 |
printf( |
| 47 |
'<a class="nav-tab" href="%s" data-type="%s">', |
| 48 |
esc_url( add_query_arg( 'type', $type_name ) ), |
| 49 |
esc_attr( $type_name ) |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
echo esc_html( $label ), 'all' === $type_name ? '' : ' <span class="badge">' . esc_html( $type_name ) . '</span>', '</a>'; |
| 54 |
} |
| 55 |
|
| 56 |
?> |
| 57 |
<a class="button button-large nav-tab-button go-pro-button" href="https://codesnippets.pro" target="_blank" |
| 58 |
title="Find more about Pro (opens in external tab)"> |
| 59 |
<?php echo wp_kses( __( 'Go <span class="badge">Pro</span>', 'code-snippets' ), [ 'span' => [ 'class' => 'badge' ] ] ); ?> |
| 60 |
<span class="dashicons dashicons-external"></span> |
| 61 |
</a> |
| 62 |
</h2> |
| 63 |
|
| 64 |
<?php |
| 65 |
$desc = code_snippets()->get_type_description( $current_type ); |
| 66 |
if ( $desc ) { |
| 67 |
echo '<p class="snippet-type-description">', esc_html( $desc ); |
| 68 |
|
| 69 |
$type_names = [ |
| 70 |
'php' => __( 'function snippets', 'code-snippets' ), |
| 71 |
'html' => __( 'content snippets', 'code-snippets' ), |
| 72 |
'css' => __( 'style snippets', 'code-snippets' ), |
| 73 |
'js' => __( 'javascript snippets', 'code-snippets' ), |
| 74 |
]; |
| 75 |
|
| 76 |
/* translators: %s: snippet type name */ |
| 77 |
$learn_more_text = sprintf( __( 'Learn more about %s →', 'code-snippets' ), $type_names[ $current_type ] ); |
| 78 |
|
| 79 |
printf( |
| 80 |
' <a href="%s" target="_blank">%s</a></p>', |
| 81 |
esc_url( "https://codesnippets.pro/learn-$current_type/" ), |
| 82 |
esc_html( $learn_more_text ) |
| 83 |
); |
| 84 |
} |
| 85 |
?> |
| 86 |
|
| 87 |
<?php |
| 88 |
do_action( 'code_snippets/admin/manage/before_list_table' ); |
| 89 |
$this->list_table->views(); |
| 90 |
?> |
| 91 |
|
| 92 |
<form method="get" action=""> |
| 93 |
<?php |
| 94 |
$this->list_table->required_form_fields( 'search_box' ); |
| 95 |
$this->list_table->search_box( __( 'Search Snippets', 'code-snippets' ), 'search_id' ); |
| 96 |
?> |
| 97 |
</form> |
| 98 |
|
| 99 |
<form method="post" action=""> |
| 100 |
<input type="hidden" id="code_snippets_ajax_nonce" |
| 101 |
value="<?php echo esc_attr( wp_create_nonce( 'code_snippets_manage_ajax' ) ); ?>"> |
| 102 |
|
| 103 |
<?php |
| 104 |
$this->list_table->required_form_fields(); |
| 105 |
$this->list_table->display(); |
| 106 |
?> |
| 107 |
</form> |
| 108 |
|
| 109 |
<?php do_action( 'code_snippets/admin/manage' ); ?> |
| 110 |
</div> |
| 111 |
|