Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds Lessons post type and Programs taxonomies. For Genesis child themes, the Primary sidebar will be replaced with a Lessons sidebar.
<?php
/*
Plugin Name: Lessons & Programs
Plugin URI:
Description: Adds Lessons post type and Programs taxonomies. For Genesis child themes, the Primary sidebar will be replaced with a Lessons sidebar.
Version: 1.0
Author: ClickWP
Author URI: https://clickwp.com
Text Domain: lessons-programs
Domain Path: /languages
*/
//* DON'T ADD ABOVE IF COPYING TO YOUR FUNCTIONS FILE
add_action('init', 'child_register_my_taxes_program');
/*
* Register Programs Taxnomy
*/
function child_register_my_taxes_program() {
$labels = array(
"name" => __("Programs", ""),
"singular_name" => __("Program", ""),
);
$args = array(
"label" => __("Programs", ""),
"labels" => $labels,
"public" => true,
"hierarchical" => true,
"label" => "Programs",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( 'slug' => 'program', 'with_front' => true, ),
"show_admin_column" => false,
"show_in_rest" => true,
"rest_base" => "program",
"show_in_quick_edit" => true,
);
register_taxonomy("program", array( "lesson" ), $args);
}
add_action('init', 'child_register_my_cpts_lesson');
/*
* Register Lessons post type
*/
function child_register_my_cpts_lesson() {
$labels = array(
"name" => __("Lessons", ""),
"singular_name" => __("Lesson", ""),
);
$args = array(
"label" => __("Lessons", ""),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => true,
"rest_base" => "",
"has_archive" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "lesson", "with_front" => true ),
"query_var" => true,
"menu_icon" => "dashicons-book",
"supports" => array( "title", "editor", "thumbnail" ),
"taxonomies" => array( "program" ),
);
register_post_type("lesson", $args);
}
add_action( 'genesis_init', 'child_lessons_theme_supports' );
/*
* Add theme supports to Lessons
*/
function child_lessons_theme_supports() {
add_post_type_support( 'lesson', array(
'genesis-cpt-archives-settings', // Archive settings
'genesis-layouts', // In-post layout settings
'genesis-seo', // In-post SEO settings
'genesis-scripts', // In-post script options
) );
}
add_action( 'genesis_before', 'child_remove_lesson_meta', 11 );
/*
* Remove post info and meta for Lessons
*/
function child_remove_lesson_meta() {
// Remove post info
remove_post_type_support( 'lesson', 'genesis-entry-meta-before-content' );
// Remove post meta
remove_post_type_support( 'lesson', 'genesis-entry-meta-after-content' );
}
add_action('genesis_setup', 'child_lessons_sidebar_setup');
/*
* Setup Lessons Sidebar
* Loaded on genesis_setup hook to ensure genesis_ functions are available
*/
// Swap sidebars on CPT pages
function child_maybe_do_lessons_sidebar() {
if (is_singular('lesson') || is_post_type_archive('lesson') || is_tax('program')) {
remove_action('genesis_sidebar', 'genesis_do_sidebar'); // Remove the default genesis sidebar
add_action('genesis_sidebar', 'child_do_lesson_sidebar'); // Add the custom sidebar instead
}
}
// Output lesson sidebar
function child_do_lesson_sidebar() {
genesis_widget_area('sidebar-lesson');
}
function child_lessons_sidebar_setup() {
genesis_register_sidebar(
array(
'name'=>'Lessons Sidebar',
'id' => 'sidebar-lesson',
'description' => 'This is a sidebar displayed on Lessons and Programs only',
)
);
// Swap sidebars on Lessons
add_action('get_header', 'child_maybe_do_lessons_sidebar');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment