Skip to content

Commit

Permalink
Merge pull request #1666 from xwp/develop
Browse files Browse the repository at this point in the history
Sync RC with develop
  • Loading branch information
marcinkrzeminski authored Dec 31, 2024
2 parents 25a1779 + d344661 commit 3e890ff
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 65 deletions.
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
57 changes: 35 additions & 22 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,50 @@ 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' )
) {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}

$action = wp_stream_filter_input( INPUT_POST, 'action' );
$request_method = wp_stream_filter_input( INPUT_SERVER, 'REQUEST_METHOD' );
$theme_slug = wp_stream_filter_input( INPUT_POST, 'theme' );
$plugin_slug = wp_stream_filter_input( INPUT_POST, 'plugin' );
$relative_file = wp_stream_filter_input( INPUT_POST, 'file' );

if ( ! empty( $theme_slug ) && ! check_admin_referer( 'edit-theme_' . $theme_slug . '_' . $relative_file, 'nonce' ) ) {
return;
}

if ( ! empty( $plugin_slug ) && ! check_admin_referer( 'edit-plugin_' . $relative_file, 'nonce' ) ) {
return;
}

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

$location = null;

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 );
}

if ( ! $location ) {
return;
}

$this->log_changes( $location );
}

/**
Expand Down Expand Up @@ -298,14 +314,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
20 changes: 11 additions & 9 deletions connectors/class-connector-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ public function callback_transition_post_status( $new_status, $old_status, $post
$action = 'updated';
}

$order = new \WC_Order( $post->ID );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order->get_order_number() );
$order_id = \WC_Order_Factory::get_order_id( $post->ID );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order_id );
$order_type_name = esc_html__( 'order', 'stream' );

$this->log(
Expand Down Expand Up @@ -437,8 +437,8 @@ public function callback_deleted_post( $post_id ) {
return;
}

$order = new \WC_Order( $post->ID );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order->get_order_number() );
$order_id = \WC_Order_Factory::get_order_id( $post->ID );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order_id );
$order_type_name = esc_html__( 'order', 'stream' );

$this->log(
Expand Down Expand Up @@ -495,8 +495,8 @@ public function callback_woocommerce_order_status_changed( $order_id, $old_order
'stream'
);

$order = new \WC_Order( $order_id );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order->get_order_number() );
$order_id = \WC_Order_Factory::get_order( $order_id );
$order_title = esc_html__( 'Order number', 'stream' ) . ' ' . esc_html( $order_id );
$order_type_name = esc_html__( 'order', 'stream' );

$this->log(
Expand Down Expand Up @@ -619,14 +619,16 @@ public function callback_woocommerce_tax_rate_added( $tax_rate_id, $tax_rate ) {
* @param array $tax_rate Tax Rate data.
*/
public function callback_woocommerce_tax_rate_updated( $tax_rate_id, $tax_rate ) {
$tax_rate_label = \WC_Tax::get_rate_label( $tax_rate_id );

$this->log(
/* translators: %4$s: a tax rate name (e.g. "GST") */
/* translators: %s: a tax rate name (e.g. "GST") */
_x(
'"%4$s" tax rate updated',
'"%s" tax rate updated',
'Tax rate name',
'stream'
),
$tax_rate,
array( $tax_rate_label ),
$tax_rate_id,
'tax',
'updated'
Expand Down
11 changes: 7 additions & 4 deletions connectors/class-connector-wordpress-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,18 @@ private function meta( $object_id, $meta_key, $meta_value ) {
}

$post = get_post( $object_id );
$post_type_label = get_post_type_labels( get_post_type_object( $post->post_type ) )->singular_name;
$post_type_obj = get_post_type_object( $post->post_type );
$post_type_label = is_object( $post_type_obj ) && isset( $post_type_obj->labels->singular_name )
? $post_type_obj->labels->singular_name
: $post->post_type;

$this->log(
sprintf(
/* translators: %1$s: a meta field title, %2$s: a post title, %3$s: a post type (e.g. "Description", "Hello World", "Post") */
__( 'Updated "%1$s" of "%2$s" %3$s', 'stream' ),
$this->escape_percentages( $field['title'] ),
$this->escape_percentages( $post->post_title ),
$this->escape_percentages( $post_type_label )
$this->escape_percentages( (string) $field['title'] ),
$this->escape_percentages( (string) $post->post_title ),
$this->escape_percentages( (string) $post_type_label )
),
array(
'meta_key' => $meta_key,
Expand Down
49 changes: 26 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.2",
"@wordpress/e2e-test-utils-playwright": "^1.14.0",
"@wordpress/eslint-plugin": "^21.6.0",
"@wordpress/eslint-plugin": "^22.0.0",
"@wordpress/scripts": "^30.7.0",
"copy-webpack-plugin": "^12.0.2",
"eslint-plugin-react-hooks": "^5.1.0",
Expand Down

0 comments on commit 3e890ff

Please sign in to comment.