Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Edits Grayed Out #1658

Merged
merged 8 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions classes/class-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ public function action_links( $links, $record ) {
/**
* Log handler
*
* @param string $message sprintf-ready error message string.
* @param array $args sprintf (and extra) arguments to use.
* @param int $object_id Target object id.
* @param string $context Context of the event.
* @param string $action Action of the event.
* @param int $user_id User responsible for the event.
* @param string $message sprintf-ready error message string.
* @param array $args sprintf (and extra) arguments to use.
* @param int|null $object_id Target object id (if any).
* @param string $context Context of the event.
* @param string $action Action of the event.
* @param int $user_id User responsible for the event.
*
* @return bool
*/
Expand Down
37 changes: 17 additions & 20 deletions connectors/class-connector-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +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_filter( 'wp_redirect', array( $this, 'log_changes' ) );

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

/**
Expand Down Expand Up @@ -187,33 +186,34 @@ 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' );

tharsheblows marked this conversation as resolved.
Show resolved Hide resolved
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 );
}

$this->log_changes( $location );
tharsheblows marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -298,14 +298,11 @@ public function get_plugin_data( $slug ) {
/**
* Logs changes
*
* @filter wp_redirect
*
* @param string $location Location.
*/
public function log_changes( $location ) {
public function log_changes( string $location ): string {
if ( ! empty( $this->edited_file ) ) {
// TODO: phpcs fix.
if ( md5_file( $this->edited_file['file_path'] ) !== $this->edited_file['file_md5'] ) {
if ( md5_file( $this->edited_file['file_path'] ) === $this->edited_file['file_md5'] ) {
$context = $this->get_context( $location );

switch ( $context ) {
Expand Down