Skip to content

Commit

Permalink
Use different hook to track theme and plugin files changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinkrzeminski committed Dec 20, 2024
1 parent d66e82e commit c736511
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions connectors/class-connector-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Connector_Editor extends Connector {
*/
public function register() {
parent::register();
add_action( 'load-theme-editor.php', array( $this, 'get_edition_data' ) );
add_action( 'load-plugin-editor.php', array( $this, 'get_edition_data' ) );

add_action( 'wp_ajax_edit-theme-plugin-file', array( $this, 'get_edition_data' ), 1 );
add_filter( 'wp_redirect', array( $this, 'log_changes' ) );
}

Expand Down Expand Up @@ -187,31 +187,30 @@ public function action_links( $links, $record ) {
}

/**
* Retrieves data submitted on the screen, and prepares it for the appropriate context type
* Retrieves data submitted on the screen, prepares it for the appropriate context type and logs the changes
*
* @action load-theme-editor.php
* @action load-plugin-editor.php
* @action wp_ajax_edit-theme-plugin-file
*/
public function get_edition_data() {
if (
(
isset( $_SERVER['REQUEST_METHOD'] )
&&
'POST' !== sanitize_text_field( $_SERVER['REQUEST_METHOD'] )
)
||
'update' !== wp_stream_filter_input( INPUT_POST, 'action' )
) {
$action = wp_stream_filter_input( INPUT_POST, 'action' );
$request_method = wp_stream_filter_input( INPUT_SERVER, 'REQUEST_METHOD' );

if ( ( isset( $request_method ) && 'POST' !== $request_method ) || ( 'edit-theme-plugin-file' !== $action ) ) {
return;
}

$location = null;
$theme_slug = wp_stream_filter_input( INPUT_POST, 'theme' );

if ( $theme_slug ) {
$location = 'theme-editor.php';
$this->edited_file = $this->get_theme_data( $theme_slug );
}

$plugin_slug = wp_stream_filter_input( INPUT_POST, 'plugin' );

if ( $plugin_slug ) {
$location = 'plugin-editor.php';
$this->edited_file = $this->get_plugin_data( $plugin_slug );
}
}
Expand Down

0 comments on commit c736511

Please sign in to comment.