Skip to content

Commit f7a5aa0

Browse files
committed
Fix Rewrites
adding a flush rewrite to help updates, remove the dashboard New Posts menus
1 parent 3055d7e commit f7a5aa0

File tree

3 files changed

+126
-138
lines changed

3 files changed

+126
-138
lines changed

includes/admin.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* hide the "new posts" button for admin */
2+
3+
.wp-admin.post-type-post a.page-title-action {
4+
display: none;
5+
}

includes/setup.php

Lines changed: 120 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function truwriter_setup () {
5555
wp_insert_post( $page_data );
5656
}
5757

58-
flush_rewrite_rules( );
5958
}
6059

6160
# -----------------------------------------------------------------
@@ -70,6 +69,10 @@ function truwriter_setup () {
7069
// and of course the Codex http://codex.wordpress.org/Function_Reference/add_submenu_page
7170

7271

72+
# -----------------------------------------------------------------
73+
# Dashboard menus
74+
# -----------------------------------------------------------------
75+
7376
// Here we further move the Wordpress interface from it's Post centric personality, to rename the labels for posts
7477
add_action( 'init', 'truwriter_change_post_object' );
7578

@@ -91,96 +94,115 @@ function truwriter_change_post_object() {
9194
$labels->all_items = 'All ' . $thing_name;
9295
$labels->menu_name = $thing_name;
9396
$labels->name_admin_bar = $thing_name;
97+
98+
}
99+
100+
add_action( 'admin_menu', 'truwriter_change_post_label' );
101+
102+
function truwriter_change_post_label() {
103+
global $menu;
104+
global $submenu;
105+
106+
$thing_name = 'Writing';
107+
108+
$menu[5][0] = $thing_name . 's';
109+
$submenu['edit.php'][5][0] = 'All ' . $thing_name . 's';
110+
$submenu['edit.php'][15][0] = $thing_name .' Categories';
111+
$submenu['edit.php'][16][0] = $thing_name .' Tags';
112+
echo '';
113+
}
114+
115+
// Add some menu items to the admin menu to porvide easy access to the In Progress category items
116+
// and the pending status ones
117+
118+
add_action('admin_menu', 'truwriter_drafts_menu');
119+
120+
function truwriter_drafts_menu() {
121+
add_submenu_page('edit.php', 'Writings in Progress (not submitted)', 'In Progress', 'edit_pages', 'edit.php?post_status=draft&post_type=post&cat=' . get_cat_ID( 'In Progress' ) );
122+
123+
add_submenu_page('edit.php', 'Writings Submitted for Approval', 'Pending Approval', 'edit_pages', 'edit.php?post_status=pending&post_type=post' );
124+
}
125+
126+
127+
# -----------------------------------------------------------------
128+
# Remove the New Post buttons, links from dashboard
129+
# -----------------------------------------------------------------
130+
131+
132+
add_action( 'admin_menu', 'truwriter_remove_admin_submenus', 999 );
133+
134+
function truwriter_remove_admin_submenus() {
135+
remove_submenu_page( 'edit.php', 'post-new.php' );
136+
}
137+
138+
add_action( 'admin_bar_menu', 'truwriter_remove_admin_menus', 999 );
139+
140+
function truwriter_remove_admin_menus() {
141+
global $wp_admin_bar;
142+
$wp_admin_bar->remove_node( 'new-post' );
143+
}
144+
145+
function truwriter_custom_admin_styles(){
146+
wp_enqueue_style( 'admin_css', get_stylesheet_directory_uri() . '/includes/admin.css');
94147
}
95148

149+
add_action('admin_enqueue_scripts', 'truwriter_custom_admin_styles');
150+
151+
152+
# -----------------------------------------------------------------
153+
# Redirects
154+
# -----------------------------------------------------------------
155+
96156

97157
/* set up rewrite rules */
98158
add_action('init','truwriter_rewrite_rules');
99159

100-
101160
function truwriter_rewrite_rules() {
102161
// for sending to random item
103162
add_rewrite_rule('random/?$', 'index.php?random=1', 'top');
104163

105164
// for edit link requests
106-
add_rewrite_rule( '^get-edit-link/([^/]+)/?', 'index.php?elink=1&wid=$matches[1]','top');
165+
add_rewrite_rule( '^get-edit-link/([^/]+)/?', 'index.php?elink=1&wid=$matches[1]','top');
166+
167+
// they say this is "expensive" but I know of no other way to ensure it happens on updates
168+
flush_rewrite_rules();
107169
}
108-
109-
110-
/* handle redirects */
170+
111171

112172
add_action( 'template_redirect', 'truwriter_write_director' );
113173

114174
function truwriter_write_director() {
115175

116-
if ( is_page( truwriter_get_write_page() ) and !isset( $_POST['truwriter_form_make_submitted'] ) ) {
176+
if ( is_page( truwriter_get_write_page() ) and !isset( $_POST['truwriter_form_make_submitted'] ) and !empty(truwriter_option('accesscode') ) ) {
117177

178+
// redirect for checking of access code
179+
118180
// check for query vars that indicate this is a edit request/ build qstring
119-
$wid = get_query_var( 'wid' , 0 ); // id of post
181+
$wid = get_query_var( 'wid', 0 ); // id of post
120182
$tk = get_query_var( 'tk', 0 ); // magic token to check
121183

184+
// pass argument string if we got 'em
122185
$args = ( $wid and $tk ) ? '?wid=' . $wid . '&tk=' . $tk : '';
123186

124-
// normal entry check for author
125-
if ( !is_user_logged_in() ) {
126-
// not already logged in? go to desk.
127-
wp_redirect ( home_url('/') . truwriter_get_desk_page() . $args );
128-
exit;
129-
130-
} elseif ( !current_user_can( 'edit_others_posts' ) ) {
131-
// okay user, who are you? we know you are not an admin or editor
132-
133-
// if the writer user not found, we send you to the desk
134-
if ( !truwriter_check_user() ) {
135-
// now go to the desk and check in properly
136-
wp_redirect ( home_url('/') . truwriter_get_desk_page() . $args );
137-
exit;
138-
}
139-
}
140-
187+
wp_redirect ( home_url('/') . truwriter_get_desk_page() . $args );
188+
exit;
141189
}
190+
191+
// redirect for checking access code
192+
if ( is_page( truwriter_get_desk_page() ) and isset( $_POST['truwriter_form_access_submitted'] )
193+
and wp_verify_nonce( $_POST['truwriter_form_access_submitted'], 'truwriter_form_access' ) ) {
142194

143-
if ( is_page(truwriter_get_desk_page()) ) {
144-
145-
146-
// check for query vars that indicate this is a edit request/ build qstring
147-
$wid = get_query_var( 'wid' , 0 ); // id of post
148-
$tk = get_query_var( 'tk', 0 ); // magic token to check
195+
if ( stripslashes( $_POST['wAccess'] ) == truwriter_option('accesscode') ) {
196+
197+
// check for query vars that indicate this is a edit request/ build qstring
198+
$wid = get_query_var( 'wid' , 0 ); // id of post
199+
$tk = get_query_var( 'tk', 0 ); // magic token to check
149200

150-
$args = ( $wid and $tk ) ? '?wid=' . $wid . '&tk=' . $tk : '';
201+
$args = ( $wid and $tk ) ? '?wid=' . $wid . '&tk=' . $tk : '';
151202

152-
153-
// already logged in? go directly to the tool
154-
if ( is_user_logged_in() ) {
155-
156-
if ( current_user_can( 'edit_others_posts' ) ) {
157-
// If user has edit/admin role, send them to the tool
158-
wp_redirect( splot_redirect_url() . $args );
159-
exit;
160-
161-
} else {
162-
163-
// if the correct user already logged in, go directly to the tool
164-
if ( truwriter_check_user() ) {
165-
wp_redirect( splot_redirect_url() . $args );
166-
exit;
167-
}
168-
}
169-
170-
} elseif ( truwriter_option('accesscode') == '') {
171-
splot_user_login('writer', true, $args );
203+
wp_redirect( splot_redirect_url() . $args );
172204
exit;
173-
} elseif ( isset( $_POST['truwriter_form_access_submitted'] )
174-
&& wp_verify_nonce( $_POST['truwriter_form_access_submitted'], 'truwriter_form_access' ) ) {
175-
176-
// access code from the form
177-
if ( stripslashes( $_POST['wAccess'] ) == truwriter_option('accesscode') ) {
178-
splot_user_login('writer', true, $args );
179-
exit;
180-
}
181-
182-
}
183-
205+
}
184206
}
185207

186208
if ( get_query_var('random') == 1 ) {
@@ -213,55 +235,7 @@ function truwriter_write_director() {
213235
}
214236

215237

216-
function truwriter_no_featured_image() {
217-
if ( is_page( truwriter_get_write_page() ) and isset( $_POST['truwriter_form_make_submitted'] ) ) {
218-
?>
219-
<style>
220-
.featured-media {
221-
display:none;
222-
}
223-
</style>
224-
<?php
225-
}
226-
}
227-
228-
add_action('wp_head', 'truwriter_no_featured_image');
229-
230-
231-
// filter content on writing page so we do not submit the page content if form is submitted
232-
add_filter( 'the_content', 'truwriter_firstview' );
233-
234-
function truwriter_firstview( $content ) {
235-
236-
// Check if we're inside the main loop on the writing page
237-
if ( is_page( truwriter_get_write_page() ) && in_the_loop() && is_main_query() ) {
238-
239-
if ( isset( $_POST['truwriter_form_make_submitted'] ) ) {
240-
return '';
241-
} else {
242-
return $content;
243-
}
244-
245-
}
246-
247-
return $content;
248-
}
249-
250-
251-
// Some vain attempts to manage the twitter auto logout time, make them much longer for admins
252-
// and much shorther for authors (this does not seem to work, sigh. Help me Obi Wordpress Kenobi)
253238

254-
add_filter( 'auth_cookie_expiration', 'truwriter_cookie_expiration', 99, 3 );
255-
function truwriter_cookie_expiration( $expiration, $user_id, $remember ) {
256-
257-
if ( current_user_can( 'edit_pages' ) ) {
258-
// bump up default 14 day logout function
259-
return $remember ? $expiration : 1209600;
260-
} else {
261-
// shorter auto logout for guests (2 hours)
262-
return $remember ? $expiration : 7200;
263-
}
264-
}
265239

266240
// Customize the headings for the comment form
267241
add_filter('comment_form_defaults', 'truwriter_comment_mod');
@@ -301,8 +275,6 @@ function truwriter_tinymce_2_buttons($buttons)
301275
return array_diff($buttons,$remove);
302276
}
303277

304-
305-
306278
// ----- add allowable url parameters so we can do reall cool stuff, wally
307279
add_filter('query_vars', 'truwriter_queryvars' );
308280

@@ -315,38 +287,49 @@ function truwriter_queryvars( $qvars ) {
315287
return $qvars;
316288
}
317289

318-
add_action( 'admin_menu', 'truwriter_change_post_label' );
319-
320-
function truwriter_change_post_label() {
321-
global $menu;
322-
global $submenu;
323-
324-
$thing_name = 'Writing';
325-
326-
$menu[5][0] = $thing_name . 's';
327-
$submenu['edit.php'][5][0] = 'All ' . $thing_name . 's';
328-
$submenu['edit.php'][10][0] = 'Add ' . $thing_name;
329-
$submenu['edit.php'][15][0] = $thing_name .' Categories';
330-
$submenu['edit.php'][16][0] = $thing_name .' Tags';
331-
echo '';
332-
}
333-
334-
// Add some menu items to the admin menu to porvide easy access to the In Progress category items
335-
// and the pending status ones
336-
add_action('admin_menu', 'truwriter_drafts_menu');
337290

338-
function truwriter_drafts_menu() {
339-
add_submenu_page('edit.php', 'Writings in Progress (not submitted)', 'In Progress', 'edit_pages', 'edit.php?post_status=draft&post_type=post&cat=' . get_cat_ID( 'In Progress' ) );
340-
341-
add_submenu_page('edit.php', 'Writings Submitted for Approval', 'Pending Approval', 'edit_pages', 'edit.php?post_status=pending&post_type=post' );
342-
}
343291

344292

345293

346294
# -----------------------------------------------------------------
347295
# For the Writing Form
348296
# -----------------------------------------------------------------
349297

298+
add_action('wp_head', 'truwriter_no_featured_image');
299+
300+
function truwriter_no_featured_image() {
301+
if ( is_page( truwriter_get_write_page() ) and isset( $_POST['truwriter_form_make_submitted'] ) ) {
302+
?>
303+
<style>
304+
.featured-media {
305+
display:none;
306+
}
307+
</style>
308+
<?php
309+
}
310+
}
311+
312+
313+
// filter content on writing page so we do not submit the page content if form is submitted
314+
add_filter( 'the_content', 'truwriter_firstview' );
315+
316+
function truwriter_firstview( $content ) {
317+
318+
// Check if we're inside the main loop on the writing page
319+
if ( is_page( truwriter_get_write_page() ) && in_the_loop() && is_main_query() ) {
320+
321+
if ( isset( $_POST['truwriter_form_make_submitted'] ) ) {
322+
return '';
323+
} else {
324+
return $content;
325+
}
326+
327+
}
328+
329+
return $content;
330+
}
331+
332+
350333
add_action('wp_enqueue_scripts', 'add_truwriter_scripts');
351334

352335
function add_truwriter_scripts() {

style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Theme Name: TRU Writer
33
Theme URI: https://github.com/cogdog/truwriter
44
Description: TRU Writer (Child of Radcliffe) is a SPLOT (http://splot.ca/) for rich media writing on the web suitable for essays, magazines, conference session proposals, and more. It creates a place for people to publish in a site without them needing a WordPress account or providing identifying information.
5-
Version: 1.95
5+
Version: 2.0
66
Template: radcliffe
77
Author: CogDog
88
Author URI: https://cog.dog

0 commit comments

Comments
 (0)