Skip to content
Open

Release #1421

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7f6ddb4
Sync branch [skip ci]
pirate-bot Nov 25, 2026
aa77bd9
Sync branch [skip ci]
pirate-bot Nov 25, 2026
5a425f1
fix: escape the attributes of chart action buttons
vytisbulkevicius Nov 26, 2026
94cbd14
fix: protect the chart meta keys
vytisbulkevicius Nov 26, 2026
3944494
fix: delete only the chart's own image when the image changes
vytisbulkevicius Nov 26, 2026
34d8ed6
chore(deps-dev): bump phpstan/phpstan from 2.3.6 to 2.3.7 (#1420)
dependabot[bot] Nov 26, 2026
4146ed3
ci: remove the linked-issue check
selul Nov 26, 2026
9c38d23
chore(deps): bump codeinwp/themeisle-sdk from 3.3.73 to 3.3.74 (#1423)
dependabot[bot] Nov 27, 2026
b9dbb61
test: cover the key and title of a filtered action
vytisbulkevicius Nov 27, 2026
02e5897
fix: clear the chart image reference when image saving is off
vytisbulkevicius Nov 28, 2026
313eed7
Merge pull request #1424 from Codeinwp/bugfix/pro/652
vytisbulkevicius Dec 1, 2026
2983567
Merge pull request #1426 from Codeinwp/bugfix/pro/654
vytisbulkevicius Dec 1, 2026
56c9201
Merge remote-tracking branch 'origin/development' into bugfix/pro/653
vytisbulkevicius Dec 1, 2026
1ae1c4c
fix: a copied chart does not take the image of its source chart
vytisbulkevicius Dec 1, 2026
9708978
test: cover deleting the chart's own image and keeping another chart'…
vytisbulkevicius Dec 1, 2026
f3b8301
Merge pull request #1425 from Codeinwp/bugfix/pro/653
vytisbulkevicius Dec 1, 2026
672790f
fix: keep the saved JSON source credentials on the server
vytisbulkevicius Dec 1, 2026
bc1b558
fix: use saved JSON credentials for their exact endpoint and its orig…
vytisbulkevicius Dec 1, 2026
35d8e82
fix: show a saved chart image only for the chart it was saved for
vytisbulkevicius Dec 1, 2026
f9b0fab
fix: give the stored rows of an unpublished post-type chart only to u…
vytisbulkevicius Dec 1, 2026
176ff0c
test: give the chart of the rows test the settings that the chart edi…
vytisbulkevicius Dec 1, 2026
c140af8
test: give the chart of the credentials test stored rows
vytisbulkevicius Dec 1, 2026
d6ec928
fix: keep the stored rows when a user who cannot read them saves a ma…
vytisbulkevicius Dec 2, 2026
73e94c5
fix: keep the chart image after WordPress renames its edited file
vytisbulkevicius Dec 2, 2026
f3d4be1
fix: use GET for a JSON request that brings no method with the saved …
vytisbulkevicius Dec 2, 2026
19b1284
fix: accept only the image name suffixes that WordPress adds
vytisbulkevicius Dec 2, 2026
f05ac70
fix: refuse every upload that removes a query its user cannot read
vytisbulkevicius Dec 2, 2026
2407951
test: describe every accepted suffix
vytisbulkevicius Dec 2, 2026
a4b27ef
fix: bind saved JSON credentials to their endpoint and keep them out …
vytisbulkevicius Dec 2, 2026
1cc2ae9
fix: keep saved JSON credentials out of the ability log and match the…
vytisbulkevicius Dec 2, 2026
0c66115
fix: save the endpoint of JSON credentials beside them
vytisbulkevicius Dec 2, 2026
37c1ded
test: cover the deletion of an edited chart image
vytisbulkevicius Dec 2, 2026
d3b6643
fix: keep unreadable rows out of the revision comparison and the char…
vytisbulkevicius Dec 2, 2026
2ffa5cf
ci: install the plugins of the e2e tests after wp-env starts
vytisbulkevicius Dec 2, 2026
88c1d05
fix: check both sides of a chart revision comparison
vytisbulkevicius Dec 2, 2026
243d590
test: date the older chart revision before the chart
vytisbulkevicius Dec 2, 2026
1557394
test: compare two chart revisions
vytisbulkevicius Dec 2, 2026
149cea3
Merge pull request #1432 from Codeinwp/bugfix/1431
vytisbulkevicius Dec 2, 2026
2fb7ef9
Merge remote-tracking branch 'origin/development' into HEAD
vytisbulkevicius Dec 2, 2026
f6ed9f6
Merge remote-tracking branch 'origin/development' into bugfix/pro/668
vytisbulkevicius Dec 2, 2026
0c99490
Merge remote-tracking branch 'origin/development' into bugfix/pro/669
vytisbulkevicius Dec 2, 2026
03a2b67
Merge pull request #1428 from Codeinwp/bugfix/pro/666
vytisbulkevicius Dec 2, 2026
5751f11
Merge pull request #1429 from Codeinwp/bugfix/pro/668
vytisbulkevicius Dec 2, 2026
5fafc69
Merge remote-tracking branch 'origin/development' into bugfix/pro/669
vytisbulkevicius Dec 2, 2026
8f6eb6c
fix: keep no saved image for an unpublished chart with a post-type query
vytisbulkevicius Dec 2, 2026
dd72a30
fix: delete the image of an unpublished chart for each order of its meta
vytisbulkevicius Dec 2, 2026
56fb503
refactor: delete the chart image without a retry branch
vytisbulkevicius Dec 2, 2026
a863162
Merge pull request #1422 from Codeinwp/ci/remove-linked-issue-check
selul Dec 2, 2026
2d39dca
fix: apply the rows rule to XML-RPC and keep the slice settings of a …
vytisbulkevicius Dec 2, 2026
a37c367
test: read the post fields through XML-RPC
vytisbulkevicius Dec 2, 2026
d3db263
fix: apply the rows rule to each XML-RPC method and to the revisions …
vytisbulkevicius Dec 2, 2026
4fb6d13
Correct the comment on when the XML-RPC filter runs
vytisbulkevicius Dec 2, 2026
1161fff
Merge pull request #1430 from Codeinwp/bugfix/pro/669
vytisbulkevicius Dec 2, 2026
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
49 changes: 0 additions & 49 deletions .github/workflows/pr_verify_linked_issue.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
run: composer install --no-dev
- name: Start wp-env
run: npx wp-env start
- name: Install the plugins the tests need
# The afterStart script of .wp-env.json installs them too, but they do not stay on the runner.
run: npx wp-env run tests-cli wp plugin install classic-editor elementor --activate
- name: Run the tests
run: |
npm run test:e2e:playwright
Expand Down
6 changes: 5 additions & 1 deletion classes/Visualizer/Gutenberg/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function get_visualizer_data( $post ) {
$data['visualizer-data'] = Visualizer_Module::sanitize_chart_data(
apply_filters(
Visualizer_Plugin::FILTER_GET_CHART_DATA,
Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ),
Visualizer_Module::can_read_chart_rows( $post_id ) ? Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ) : array(),
$post_id,
$data['visualizer-chart-type']
)
Expand Down Expand Up @@ -427,6 +427,10 @@ public function get_visualizer_data( $post ) {
if ( ! empty( $json_url ) ) {
$data['visualizer-json-schedule'] = $json_schedule;
$data['visualizer-json-url'] = $json_url;
// The saved credentials stay on the server.
if ( is_array( $json_headers ) ) {
unset( $json_headers['auth'], $json_headers['auth_url'] );
}
$data['visualizer-json-headers'] = $json_headers;
$data['visualizer-json-root'] = $json_root;

Expand Down
153 changes: 145 additions & 8 deletions classes/Visualizer/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,16 +878,76 @@ public static function maybe_decode_content( $value ) {
return is_serialized( $value ) ? self::decode_content( $value ) : $value;
}

/**
* Tells whether the current user can read the stored rows of a chart.
*
* A post-type chart of the Pro plugin stores post titles and meta values of posts in any status.
* A published chart shows its rows to everyone who can see it. The rows of an unpublished chart are for
* users who can read every post of the type: the post type has an admin screen, and the user can edit
* its posts of other users and read its private posts. This is the rule the Pro plugin has for the query.
*
* @param int $chart_id The chart ID, or the ID of a chart revision.
* @return bool
*/
public static function can_read_chart_rows( $chart_id ) {
if ( self::has_public_rows( $chart_id ) ) {
return true;
}

$filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true );
$post_type = is_array( $filter_config ) && isset( $filter_config['type'] ) && is_string( $filter_config['type'] ) ? get_post_type_object( $filter_config['type'] ) : null;
return $post_type instanceof WP_Post_Type
&& $post_type->show_ui
&& current_user_can( $post_type->cap->edit_others_posts )
&& current_user_can( $post_type->cap->read_private_posts );
}

/**
* Tells whether everyone who can see a chart can read its stored rows: the chart has no post-type query, or it is published.
*
* @param int $chart_id The chart ID, or the ID of a chart revision.
* @return bool
*/
public static function has_public_rows( $chart_id ) {
$parent_id = wp_is_post_revision( $chart_id );
return empty( get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true ) ) || 'publish' === get_post_status( $parent_id ? $parent_id : $chart_id );
}

/**
* Deletes the saved image of a chart whose rows are not public.
*
* The image shows the rows, and each visitor can read a file in the uploads folder.
*
* @param int $chart_id The chart ID. A revision has no image of its own.
* @return void
*/
public static function delete_image_of_private_rows( $chart_id ) {
if ( wp_is_post_revision( $chart_id ) || self::has_public_rows( $chart_id ) ) {
return;
}
$image_id = self::get_chart_image_id( $chart_id );
// An image that WordPress did not delete keeps its meta, so a later call finds it.
if ( $image_id && ! wp_delete_attachment( $image_id, true ) ) {
return;
}
delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE );
}

/**
* Gets the chart content after common manipulations.
*
* @param WP_Post|object $chart The chart post.
* @param string $type The chart type passed to the data filter.
* @param bool $run_filter Whether to run the chart data filter.
* @param bool $sanitize Whether to prepare the cells for HTML-capable renderers; exports and editors need the stored values.
* @return mixed The chart data.
* @return mixed The chart data; an empty array when the current user cannot read the stored rows.
*/
public static function get_chart_data( $chart, $type, $run_filter = true, $sanitize = true ) {
// A chart object that is not a saved post has no ID and no saved post-type query.
if ( isset( $chart->ID ) && ! self::can_read_chart_rows( $chart->ID ) ) {
return array();
}

// change HTML entities
$post_content = html_entity_decode( htmlentities( $chart->post_content ) );
$post_content = preg_replace_callback(
Expand Down Expand Up @@ -924,20 +984,68 @@ function ( $matches ) {
return $sanitize ? self::sanitize_chart_data( $altered ) : $altered;
}

/**
* Returns the saved credentials of a JSON chart for a request to the endpoint they were saved for.
*
* A user who does not know the credentials can then not send them to another address, or read them
* back from an address that returns its request headers. A save writes that endpoint beside the
* credentials as `auth_url`, so a later change of the chart endpoint does not move them. Headers of an
* older version have no `auth_url`; their credentials belong to the chart endpoint.
*
* @param int $chart_id The chart ID.
* @param string $url The JSON endpoint of the request.
* @return array{username: string, password: string}|string|null The credentials, or null when the chart has none for that endpoint.
*/
public static function get_saved_json_auth( $chart_id, $url ) {
$headers = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_HEADERS, true );
$saved_url = is_array( $headers ) && isset( $headers['auth_url'] ) ? $headers['auth_url'] : get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true );
$saved_url = is_string( $saved_url ) ? trim( $saved_url ) : '';
if ( ! is_array( $headers ) || empty( $headers['auth'] ) || ! self::is_json_endpoint( $saved_url, $url ) ) {
return null;
}
$auth = $headers['auth'];
if ( is_string( $auth ) || ( is_array( $auth ) && isset( $auth['username'], $auth['password'] ) && is_string( $auth['username'] ) && is_string( $auth['password'] ) ) ) {
return $auth;
}
return null;
}

/**
* Tells whether a request address is the saved JSON endpoint of a chart.
*
* The chart editor prints the saved endpoint with esc_url(), which encodes some characters, and the browser
* decodes the HTML entities. The form then sends that address, so it counts as the saved endpoint too.
*
* @param string $saved_url The saved JSON endpoint.
* @param string $url The address of the request.
* @return bool
*/
private static function is_json_endpoint( $saved_url, $url ) {
$url = trim( $url );
return '' !== $saved_url && ( $url === $saved_url || $url === html_entity_decode( esc_url( $saved_url ), ENT_QUOTES ) );
}

/**
* Saves a chart's JSON endpoint, recording the user who changes it as the WooCommerce report user.
*
* A scheduled refresh of the endpoint then uses this user's report access,
* not the access of whoever authorized an earlier endpoint.
* not the access of whoever authorized an earlier endpoint. Saved credentials belong to the endpoint
* they were saved for, so a new endpoint removes them.
*
* @param int $chart_id The chart ID.
* @param string $url The JSON endpoint.
* @param string $url The JSON endpoint, with slashes.
* @return void
*/
public static function update_json_url( $chart_id, $url ) {
if ( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ) !== $url ) {
$saved_url = trim( (string) get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ) );
if ( $saved_url !== $url ) {
update_post_meta( $chart_id, Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER, get_current_user_id() );
}
$headers = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_HEADERS, true );
if ( is_array( $headers ) && isset( $headers['auth'] ) && ! self::is_json_endpoint( $saved_url, wp_unslash( $url ) ) ) {
unset( $headers['auth'], $headers['auth_url'] );
update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_HEADERS, wp_slash( $headers ) );
}
update_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, $url );
}

