Skip to content

Commit

Permalink
Fix broken snippet code verification functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sheabunge committed Feb 27, 2017
1 parent ee3cb12 commit e0590b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
29 changes: 0 additions & 29 deletions php/admin-menus/class-edit-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public function __construct() {
public function run() {
parent::run();
$this->remove_debug_bar_codemirror();

if ( isset( $_POST['save_snippet'] ) && $_POST['save_snippet'] ) {
add_action( 'code_snippets/allow_execute_snippet', array( $this, 'prevent_exec_on_save' ), 10, 2 );
}

}

/**
Expand All @@ -46,30 +41,6 @@ public function register() {
);
}

/**
* Prevent the snippet currently being saved from being executed
* so it is not run twice (once normally, once
*
* @param bool $exec Whether the snippet will be executed
* @param int $exec_id The ID of the snippet being executed
*
* @return bool Whether the snippet will be executed
*/
function prevent_exec_on_save( $exec, $exec_id ) {

if ( ! isset( $_POST['save_snippet'], $_POST['snippet_id'] ) ) {
return $exec;
}

$id = intval( $_POST['snippet_id'] );

if ( $id == $exec_id ) {
return false;
}

return $exec;
}

/**
* Executed when the menu is loaded
*/
Expand Down
28 changes: 28 additions & 0 deletions php/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function run() {
add_filter( 'plugin_action_links_' . plugin_basename( CODE_SNIPPETS_FILE ), array( $this, 'plugin_settings_link' ) );
add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 2 );
add_action( 'code_snippets/admin/manage', array( $this, 'survey_message' ) );

if ( isset( $_POST['save_snippet'] ) && $_POST['save_snippet'] ) {
add_action( 'code_snippets/allow_execute_snippet', array( $this, 'prevent_exec_on_save' ), 10, 2 );
}
}

/**
Expand Down Expand Up @@ -99,6 +103,30 @@ function enqueue_admin_stylesheet( $hook ) {
);
}

/**
* Prevent the snippet currently being saved from being executed
* so it is not run twice (once normally, once
*
* @param bool $exec Whether the snippet will be executed
* @param int $exec_id The ID of the snippet being executed
*
* @return bool Whether the snippet will be executed
*/
function prevent_exec_on_save( $exec, $exec_id ) {

if ( ! isset( $_POST['save_snippet'], $_POST['snippet_id'] ) ) {
return $exec;
}

$id = intval( $_POST['snippet_id'] );

if ( $id == $exec_id ) {
return false;
}

return $exec;
}

/**
* Adds a link pointing to the Manage Snippets page
*
Expand Down

0 comments on commit e0590b5

Please sign in to comment.