/
admin.php
102 lines (83 loc) · 3.24 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Admin functions.
*
* @package News
* @subpackage Functions
*/
add_action( 'admin_menu', 'news_admin_setup', 11 );
/**
* Sets up the admin functionality for the News theme.
*
* @since 0.2.0
*/
function news_admin_setup() {
$prefix = hybrid_get_prefix();
$settings_page = hybrid_get_settings_page_name();
/* Load theme settings meta boxes. */
add_action( "load-{$settings_page}", 'news_create_settings_meta_boxes' );
/* Validate theme settings. */
add_filter( "sanitize_option_{$prefix}_theme_settings", 'news_validate_theme_settings' );
/* Flush rewrite rules for custom post types. */
add_action( 'load-themes.php', 'news_flush_rewrite_rules' );
}
/**
* Flushes the rewrite rules on theme activation so that custom post type permalinks work correctly.
*
* @since 0.1.0
*/
function news_flush_rewrite_rules() {
global $pagenow, $wp_rewrite;
if ( 'themes.php' == $pagenow && isset( $_GET['activated'] ) )
$wp_rewrite->flush_rules();
}
/**
* Validates the theme settings.
*
* @since 0.1.0
*/
function news_validate_theme_settings( $settings ) {
$settings['home_template_categories'] = ( ( isset( $settings['home_template_categories'] ) && is_array( $settings['home_template_categories'] ) ) ? array_map( 'absint', $settings['home_template_categories'] ) : array() );
return $settings;
}
/**
* Add meta boxes to the theme settings page.
*
* @since 0.1.0
*/
function news_create_settings_meta_boxes() {
add_meta_box( "news-home-template-meta-box", __( 'Home Page Template Settings', 'news' ), 'news_home_template_theme_meta_box', 'appearance_page_theme-settings', 'normal', 'low' );
}
/**
* Display the home template meta box.
*
* @since 0.1.0
*/
function news_home_template_theme_meta_box() {
$prefix = hybrid_get_prefix();
/* Settings used. */
$category_highlight = hybrid_get_setting( 'home_template_categories' );
/* Get categories. */
$categories = get_categories(); ?>
<table class="form-table">
<tr>
<th><?php _e( 'About:', 'news' ); ?></th>
<td>
<?php _e( 'Settings used on pages that use the "Home" page template. This template must be assigned to a page before its settings take effect.', 'news' ); ?>
</td>
</tr>
<tr>
<th><label for="<?php echo hybrid_settings_field_id( 'home_template_categories' ); ?>"><?php _e( 'Category Highlight:', 'news' ); ?></label></th>
<td>
<label for="<?php echo hybrid_settings_field_id( 'home_template_categories' ); ?>"><?php _e( 'Categories to show blog posts from in the category highlight section. Multiple categories may be chosen by holding the <code>Ctrl</code> key and selecting.', 'news' ); ?></label>
<br />
<select id="<?php echo hybrid_settings_field_id( 'home_template_categories' ); ?>" name="<?php echo hybrid_settings_field_name( 'home_template_categories' ); ?>[]" multiple="multiple" style="height:150px;">
<?php foreach( $categories as $cat ) { ?>
<option value="<?php echo $cat->term_id; ?>" <?php if ( is_array( $category_highlight ) && in_array( $cat->term_id, $category_highlight ) ) echo ' selected="selected"'; ?>><?php echo esc_html( $cat->name ); ?></option>
<?php } ?>
</select>
</td>
</tr>
</table><?php
}
?>