Skip to content

Commit 11c70e0

Browse files
authored
Merge pull request #71 from DevinWalker/develop
Merge develop -> master for 2.0.4 release
2 parents b0fe44f + 8c316e6 commit 11c70e0

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

readme.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Requires at least: 4.8
55
Donate Link: https://givewp.com/
66
Tested up to: 6.5
77
Requires PHP: 7.4
8-
Stable tag: 2.0.3
8+
Stable tag: 2.0.4
99
License: GPLv3
1010
License URI: http://www.gnu.org/licenses/gpl-3.0.html
1111

@@ -43,8 +43,8 @@ We do have documentation on the plugin [GitHub Wiki](https://github.com/impress-
4343

4444
= Minimum Requirements =
4545

46-
* WordPress 4.8 or greater
47-
* PHP version 5.3 or greater
46+
* WordPress 5.5 or greater
47+
* PHP version 7.4 or greater
4848
* MySQL version 5.0 or greater
4949

5050
= Automatic installation =
@@ -106,6 +106,10 @@ This is the first version of this plugin. It is a tool for your convenience. Rol
106106

107107
== Changelog ==
108108

109+
= 2.0.4 =
110+
* Fix: Resolved issue REST route not including proper permission callback which created a PHP notice. Thanks, @rom1our for submitting the issue.
111+
* Fix: Resolve issue with REST API and multisite installs not being able to properly communicate with the endpoint.
112+
109113
= 2.0.3 =
110114
* Fix: A few additional strings in JavaScript needed to be internationalized. Thanks, @pedro-mendonca for contributing the fix.
111115

src/admin.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ const AdminPage = () => {
2525

2626
useEffect( () => {
2727

28-
let restUrl = `${wprData.baseUrl}/wp-json/wp-rollback/v1/fetch-info/?type=${queryArgs.type}&slug=${queryArgs.type === 'theme' ? queryArgs.theme_file : queryArgs.plugin_slug}`;
28+
let restUrl = `${wprData.restUrl}wp-rollback/v1/fetch-info/?type=${queryArgs.type}&slug=${queryArgs.type === 'theme' ? queryArgs.theme_file : queryArgs.plugin_slug}`;
2929

30+
const headers = new Headers({
31+
'X-WP-Nonce': wprData.restApiNonce // Assuming nonce is stored in wprData.nonce
32+
});
3033

31-
32-
fetch( restUrl )
34+
fetch( restUrl, { headers: headers } )
3335
.then( ( response ) => response.json() )
3436
.then( ( data ) => {
3537
setRollbackInfo( data );
@@ -38,7 +40,7 @@ const AdminPage = () => {
3840
.catch( ( error ) => {
3941
console.error( 'Error fetching data:', error );
4042
} );
41-
}, [] );
43+
}, [wprData] );
4244

4345
useEffect( () => {
4446
if ( rollbackInfo && rollbackInfo.slug ) { // Check if rollbackInfo is loaded and has a slug
@@ -138,9 +140,6 @@ const AdminPage = () => {
138140
}
139141
}
140142

141-
console.log(rollbackInfo);
142-
console.log(queryArgs);
143-
144143
return (
145144
<div className={'wpr-wrapper'}>
146145
<div className={'wpr-logo-wrap'}>

src/themes-wp-rollback.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const wprThemeRollback = theme => {
6363

6464
const wprGetThemeData = theme => {
6565
const themeData = wp.themes?.data?.themes;
66+
6667
if (!Array.isArray(themeData)) {
6768
console.error('Invalid theme data');
6869
return null;

wp-rollback.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Rollback (or forward) any WordPress.org plugin, theme or block like a boss.
66
* Author: WP Rollback
77
* Author URI: https://wprollback.com/
8-
* Version: 2.0.3
8+
* Version: 2.0.4
99
* Text Domain: wp-rollback
1010
* Domain Path: /languages
1111
*
@@ -188,13 +188,7 @@ private function setup_constants(): void {
188188
private function hooks(): void {
189189

190190
// Multisite compatibility: only loads on main site.
191-
if ( is_network_admin() ) {
192-
$this->multisite_compatibility = new WP_Rollback_Multisite_Compatibility( $this );
193-
}
194-
195-
if ( is_multisite() && ! is_network_admin() ) {
196-
return;
197-
}
191+
$this->multisite_compatibility = new WP_Rollback_Multisite_Compatibility( $this );
198192

199193
// i18n
200194
add_action( 'plugins_loaded', [ self::$instance, 'load_textdomain' ] );
@@ -226,23 +220,24 @@ private function hooks(): void {
226220
* @return void
227221
*/
228222
public function scripts( $hook ): void {
229-
if ( 'themes.php' === $hook ) {
223+
224+
// Theme's listing page JS
225+
if ( 'themes.php' === $hook && !is_multisite() ) {
230226
$theme_script_asset = require WP_ROLLBACK_PLUGIN_DIR . '/build/themes.asset.php';
231227

232228
wp_enqueue_script(
233229
'wp-rollback-themes-script',
234-
plugin_dir_url( __FILE__ ) . 'build/themes.js',
230+
WP_ROLLBACK_PLUGIN_URL . 'build/themes.js',
235231
$theme_script_asset['dependencies'],
236232
$theme_script_asset['version']
237233
);
238234
// Localize for i18n
239235
wp_localize_script(
240236
'wp-rollback-themes-script', 'wprData', [
241237
'ajaxurl' => admin_url(),
242-
'logo' => plugins_url( 'src/assets/logo.svg', __FILE__ ),
243-
'avatarFallback' => plugins_url( 'src/assets/avatar-plugin-fallback.jpg', __FILE__ ),
244238
'rollback_nonce' => wp_create_nonce( 'wpr_rollback_nonce' ),
245-
'apiNonce' => wp_create_nonce( 'wpr_rollback_api_nonce' ),
239+
'logo' => plugins_url( 'src/assets/logo.svg', WP_ROLLBACK_PLUGIN_FILE ),
240+
'avatarFallback' => plugins_url( 'src/assets/avatar-plugin-fallback.jpg', WP_ROLLBACK_PLUGIN_FILE ),
246241
'text_rollback_label' => __( 'Rollback', 'wp-rollback' ),
247242
'text_not_rollbackable' => __(
248243
'No Rollback Available: This is a non-WordPress.org theme.',
@@ -272,13 +267,14 @@ public function scripts( $hook ): void {
272267
// Localize the script with vars for JS.
273268
wp_localize_script( 'wp-rollback-plugin-admin-editor', 'wprData', [
274269
'rollback_nonce' => wp_create_nonce( 'wpr_rollback_nonce' ),
270+
'restApiNonce' => wp_create_nonce( 'wp_rest' ),
275271
'adminUrl' => admin_url( 'index.php' ),
276-
'baseUrl' => get_site_url(),
277-
'logo' => plugins_url( 'src/assets/logo.svg', __FILE__ ),
278-
'avatarFallback' => plugins_url( 'src/assets/avatar-plugin-fallback.jpg', __FILE__ ),
272+
'restUrl' => esc_url_raw( rest_url() ),
273+
'logo' => plugins_url( 'src/assets/logo.svg', WP_ROLLBACK_PLUGIN_FILE ),
274+
'avatarFallback' => plugins_url( 'src/assets/avatar-plugin-fallback.jpg', WP_ROLLBACK_PLUGIN_FILE ),
279275
'referrer' => wp_get_referer(),
280276
'text_no_changelog_found' => isset( $_GET['plugin_slug'] ) ? sprintf(
281-
// translators: %s Link.
277+
// translators: %s Link.
282278
__(
283279
'Sorry, we couldn\'t find a changelog entry found for this version. Try checking the <a href="%s" target="_blank">developer log</a> on WP.org.',
284280
'wp-rollback'
@@ -332,13 +328,16 @@ public function register_rest_route() {
332328
include WP_ROLLBACK_PLUGIN_DIR . '/src/class-rollback-api-requests.php';
333329

334330
register_rest_route( 'wp-rollback/v1', '/fetch-info/', [
335-
'methods' => 'GET',
336-
'callback' => function ( WP_REST_Request $request ) {
331+
'methods' => 'GET',
332+
'callback' => function ( WP_REST_Request $request ) {
337333
$fetcher = new WP_Rollback_API_Fetcher();
338334

339335
return $fetcher->fetch_plugin_or_theme_info( $request['type'], $request['slug'] );
340336
},
341-
'args' => [
337+
'permission_callback' => function () {
338+
return current_user_can( 'update_plugins' );
339+
},
340+
'args' => [
342341
'type' => [
343342
'required' => true,
344343
'type' => 'string',
@@ -472,12 +471,17 @@ private function setup_plugin_vars() {
472471
* @return array $actions
473472
*/
474473
public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ): array {
474+
475+
if ( is_multisite() && !is_network_admin()) {
476+
return $actions;
477+
}
478+
475479
// Filter for other devs.
476480
$plugin_data = apply_filters( 'wpr_plugin_data', $plugin_data );
477481

478482
// If plugin is missing package data do not output Rollback option.
479483
if ( ! isset( $plugin_data['package'] ) ||
480-
(strpos($plugin_data['package'], 'downloads.wordpress.org') === false) ) {
484+
( strpos( $plugin_data['package'], 'downloads.wordpress.org' ) === false ) ) {
481485
return $actions;
482486
}
483487

@@ -487,7 +491,7 @@ public function plugin_action_links( $actions, $plugin_file, $plugin_data, $cont
487491
}
488492

489493
// Base rollback URL
490-
$rollback_url = admin_url( 'index.php' );
494+
$rollback_url = is_network_admin() ? network_admin_url( 'index.php' ) : admin_url( 'index.php' );
491495

492496
$rollback_url = add_query_arg(
493497
apply_filters(
@@ -683,7 +687,7 @@ public function wpr_prepare_themes_js( $prepared_themes ): array {
683687

684688
// Loop through themes and provide a 'hasRollback' boolean key for JS.
685689
foreach ( $prepared_themes as $key => $value ) {
686-
$themes[ $key ] = $prepared_themes[ $key ];
690+
$themes[ $key ] = $value;
687691
$themes[ $key ]['hasRollback'] = isset( $rollbacks[ $key ] );
688692
}
689693

0 commit comments

Comments
 (0)