forked from jgwhite/wp-broadbean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroadbean.php
147 lines (126 loc) · 4.36 KB
/
broadbean.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
<?php
/*
Plugin Name: Broadbean
Plugin URI: http://github.com/jgwhite/wp-broadbean
Description: Provides endpoint and integration for Broadbean AdCourier.
Version: 1.0
Author: Jamie White
Author URI: http://jgwhite.co.uk/
License: MIT
Copyright (C) 2012 Jamie White, Lawrence Brown
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
class Broadbean {
const basename = 'broadbean/broadbean.php';
function activate() {
self::add_rewrite_rule();
flush_rewrite_rules();
}
function deactivate() {
global $wp_rewrite;
unset($wp_rewrite->non_wp_rules['broadbean-inbox$']);
flush_rewrite_rules();
}
function init() {
self::create_post_type();
}
function admin_init() {
self::register_settings();
self::add_rewrite_rule();
}
function admin_menu() {
add_submenu_page(
'options-general.php',
'Broadbean',
'Broadbean',
'manage_options',
'broadbean',
array('Broadbean', 'render_admin_menu')
);
}
function create_post_type() {
register_post_type('job',
array(
'labels' => array(
'name' => __( 'Jobs' ),
'singular_name' => __( 'Job' )
),
'public' => true,
'has_archive' => true,
'taxonomies' => array(
'post_tag',
'category'
),
'supports' => array(
'title',
'editor',
'revisions',
'author',
'excerpt',
'thumbnail',
'custom-fields'
)
)
);
}
function register_settings() {
register_setting('broadbean_settings', 'broadbean_username');
register_setting('broadbean_settings', 'broadbean_password');
}
function add_rewrite_rule() {
$url = plugins_url('inbox.php', self::basename);
$url = str_replace(site_url(), '', $url);
$url = preg_replace('/^\/+/', '', $url);
add_rewrite_rule('broadbean-inbox$', $url, 'top');
}
function action_links($links) {
array_unshift($links, '<a href="options-general.php?page=broadbean">Settings</a>');
return $links;
}
function render_admin_menu() {
?>
<div class="wrap">
<h2>Broadbean Settings</h2>
<form method="post" action="options.php">
<?php settings_fields('broadbean_settings') ?>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><label for="broadbean_username">Username</label></th>
<td><input type="text" name="broadbean_username" id="broadbean_username"
value="<?php echo get_option('broadbean_username') ?>"></td>
</tr>
<tr valign="top">
<th scope="row"><label for="broadbean_password">Password</label></th>
<td><input type="text" name="broadbean_password" id="broadbean_password"
value="<?php echo get_option('broadbean_password') ?>"></td>
</tr>
</tbody>
</table>
<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"></p>
</form>
</div>
<?php
}
}
register_activation_hook(Broadbean::basename, array('Broadbean', 'activate'));
register_deactivation_hook(Broadbean::basename, array('Broadbean', 'deactivate'));
add_filter('plugin_action_links_'.Broadbean::basename, array('Broadbean', 'action_links'));
add_action('init', array('Broadbean', 'init'));
add_action('admin_init', array('Broadbean', 'admin_init'));
add_action('admin_menu', array('Broadbean', 'admin_menu'));
?>