Skip to content

Commit 0e5bd5e

Browse files
committed
Fix not redirecting to edit page after adding a snippet
1 parent 64a2863 commit 0e5bd5e

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

includes/edit/edit.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,40 +116,37 @@ function code_snippets_load_single_menu() {
116116
}
117117

118118
/* Save the snippet to the database */
119-
$network = get_current_screen()->is_network;
120-
$result = save_snippet( stripslashes_deep( $_POST ), $network );
121-
122-
/* Strip old status query vars from URL */
123-
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'added', 'updated', 'activated', 'deactivated', 'invalid' ) );
124-
125-
/* Change the redirect URL to the edit snippet page if a new snippet was successfully added */
126-
if ( $result && $result > 1 && ! isset( $_POST['snippet_id'] ) ) {
127-
$_SERVER['REQUEST_URI'] = code_snippets_get_menu_url( 'edit' );
128-
}
119+
$result = save_snippet( stripslashes_deep( $_POST ) );
129120

130121
/* Build the status message and redirect */
122+
$query_args = array();
131123

132124
if ( $result && isset( $_POST['save_snippet_activate'] ) ) {
133125
/* Snippet was activated addition to saving*/
134-
$_SERVER['REQUEST_URI'] = add_query_arg( 'activated', true );
126+
$query_args['activated'] = true;
135127
}
136128
elseif ( $result && isset( $_POST['save_snippet_deactivate'] ) ) {
137129
/* Snippet was deactivated addition to saving*/
138-
$_SERVER['REQUEST_URI'] = add_query_arg( 'deactivated', true );
130+
$query_args['deactivated'] = true;
139131
}
140132

141133
if ( ! $result || $result < 1 ) {
142134
/* An error occurred */
143-
wp_redirect( add_query_arg( 'invalid', true ) );
135+
$query_args['invalid'] = true;
144136
}
145137
elseif ( isset( $_POST['snippet_id'] ) ) {
146138
/* Existing snippet was updated */
147-
wp_redirect( add_query_arg( array( 'id' => $result, 'updated' => true ) ) );
139+
$query_args['id'] = $result;
140+
$query_args['updated'] = true;
148141
}
149142
else {
150143
/* New snippet was added */
151-
wp_redirect( add_query_arg( array( 'id' => $result, 'added' => true ) ) );
144+
$query_args['id'] = $result;
145+
$query_args['added'] = true;
152146
}
147+
148+
/* Redirect to edit snippet page */
149+
wp_redirect( add_query_arg( $query_args, code_snippets_get_menu_url( 'edit' ) ) );
153150
}
154151

155152
/* Delete the snippet if the button was clicked */

languages/code-snippets.pot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: code-snippets 2.0.0-dev\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2015-02-23 17:50+1030\n"
11+
"POT-Creation-Date: 2015-02-23 22:26+1030\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -272,11 +272,11 @@ msgstr ""
272272
msgid "You are not access this page."
273273
msgstr ""
274274

275-
#: includes/edit/edit.php:179 includes/manage/class-list-table.php:242
275+
#: includes/edit/edit.php:176 includes/manage/class-list-table.php:242
276276
msgid "Description"
277277
msgstr ""
278278

279-
#: includes/edit/edit.php:208 includes/manage/class-list-table.php:243
279+
#: includes/edit/edit.php:205 includes/manage/class-list-table.php:243
280280
msgid "Tags"
281281
msgstr ""
282282

0 commit comments

Comments
 (0)