Skip to content

Commit

Permalink
Fix not redirecting to edit page after adding a snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
sheabunge committed Feb 23, 2015
1 parent 64a2863 commit 0e5bd5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
27 changes: 12 additions & 15 deletions includes/edit/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,37 @@ function code_snippets_load_single_menu() {
}

/* Save the snippet to the database */
$network = get_current_screen()->is_network;
$result = save_snippet( stripslashes_deep( $_POST ), $network );

/* Strip old status query vars from URL */
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'added', 'updated', 'activated', 'deactivated', 'invalid' ) );

/* Change the redirect URL to the edit snippet page if a new snippet was successfully added */
if ( $result && $result > 1 && ! isset( $_POST['snippet_id'] ) ) {
$_SERVER['REQUEST_URI'] = code_snippets_get_menu_url( 'edit' );
}
$result = save_snippet( stripslashes_deep( $_POST ) );

/* Build the status message and redirect */
$query_args = array();

if ( $result && isset( $_POST['save_snippet_activate'] ) ) {
/* Snippet was activated addition to saving*/
$_SERVER['REQUEST_URI'] = add_query_arg( 'activated', true );
$query_args['activated'] = true;
}
elseif ( $result && isset( $_POST['save_snippet_deactivate'] ) ) {
/* Snippet was deactivated addition to saving*/
$_SERVER['REQUEST_URI'] = add_query_arg( 'deactivated', true );
$query_args['deactivated'] = true;
}

if ( ! $result || $result < 1 ) {
/* An error occurred */
wp_redirect( add_query_arg( 'invalid', true ) );
$query_args['invalid'] = true;
}
elseif ( isset( $_POST['snippet_id'] ) ) {
/* Existing snippet was updated */
wp_redirect( add_query_arg( array( 'id' => $result, 'updated' => true ) ) );
$query_args['id'] = $result;
$query_args['updated'] = true;
}
else {
/* New snippet was added */
wp_redirect( add_query_arg( array( 'id' => $result, 'added' => true ) ) );
$query_args['id'] = $result;
$query_args['added'] = true;
}

/* Redirect to edit snippet page */
wp_redirect( add_query_arg( $query_args, code_snippets_get_menu_url( 'edit' ) ) );
}

/* Delete the snippet if the button was clicked */
Expand Down
6 changes: 3 additions & 3 deletions languages/code-snippets.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: code-snippets 2.0.0-dev\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-23 17:50+1030\n"
"POT-Creation-Date: 2015-02-23 22:26+1030\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -272,11 +272,11 @@ msgstr ""
msgid "You are not access this page."
msgstr ""

#: includes/edit/edit.php:179 includes/manage/class-list-table.php:242
#: includes/edit/edit.php:176 includes/manage/class-list-table.php:242
msgid "Description"
msgstr ""

#: includes/edit/edit.php:208 includes/manage/class-list-table.php:243
#: includes/edit/edit.php:205 includes/manage/class-list-table.php:243
msgid "Tags"
msgstr ""

Expand Down

0 comments on commit 0e5bd5e

Please sign in to comment.