';
echo $args['after_widget'];
}
}
class WP_Builders_Log {
const BUILDERS_LOG_TAXONOMY = 'airplane_section';
static $instance = false;
public static function getInstance() {
if (! self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
// Make sure custom slugs work for airplane sections
add_action('admin_init', 'flush_rewrite_rules');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
// Add a new taxonomy for airplane sections. This will be used to force selection of
// only a single airplane section at a time (to simplify time tracking).
// Otherwise these are pretty much the same as categories.
add_action('init', array(__CLASS__, 'register_taxonomy_plane_section'));
// Remove the default controls for adding an airplane section to a post.
add_action('admin_menu', array(__CLASS__, 'remove_default_airplane_section_meta_box'));
// Add new controls that use radio buttons rather than multi-select.
add_action('add_meta_boxes_post', array(__CLASS__, 'add_airplane_section_meta_box'));
// script to keep radio buttons in sync on admin meta box form
add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_script'));
// Allow admins to add new airplane sections from the post edit page
add_action('wp_ajax_radio_tax_add_taxterm', array(__CLASS__,'ajax_add_term'));
// Add a new box to the post add/edit page to record hours and minutes spent
add_action('add_meta_boxes_post', array(__CLASS__, 'add_build_time_meta_box'));
add_action('save_post', array($this, 'save_build_time_meta_box'));
// Setup the widget
add_action('widgets_init', function(){
register_widget('WP_Builders_Log_Widget');
});
}
public static function remove_default_airplane_section_meta_box() {
remove_meta_box('tagsdiv-' . self::BUILDERS_LOG_TAXONOMY, 'post', 'normal');
}
public static function add_airplane_section_meta_box() {
add_meta_box(
'tagsdiv-new-airplane_section', // div id
__('Airplane Section'), // title
array(__CLASS__, 'airplane_section_meta_box'), // callback
'post','normal','high' // post type, context, priority
);
}
public static function airplane_section_meta_box($post) {
$tax_obj = get_taxonomy(self::BUILDERS_LOG_TAXONOMY);
$input_name = 'tax_input[' . self::BUILDERS_LOG_TAXONOMY . ']';
$all_terms = get_terms(self::BUILDERS_LOG_TAXONOMY, array('hide_empty' => 0));
$popular_terms = get_terms(self::BUILDERS_LOG_TAXONOMY, array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
'hierarchical' => false
));
$post_terms = get_the_terms($post->ID, self::BUILDERS_LOG_TAXONOMY);
$current_term = ($post_terms ? array_pop($post_terms) : false);
$current_term_id = ($current_term ? $current_term->term_id : false);
?>