feat: add customizer option to disable post type
Introduced a new customizer setting to disable posts. This includes: - New customizer settings and controls for enabling or disabling posts. - Functions to unregister the post type and remove it from the admin menu when disabled. - Post exclusion from front-end queries when disabled. Provides flexibility for sites that may not need the post functionality.
This commit is contained in:
parent
c738ed6f89
commit
acdff85d5a
1 changed files with 50 additions and 0 deletions
|
@ -1033,3 +1033,53 @@ function preprocess_mathjax_content($content)
|
|||
}
|
||||
|
||||
add_filter('the_content', 'preprocess_mathjax_content');
|
||||
|
||||
function customize_register($wp_customize) {
|
||||
// Add setting to disable posts
|
||||
$wp_customize->add_setting('disable_posts', array(
|
||||
'default' => false,
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
// Add control for the setting
|
||||
$wp_customize->add_control('disable_posts_control', array(
|
||||
'label' => __('Disable Posts', 'duck_behavior_journal'),
|
||||
'section' => 'title_tagline',
|
||||
'settings' => 'disable_posts',
|
||||
'type' => 'checkbox',
|
||||
));
|
||||
}
|
||||
|
||||
add_action('customize_register', 'customize_register');
|
||||
|
||||
function unregister_post_type() {
|
||||
// Get the customizer setting
|
||||
$disable_posts = get_theme_mod('disable_posts', false);
|
||||
|
||||
// If the setting is enabled, unregister the post type
|
||||
if ($disable_posts) {
|
||||
unregister_post_type('post');
|
||||
}
|
||||
}
|
||||
|
||||
add_action('init', 'unregister_post_type', 20);
|
||||
|
||||
function remove_post_menu_item() {
|
||||
$disable_posts = get_theme_mod('disable_posts', false);
|
||||
if ($disable_posts) {
|
||||
remove_menu_page('edit.php');
|
||||
}
|
||||
}
|
||||
|
||||
add_action('admin_menu', 'remove_post_menu_item');
|
||||
|
||||
function exclude_posts_from_queries($query) {
|
||||
if (!is_admin() && $query->is_main_query()) {
|
||||
$disable_posts = get_theme_mod('disable_posts', false);
|
||||
if ($disable_posts) {
|
||||
$query->set('post_type', array('page'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_action('pre_get_posts', 'exclude_posts_from_queries');
|
Loading…
Reference in a new issue