Skip to content

Commit 2b9d268

Browse files
committed
Load all admin stylesheets from the same function; add settings screen stylesheet
1 parent e3daae5 commit 2b9d268

File tree

8 files changed

+145
-118
lines changed

8 files changed

+145
-118
lines changed
File renamed without changes.
File renamed without changes.

css/settings.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.form-table th {
3+
font-weight: normal;
4+
}
5+
6+
#code_snippets_editor_preview .CodeMirror {
7+
height: 200px;
8+
}

includes/admin.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,38 @@ function code_snippets_mu_menu_items( $menu_items ) {
8484

8585
add_filter( 'mu_menu_items', 'code_snippets_mu_menu_items' );
8686

87+
/**
88+
* Enqueue the stylesheet for a snippet menu
89+
*
90+
* @since 2.2.0
91+
* @uses wp_enqueue_style() To add the stylesheet to the queue
92+
* @param string $hook The current page hook
93+
*/
94+
function code_snippets_enqueue_admin_stylesheet( $hook ) {
95+
$pages = array( 'manage', 'add', 'edit', 'settings' );
96+
$hooks = array_map( 'code_snippets_get_menu_hook', $pages );
97+
98+
/* Only load the stylesheet on the right snippets page */
99+
if ( ! in_array( $hook, $hooks ) ) {
100+
return;
101+
}
102+
103+
$hooks = array_combine( $hooks, $pages );
104+
$page = $hooks[ $hook ];
105+
106+
// add snippet page uses edit stylesheet
107+
if ( 'add' === $page ) $page = 'edit';
108+
109+
wp_enqueue_style(
110+
"code-snippets-$page",
111+
plugins_url( "css/min/$page.css", CODE_SNIPPETS_FILE ),
112+
false,
113+
CODE_SNIPPETS_VERSION
114+
);
115+
}
116+
117+
add_action( 'admin_enqueue_scripts', 'code_snippets_enqueue_admin_stylesheet' );
118+
87119
/**
88120
* Enqueue the icon stylesheet globally in the admin
89121
*

includes/edit/edit.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function code_snippets_add_single_menu() {
3838
'code_snippets_render_single_menu'
3939
);
4040

41+
add_action( 'load-' . $add_hook, 'code_snippets_load_single_menu' );
42+
4143
/* Check if we are currently editing a snippet */
4244
if ( isset( $_REQUEST['page'] ) && code_snippets_get_menu_slug( 'edit' ) === $_REQUEST['page'] ) {
4345

@@ -52,8 +54,6 @@ function code_snippets_add_single_menu() {
5254

5355
add_action( 'load-' . $edit_hook, 'code_snippets_load_single_menu' );
5456
}
55-
56-
add_action( 'load-' . $add_hook, 'code_snippets_load_single_menu' );
5757
}
5858

5959
add_action( 'admin_menu', 'code_snippets_add_single_menu', 5 );
@@ -337,15 +337,6 @@ function code_snippets_enqueue_codemirror() {
337337
$codemirror_version
338338
);
339339

340-
/* Plugin Assets */
341-
342-
wp_enqueue_style(
343-
'code-snippets-edit',
344-
plugins_url( 'css/min/edit-snippet.css', CODE_SNIPPETS_FILE ),
345-
false,
346-
CODE_SNIPPETS_VERSION
347-
);
348-
349340
/* CodeMirror Theme */
350341

351342
$theme = code_snippets_get_setting( 'editor', 'theme' );
@@ -391,7 +382,4 @@ function code_snippets_enqueue_codemirror() {
391382
array( 'code-snippets-tagit' ),
392383
$tagit_version
393384
);
394-
395-
/* Needed for resizable editor functionality */
396-
wp_enqueue_script( 'jquery-ui-resizable' );
397385
}

includes/manage/manage.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ function code_snippets_load_manage_menu() {
6767
wp_die( __( 'You are not authorized to access this page.', 'code-snippets' ) );
6868
}
6969

70-
/* Load stylesheet for this page */
71-
add_action( 'admin_enqueue_scripts', 'code_snippets_manage_menu_assets' );
72-
7370
/* Create the snippet tables if they don't exist */
7471
create_code_snippets_tables();
7572

@@ -83,28 +80,6 @@ function code_snippets_load_manage_menu() {
8380
$code_snippets_list_table->prepare_items();
8481
}
8582

86-
/**
87-
* Enqueue the manage menu stylesheet
88-
*
89-
* @since 2.0
90-
* @uses wp_enqueue_style() To add the stylesheet to the queue
91-
* @param string $hook The current page hook, to be compared with the manage snippets page hook
92-
*/
93-
function code_snippets_manage_menu_assets( $hook ) {
94-
95-
/* Only load the stylesheet on the manage snippets page */
96-
if ( code_snippets_get_menu_hook() !== $hook ) {
97-
return;
98-
}
99-
100-
wp_enqueue_style(
101-
'code-snippets-manage',
102-
plugins_url( 'css/min/manage-snippets.css', CODE_SNIPPETS_FILE ),
103-
false,
104-
CODE_SNIPPETS_VERSION
105-
);
106-
}
107-
10883
/**
10984
* Handles saving the user's snippets per page preference
11085
*

includes/settings/editor-preview.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ function example_custom_admin_footer_text( \$text ) {
115115
} );
116116

117117
<?php break;
118-
case 'checkbox': ?>
118+
case 'checkbox': ?>
119119

120120
$( 'input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
121121
editor.setOption( '<?php echo $att_name; ?>', $(this).is(':checked') );
122122
} );
123123

124124
<?php break;
125-
case 'number': ?>
125+
case 'number': ?>
126126

127127
$( 'input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
128128
editor.setOption( '<?php echo $att_name; ?>', $(this).val() );

0 commit comments

Comments
 (0)