Expand All @@ -962,16 +1070,45 @@ static function ( $value ) {
}

/**
* Get chart image.
* Returns the name of the file that holds the saved image of a chart.
*
* @param object $chart Chart data.
* @param int $chart_id The chart ID.
* @return string
*/
protected static function chart_image_filename( $chart_id ) {
return 'visualization-' . $chart_id . '.png';
}

/**
* Returns the ID of the image that was saved for a chart.
*
* A chart copied by an older version can point to the image of its source chart, also after that image is deleted.
* The file of an image keeps the name it was saved with. WordPress adds a suffix for a name that is in use, for an
* image that a user edits, and for a large image that it scales or rotates.
*
* @param int $chart_id The chart ID.
* @return int The attachment ID, or 0 when the chart has no image of its own.
*/
public static function get_chart_image_id( $chart_id ) {
$attachment_id = (int) get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, true );
$saved_name = preg_quote( pathinfo( self::chart_image_filename( $chart_id ), PATHINFO_FILENAME ), '/' );
if ( $attachment_id && preg_match( '/^' . $saved_name . '(-(\d+|e\d+|scaled|rotated))*\.png\z/', basename( (string) get_attached_file( $attachment_id ) ) ) ) {
return $attachment_id;
}
return 0;
}

/**
* Get chart image.
*
* @param WP_Post|null $chart The chart post.
* @return array{csv: string} The `csv` value is the image tag of the saved chart image, or an empty string.
*/
public function _getImage( $chart = null ) {
$image = '';
if ( $chart ) {
$chart_image = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true );
if ( ! empty( $chart_image ) ) {
$chart_image = self::get_chart_image_id( $chart->ID );
if ( $chart_image ) {
$image = wp_get_attachment_image( $chart_image, 'full' );
}
}
Expand Down
29 changes: 13 additions & 16 deletions classes/Visualizer/Module/Abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,22 +968,14 @@ private function setJsonSource( $chart, $input, $hours, $dry_run ) {
$params['paging'] = sanitize_text_field( $input['json_paging'] );
}

// Credentials saved from the chart editor are reused for the same host only; they are never accepted or returned here.
$saved_headers = get_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS, true );
$saved_url = (string) get_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, true );
$auth = array();
if ( is_array( $saved_headers ) && ! empty( $saved_headers['auth'] ) && '' !== $saved_url && wp_parse_url( $saved_url, PHP_URL_HOST ) === wp_parse_url( $url, PHP_URL_HOST ) && wp_parse_url( $saved_url, PHP_URL_SCHEME ) === wp_parse_url( $url, PHP_URL_SCHEME ) ) {
$auth = $saved_headers['auth'];
if ( is_array( $auth ) && isset( $auth['username'], $auth['password'] ) ) {
$params['username'] = $auth['username'];
$params['password'] = $auth['password'];
} elseif ( is_string( $auth ) ) {
$params['auth'] = $auth;
}
}
// Credentials saved from the chart editor are reused for the same endpoint only; they are never accepted or returned here.
// Each source gets them through setAuth(), because a source prints its parameters to the debug log.
$auth = self::get_saved_json_auth( $chart->ID, $url );

