-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbeer-post-type.php
95 lines (72 loc) · 3.39 KB
/
beer-post-type.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
<?php
/**
* Plugin Name: Beer Directory
* Plugin URI: https://rescuethemes.com/beer-directory
* Description: Enables a beer post type and beer list shortcode.
* Version: 0.0.5
* Author: Rescue Themes
* Author URI: https://rescuethemes.com
* Text Domain: beer-directory
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
/* Copyright 2015 Rescue Themes ( email : [email protected] )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// Required files for registering the post type, taxonomies and shortcode
require plugin_dir_path( __FILE__ ) . 'includes/class-post-type.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-post-type-registrations.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-post-type-metaboxes.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-post-shortcodes.php';
require plugin_dir_path( __FILE__ ) . 'includes/scripts.php';
// Instantiate registration class, so we can add it as a dependency to main plugin class.
$post_type_registrations = new Beer_Post_Type_Registrations;
// Instantiate main plugin file, so activation callback does not need to be static.
$post_type = new Beer_Post_Type( $post_type_registrations );
// Register callback that is fired when the plugin is activated.
register_activation_hook( __FILE__, array( $post_type, 'activate' ) );
// Initialize registrations for post-activation requests.
$post_type_registrations->init();
// Initialize metaboxes
$post_type_metaboxes = new Beer_Post_Type_Metaboxes;
$post_type_metaboxes->init();
/**
* Adds styling to the dashboard for the post type and adds beer posts
* to the "At a Glance" metabox.
*/
if ( is_admin() ) {
// Loads for users viewing the WordPress dashboard
if ( ! class_exists( 'Dashboard_Glancer' ) ) {
require plugin_dir_path( __FILE__ ) . 'includes/class-dashboard-glancer.php'; // WP 3.8
}
require plugin_dir_path( __FILE__ ) . 'includes/class-post-type-admin.php';
$post_type_admin = new Beer_Post_Type_Admin( $post_type_registrations );
$post_type_admin->init();
}
/**
* Include post and page templates
*/
add_filter( 'template_include', 'beer_directory_plugin_templates' );
function beer_directory_plugin_templates( $template ) {
$post_types = array( 'beer' );
if ( is_singular( $post_types ) && ! file_exists( get_stylesheet_directory() . '/single-beer.php' ) )
$template = plugin_dir_path( __FILE__ ) . 'includes/single-beer.php';
// TODO: Add a category page template
// if ( is_post_type_archive( $post_types ) && ! file_exists( get_stylesheet_directory() . '/archive-beer.php' ) )
// $template = plugin_dir_path( __FILE__ ) . 'includes/archive-beer.php';
return $template;
}