-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
190 lines (172 loc) · 6.22 KB
/
plugin.php
File metadata and controls
190 lines (172 loc) · 6.22 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/* Plugin name: Active Page Widgets
Plugin URI: http://www.owlwatch.com
Author: Mark Fabrizio
Author URI: http://www.owlwatch.com
Version: 1.00
Description: Allows activation / deactivation of widgets and sidebars at a per post/page level.
Max WP Version: 3.0.1
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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
*/
require_once( dirname(__FILE__).'/functions.php' );
if( !is_admin() ) add_action('wp_head', 'apw_init');
function apw_init()
{
if( is_page() || is_single() ){
global $post;
apw_setup_post($post->ID);
}
else if( is_category() || is_tag() ){
global $wp_query;
$obj = $wp_query->get_queried_object();
apw_setup_term($obj->term_id);
}
else if( is_home() ){
apw_setup_type('home');
}
else if( is_search() ){
apw_setup_type('search');
}
else{
apw_setup_type('default');
}
}
add_action('admin_menu', 'apw_admin_menu' );
function apw_admin_menu()
{
add_theme_page( __( 'Active Page Widgets', 'active-page-widgets' ), __( 'Active Page Widgets', 'active-page-widgets'),
'manage_options', 'active-page-widgets', 'apw_options' );
}
function apw_options()
{
global $hook_suffix;
$subpage = @$_REQUEST['subpage'];
if( !$subpage ) $subpage = 'default';
if( $subpage != 'options' ) apw_process($subpage);
else if( $_SERVER['REQUEST_METHOD'] == 'POST' ){
$hidden_sidebars=array();
// save the options
foreach( array_keys(apw_get_sidebars()) as $key ){
if( @$_POST['apw-sidebar-'.$key] != 1 ){
$hidden_sidebars[] = $key;
}
}
update_option('apw_hidden_sidebars', $hidden_sidebars);
}
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2 style="border-bottom: 1px solid #ccc; padding-bottom: 0;">
<a href="?page=active-page-widgets" class="nav-tab <?php echo $subpage=='default'?'nav-tab-active':''; ?>">Defaults</a>
<a href="?page=active-page-widgets&subpage=home" class="nav-tab <?php echo $subpage=='home'?'nav-tab-active':''; ?>">Home</a>
<a href="?page=active-page-widgets&subpage=search" class="nav-tab <?php echo $subpage=='search'?'nav-tab-active':''; ?>">Search</a>
<a href="?page=active-page-widgets&subpage=options" class="nav-tab <?php echo $subpage=='options'?'nav-tab-active':''; ?>">Options</a>
</h2>
<?php if( $subpage != 'options' ){ ?>
<p>Set the default widget and sidebar settings</p>
<form method="post" id="post">
<input type="hidden" name="page" value="active-page-widgets" />
<?php apw_form(apw_get_sidebars_widgets($subpage), true); ?>
<input type="submit" value="Save Settings" class="button-primary" />
</form>
<?php } else { ?>
<p>Choose which sidebars show when editing pages / posts.</p>
<form method="post" id="apw_options">
<ul>
<?php
$hidden = apw_hidden_sidebars();
foreach( apw_get_sidebars() as $key => $sidebar ){ ?>
<li>
<input <?php if(!in_array($key, $hidden)){ ?>checked<?php } ?> name="apw-sidebar-<?php echo $key; ?>" value="1" type="checkbox" id="sidebar-<?php echo $key; ?>" />
<label for="sidebar-<?php echo $key; ?>" style="padding-left: 4px;"><?php echo $sidebar['name']; ?></label>
</li>
<?php } ?>
</ul>
<input type="submit" value="Save" class="button-primary" />
</form>
<?php } ?>
</div>
<?php
}
add_action('admin_init', 'apw_admin_init');
function apw_admin_init()
{
add_meta_box('active_widgets','Active Page Widgets','apw_block_inner','page','side','low');
add_meta_box('active_widgets','Active Page Widgets','apw_block_inner','post','side','low');
}
add_action('admin_print_styles-post.php', 'apw_admin_print_styles');
add_action('admin_print_styles-post-new.php', 'apw_admin_print_styles');
add_action('admin_print_styles-edit-tags.php', 'apw_admin_print_styles');
add_action('admin_print_styles-appearance_page_active-page-widgets', 'apw_admin_print_styles');
function apw_admin_print_styles()
{
$url = plugins_url('/css/active-page-widgets.css', __FILE__ );
?>
<link rel="stylesheet" type="text/css" href="<?php echo $url; ?>" />
<?php
}
add_action('admin_print_scripts-tools.php', 'apw_admin_print_scripts');
add_action('admin_print_scripts-post.php', 'apw_admin_print_scripts');
add_action('admin_print_scripts-appearance_page_active-page-widgets', 'apw_admin_print_scripts');
function apw_admin_print_scripts()
{
$url = plugins_url('/js/active-page-widgets.js', __FILE__ );
wp_enqueue_script('apw', $url, array('jquery'), '1.0' );
}
add_action('save_post', 'apw_save_post', 10, 2);
function apw_save_post($post_ID, $post)
{
apw_process('post', $post_ID);
}
function apw_block_inner()
{
global $post_ID;
$values = true;
if( $post_ID ){
$values = apw_get_post_sidebars_widgets($post_ID);
}
apw_form($values);
}
add_action('edit_tag_form_fields', 'apw_tag_edit_form');
function apw_tag_edit_form()
{
global $tag_ID;
?>
<tr class="form-field">
<th scope="row" valign="top">
<label><?php _e('Active Widgets') ?></label>
</th>
<td>
<?php apw_form( apw_get_term_sidebars_widgets($tag_ID) ); ?>
</td>
</tr>
<?php
}
add_action('add_tag_form_fields', 'apw_tag_add_form');
add_action('category_add_form_fields', 'apw_tag_add_form');
function apw_tag_add_form()
{
?>
<div class="form-field">
<label>Active Widgets</label>
<?php apw_form( apw_get_defaults() ); ?>
</div>
<?php
}
add_action('edited_term', 'apw_edited_term', 10, 3);
add_action('created_term', 'apw_edited_term', 10, 3);
function apw_edited_term($term_id, $tt_id, $taxonomy)
{
// need to save for terms, and implement in the wp hook
apw_process( 'term', $term_id );
}