// First pass: discover the keys available under the chosen root.
$probe = $this->fetchSource( new Visualizer_Source_Json( $params ) );
$probe_source = new Visualizer_Source_Json( $params );
$probe_source->setAuth( $auth );
$probe = $this->fetchSource( $probe_source );
if ( is_wp_error( $probe ) ) {
return $probe;
}
Expand All @@ -997,7 +989,9 @@ private function setJsonSource( $chart, $input, $hours, $dry_run ) {

if ( ! $mapping ) {
if ( $dry_run ) {
$roots = ( new Visualizer_Source_Json( $params ) )->fetchRoots();
$roots_source = new Visualizer_Source_Json( $params );
$roots_source->setAuth( $auth );
$roots = $roots_source->fetchRoots();
return array(
'id' => $chart->ID,
'source' => 'json',
Expand Down Expand Up @@ -1025,6 +1019,7 @@ private function setJsonSource( $chart, $input, $hours, $dry_run ) {
}

$source = new Visualizer_Source_Json( $params );
$source->setAuth( $auth );
try {
$source->fetchFromEditableTable();
} catch ( Exception $e ) {
Expand Down Expand Up @@ -1053,7 +1048,9 @@ private function setJsonSource( $chart, $input, $hours, $dry_run ) {

$headers = array( 'method' => $params['method'] );
if ( $auth ) {
$headers['auth'] = $auth;
// add_post_meta() removes slashes, and the saved value is already without them.
$headers['auth'] = wp_slash( $auth );
$headers['auth_url'] = wp_slash( $params['url'] );
}
add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS, $headers );
if ( ! empty( $params['paging'] ) ) {
Expand Down
Loading
Loading