-
Notifications
You must be signed in to change notification settings - Fork 0
/
onlist.php
152 lines (134 loc) · 4.61 KB
/
onlist.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Plugin Name: OnList
* Description: Online Listing and Business Directory
* Version: 1.0.6
* Author: Tradesouthwest
* Author URI: http://tradesouthwest.com
* Filters and Actions hooks are loaded on this page.
*/
// If this file is called directly, abort.
defined( 'ABSPATH' ) or die( 'X' );
if (!defined('ONLIST_VER')) { define('ONLIST_VER', '1.0.6'); }
if (!defined('ONLIST_URL')) { define( 'ONLIST_URL', plugin_dir_url(__FILE__)); }
/**
* Upon plugin activation, always make sure init hook for a CPT
* has ran first or you will have to run `flush_rewrite()`.
*/
//create custom post type
function onlist_custom_post_type()
{
include( 'inc/onlist-plugin-post-type.php' );
}
add_action( 'init', 'onlist_custom_post_type' );
//create custom taxonomy
function onlist_custom_tax_init()
{
include( 'inc/onlist-plugin-post-taxo.php' );
register_taxonomy( 'onlist-taxonomy', 'onlist_post', $args);
}
add_action( 'init', 'onlist_custom_tax_init' );
//group terms functions
include 'inc/onlist-manage-terms.php';
remove_filter( 'map_meta_cap', 'onlist_map_meta_cap', 11, 4 );
remove_action('pre_get_posts', 'onlist_users_own_attachments');
remove_filter('pre_get_posts', 'onlist_posts_for_current_author');
//enqueue or localise scripts
function onlist_public_style()
{
wp_enqueue_style( 'onlist-style', ONLIST_URL
. '/css/onlist-style.css',array(), ONLIST_VER, false );
}
add_action( 'wp_enqueue_scripts', 'onlist_public_style' );
//load language scripts
function onlist_load_text_domain()
{
load_plugin_textdomain( 'onlist', false,
basename( dirname( __FILE__ ) ) . '/languages' );
}
//activate plugin
function onlist_plugin_activate()
{
$t=time();
$time = date("Y-m-d",$t);
add_option( 'onlist_date_plugin_activated' );
update_option( 'onlist_date_plugin_activated', $time );
flush_rewrite_rules();
}
//activate plugin
function onlist_plugin_reactivate()
{
flush_rewrite_rules();
}
//deactivation settings
function onlist_plugin_deactivate()
{
delete_option( 'onlist_date_plugin_activated' );
/* Flush rewrite rules for custom post types. */
flush_rewrite_rules();
return false;
}
//ready, set, go
register_activation_hook(__FILE__, 'onlist_plugin_activate');
register_deactivation_hook(__FILE__, 'onlist_plugin_deactivate');
add_action( 'after_switch_theme', 'onlist_plugin_reactivate' );
/**
* Admin side specific
* @since 1.0.0
*
* top level menu
*/
if( is_admin() ) :
function onlist_admin_style()
{
wp_enqueue_style( 'onlist-admin', ONLIST_URL
. '/css/onlist-admin.css',array(), ONLIST_VER, false );
}
add_action( 'admin_enqueue_scripts', 'onlist_admin_style' );
require_once 'admin/onlist-admin-forms.php';
require_once 'admin/onlist-plugin-admin.php';
endif;
// Register the Metabox
function onlist_add_custom_meta_box()
{
add_meta_box( 'onlist-meta-box', // Unique ID
__( 'OnList Entry', 'onlist' ), // Title
'onlist_meta_box_output', // Callback function
'onlist_post', // Admin page (or post type)
'normal', // Context
'high' // Priority
);
}
add_action( 'add_meta_boxes', 'onlist_add_custom_meta_box' );
//output metabox to editor pages
function onlist_meta_box_output()
{
//setup the editor post pages and display
//include 'inc/onlist-option-groups.php';
include 'admin/onlist-editor-page.php';
}
//save the meta data
function onlist_save_postdata($post_id)
{
include 'admin/onlist-public-settings.php';
}
add_action( 'save_post', 'onlist_save_postdata', 10, 2 );
//add_action( 'save_post', 'onlist_assign_parent_terms', 10, 2 );
// check for thumbnail support
if ( !current_theme_supports( 'post-thumbnails' ) ) {
add_theme_support( 'post-thumbnails' );
add_post_type_support( 'onlist_post', 'thumbnail' );
}
//and the rest of the files
include 'public/onlist-public-view.php';
//include templater
include 'inc/onlist-templater.php';
include 'inc/onlist-page-helpers.php';
include 'inc/Onlist_Widget.php';
//register shortcodes
function onlist_register_shortcodes() {
add_shortcode( 'onlist-listings', 'onlist_display_public_view' );
add_shortcode( 'onlist-categories', 'onlist_display_category_widget' );
}
add_action( 'init', 'onlist_register_shortcodes' );
?>