Created
February 5, 2018 19:26
-
-
Save justinkuepper/c550de53f24895e76dd44c11d8495fc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Featured Leaders | |
Plugin URI: http://www.asdf.com | |
Description: Creates featured leaders. | |
Version: 1.0 | |
Author: Justin | |
Author URI: https://www.asdf.com | |
License: GPLv2 | |
*/ | |
add_action('init', 'create_featured_leaders'); | |
add_action('admin_init', 'featured_leader_admin'); | |
add_action('save_post', 'add_featured_leader_fields', 10, 2); | |
function create_featured_leaders() | |
{ | |
register_post_type('featured_leaders', array( | |
'labels' => array( | |
'name' => 'Featured Leaders', | |
'singular_name' => 'Featured Leader', | |
'add_new' => 'Add New', | |
'add_new_item' => 'Add New Featured Leader', | |
'edit' => 'Edit', | |
'edit_item' => 'Edit Featured Leader', | |
'new_item' => 'New Featured Leader', | |
'view' => 'View', | |
'view_item' => 'Featured Leader', | |
'search_items' => 'Search Featured Leaders', | |
'not_found' => 'No Featured Leaders Found', | |
'not_found_in_trash' => 'No Featured Leaders Found in Trash', | |
'parent' => 'Parent Featured Leader' | |
), | |
'public' => true, | |
'menu_position' => 15, | |
'supports' => array( 'title', 'editor', 'thumbnail' ), | |
'taxonomies' => array( '' ), | |
'has_archive' => true | |
)); | |
} | |
function featured_leader_admin() | |
{ | |
add_meta_box('featured_leader_meta_box', 'CDB ID No.', 'display_featured_leader_meta_box', 'featured_leaders', 'normal', 'high'); | |
} | |
function display_featured_leader_meta_box($featured_leader) | |
{ | |
$cdb_id_number = esc_html(get_post_meta($featured_leader->ID, 'cdb_id_number', true)); ?> | |
<table> | |
<tr> | |
<td style="width: 100%">CDB ID No.</td> | |
<td><input type="text" size="80" name="cdb_id_number" value="<?php echo $cdb_id_number; ?>" /></td> | |
</tr> | |
</table> | |
<?php | |
} | |
function add_featured_leader_fields($featured_leader_id, $featured_leader) | |
{ | |
if ($featured_leader->post_type == 'featured_leaders') { | |
if (isset($_POST['cdb_id_number'])) { | |
update_post_meta($featured_leader_id, 'cdb_id_number', $_POST['cdb_id_number']); | |
} | |
} | |
} | |
function include_leader_template_function($template_path) | |
{ | |
if (get_post_type() == 'featured_leaders') { | |
if (is_single()) { | |
if ($theme_file = locate_template('single-featured-leader.php')) { | |
$template_path = $theme_file; | |
} else { | |
$template_path = plugin_dir_path(__FILE__) . 'single-featured-leader.php'; | |
} | |
} | |
} | |
return $template_path; | |
} | |
add_filter('template_include', 'include_leader_template_function', 1); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment