GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge branch 'feat/82780_error_plugins_api' into feat/82780_error_plu… · axeptio/wordpress-plugin@09b9eeb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • assets
    • img
      • alert.svg
      • check.svg
      • x-mark.svg
    • js/backend
      • app.js
      • components
        • noticeComponent.js
        • pluginList.js
      • store
        • notifications.js
  • includes
    • classes
      • admin/pages
        • class-admin-callbacks.php
      • frontend
        • class-axeptio-sdk.php
      • utils
        • class-search-callback-file-location.php
    • core.php
    • helpers
      • helpers.php
      • utility.php
  • templates/admin
    • plugin-manager.php
    • plugins/fields
      • edit.php
    • sections
      • notice.php
      • plugins.php
      • toast.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎assets/img/alert.svg‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎assets/img/check.svg‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎assets/img/x-mark.svg‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎assets/js/backend/app.js‎

Copy file name to clipboardExpand all lines: assets/js/backend/app.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import selectComponent from './components/selectComponent';
99
import noticeComponent from './components/noticeComponent';
1010
import tabsPill from './components/tabsPill';
1111
import advancedSettings from './components/advancedSettings';
12+
import notifications from './store/notifications';
1213

1314
window.Alpine = Alpine;
1415

@@ -22,6 +23,8 @@ Alpine.data('SelectComponent', selectComponent);
2223
Alpine.data('tabsPill', tabsPill);
2324
Alpine.data('advancedSettings', advancedSettings);
2425

26+
Alpine.store('notifications', notifications);
27+
2528
Alpine.plugin( persist );
2629
Alpine.plugin( collapse );
2730

Collapse file

‎assets/js/backend/components/noticeComponent.js‎

Copy file name to clipboardExpand all lines: assets/js/backend/components/noticeComponent.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const instance = function( args ) {
33
timeoutButton: null,
44
disableButton: null,
55
nonce: args.nonce,
6+
restRoot: args.rest_root,
67

78
init() {
89
this.timeoutButton = this.$el.querySelector( '#axeptio-timeout-button' );
@@ -32,15 +33,15 @@ const instance = function( args ) {
3233
},
3334

3435
fetchAPI( route ) {
35-
const apiUrl = `/wp-json/axeptio/v1/${ route }`;
36+
const apiUrl = `${ this.restRoot }${ route }/`;
3637

3738
fetch( apiUrl, {
3839
method: 'POST',
3940
headers: {
4041
'Content-Type': 'application/json',
4142
'X-WP-Nonce': this.nonce,
4243
},
43-
} ).then( ( response ) => response.json() );
44+
} ).catch( () => {} );
4445
},
4546
};
4647
};
Collapse file

‎assets/js/backend/components/pluginList.js‎

Copy file name to clipboardExpand all lines: assets/js/backend/components/pluginList.js
+60-16Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,40 @@ const instance = function( args ) {
7878
};
7979

8080
const pluginMethods = {
81+
readResponse( response ) {
82+
if ( ! response.ok ) {
83+
throw new Error( `Unexpected response status: ${ response.status }` );
84+
}
85+
return response.json();
86+
},
87+
8188
fetchPlugins() {
8289
this.isGetting = true;
83-
const apiUrl = `/wp-json/axeptio/v1/plugins/${ this.configurationId }`;
90+
91+
const apiUrl = `${ this.restRoot }plugins/${ this.configurationId }/`;
8492
fetch( apiUrl, {
8593
method: 'GET',
8694
headers: {
8795
'Content-Type': 'application/json',
88-
'X-WP-Nonce': args.nonce,
96+
'X-WP-Nonce': this.nonce,
8997
},
9098
} )
91-
.then( ( response ) => response.json() )
99+
.then( this.readResponse )
92100
.then( ( data ) => {
93101
this.plugins = data;
94102
this.isGetting = false;
103+
} )
104+
.catch( () => {
105+
this.plugins = [];
106+
this.isGetting = false;
107+
window.Alpine.store( 'notifications' ).push( args.messages.load_error );
95108
} );
96109
},
97110

98111
deletePlugin( plugin ) {
99112
this.isSaving = true;
100-
const apiUrl = `/wp-json/axeptio/v1/plugins/${ this.configurationId }/${ plugin.Metas.plugin }`;
113+
114+
const apiUrl = `${ this.restRoot }plugins/${ this.configurationId }/${ plugin.Metas.plugin }/`;
101115
fetch( apiUrl, {
102116
method: 'DELETE',
103117
headers: {
@@ -106,14 +120,19 @@ const instance = function( args ) {
106120
},
107121
body: JSON.stringify( plugin.Metas ),
108122
} )
109-
.then( ( response ) => response.json() )
123+
.then( this.readResponse )
110124
.then( () => {
111125
this.isSaving = false;
112126
this.editOpen = false;
113127
this.closeDeleteModal();
114128
this.fetchPlugins();
115129
this.editedPlugin.Metas.enabled = false;
116130
this.setForceEditOpen( false );
131+
} )
132+
.catch( () => {
133+
this.isSaving = false;
134+
this.closeDeleteModal();
135+
window.Alpine.store( 'notifications' ).push( args.messages.delete_error );
117136
} );
118137
},
119138

@@ -141,26 +160,41 @@ const instance = function( args ) {
141160
this.refreshRepeaterFields();
142161
},
143162

144-
updatePlugin( plugin ) {
163+
updatePlugin( plugin, metas = plugin.Metas ) {
145164
this.isSaving = true;
146165

147-
const apiUrl = `/wp-json/axeptio/v1/plugins/${ this.configurationId }/${ plugin.Metas.plugin }`;
148-
fetch( apiUrl, {
166+
const apiUrl = `${ this.restRoot }plugins/${ this.configurationId }/${ plugin.Metas.plugin }/`;
167+
return fetch( apiUrl, {
149168
method: 'PUT',
150169
headers: {
151170
'Content-Type': 'application/json',
152171
'X-WP-Nonce': this.nonce,
153172
},
154-
body: JSON.stringify( plugin.Metas ),
173+
body: JSON.stringify( metas ),
155174
} )
156-
.then( ( response ) => response.json() )
175+
.then( this.readResponse )
157176
.then( () => {
158177
this.refreshRepeaterFields();
159178
this.isSaving = false;
160179
this.editedPluginHasChanged = false;
180+
return true;
181+
} )
182+
.catch( () => {
183+
this.isSaving = false;
184+
window.Alpine.store( 'notifications' ).push( args.messages.save_error );
185+
return false;
161186
} );
162187
},
163188

189+
saveEditedPlugin() {
190+
this.updatePlugin( this.editedPlugin ).then( ( saved ) => {
191+
if ( saved ) {
192+
window.Alpine.store( 'notifications' ).push( args.messages.save_success, 'success' );
193+
this.editOpen = false;
194+
}
195+
} );
196+
},
197+
164198
openMediaSelector() {
165199
this.setForceEditOpen( true );
166200
const self = this;
@@ -192,12 +226,23 @@ const instance = function( args ) {
192226
},
193227

194228
enableControl( plugin ) {
229+
if ( this.isSaving ) {
230+
return;
231+
}
232+
195233
const { Metas } = plugin;
234+
const metas = {
235+
...Metas,
236+
enabled: ! Boolean( Metas.enabled ) ? 1 : 0,
237+
cookie_widget_step: 'wordpress',
238+
};
196239

197240
this.editedPlugin = plugin;
198-
Metas.enabled = ! Boolean( Metas.enabled ) ? 1 : 0;
199-
Metas.cookie_widget_step = 'wordpress';
200-
this.updatePlugin( plugin );
241+
this.updatePlugin( plugin, metas ).then( ( saved ) => {
242+
if ( saved ) {
243+
Object.assign( Metas, metas );
244+
}
245+
} );
201246
},
202247

203248
initEditedPlugin() {
@@ -303,19 +348,18 @@ const instance = function( args ) {
303348
editedPluginHasChanged: false,
304349
configurationId: 'all',
305350
activeTab: 1,
306-
currentPage: 1,
307351
forceEditOpen: false,
308352
activePlugins: args.active_plugins,
309-
totalPages: 1,
310353
nonce: args.nonce,
354+
restRoot: args.rest_root,
355+
311356
isSaving: false,
312357
isGetting: false,
313358
hookModes: [],
314359
projectVersions: args.project_versions,
315360
shortcodeTagsModes: [],
316361
editOpen: false,
317362
showDeleteModal: false,
318-
pluginToDelete: null,
319363
inputRefs: [],
320364
fields: [],
321365

Collapse file

‎assets/js/backend/store/notifications.js‎

Copy file name to clipboard
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const ENTER_DELAY = 30;
2+
const LEAVE_DURATION = 300;
3+
4+
export default {
5+
items: [],
6+
nextId: 1,
7+
autoClose: true,
8+
autoCloseDelay: 5000,
9+
10+
push( message, type = 'error' ) {
11+
const id = this.nextId++;
12+
this.items.push( { id, message, type, visible: false } );
13+
14+
setTimeout( () => {
15+
const item = this.items.find( ( notification ) => notification.id === id );
16+
if ( item ) {
17+
item.visible = true;
18+
}
19+
}, ENTER_DELAY );
20+
21+
if ( this.autoClose ) {
22+
setTimeout( () => this.dismiss( id ), this.autoCloseDelay );
23+
}
24+
},
25+
26+
dismiss( id ) {
27+
const item = this.items.find( ( notification ) => notification.id === id );
28+
if ( ! item ) {
29+
return;
30+
}
31+
32+
item.visible = false;
33+
setTimeout( () => {
34+
this.items = this.items.filter( ( notification ) => notification.id !== id );
35+
}, LEAVE_DURATION );
36+
},
37+
};
Collapse file

‎includes/classes/admin/pages/class-admin-callbacks.php‎

Copy file name to clipboardExpand all lines: includes/classes/admin/pages/class-admin-callbacks.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ public function admin_dashboard() {
3333
*/
3434
public function plugin_manager() {
3535
$settings = array(
36+
'rest_root' => \Axeptio\Plugin\get_rest_root(),
3637
'nonce' => wp_create_nonce( 'wp_rest' ),
3738
'active_plugins' => Plugins::get_active_plugins(),
3839
'project_versions' => Project_Versions::all(),
40+
'messages' => array(
41+
'load_error' => __( 'The extension list could not be loaded. Please try again, and contact your host if the problem persists.', 'axeptio-sdk-integration' ),
42+
'save_error' => __( 'Your changes have not been saved. Please try again, and contact your host if the problem persists.', 'axeptio-sdk-integration' ),
43+
'delete_error' => __( 'These settings have not been deleted. Please try again, and contact your host if the problem persists.', 'axeptio-sdk-integration' ),
44+
'save_success' => __( 'Your changes have been saved.', 'axeptio-sdk-integration' ),
45+
),
3946
);
4047
return require_once XPWP_PATH . 'templates' . DS . 'admin' . DS . 'plugin-manager.php';
4148
}
Collapse file

‎includes/classes/frontend/class-axeptio-sdk.php‎

Copy file name to clipboardExpand all lines: includes/classes/frontend/class-axeptio-sdk.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function Axeptio\Plugin\get_sdk_settings;
2323
use function Axeptio\Plugin\script_url;
2424
use function Axeptio\Plugin\style_url;
25-
use function Axeptio\Plugin\Utility\get_asset_info;
2625

2726
class Axeptio_Sdk extends Module {
2827

@@ -104,7 +103,7 @@ public function enqueue_scripts() {
104103
'axeptio/main',
105104
style_url( 'frontend/main', 'frontend' ),
106105
array(),
107-
get_asset_info( 'shared', 'version' ),
106+
XPWP_VERSION,
108107
);
109108

110109
$cookies_version = Settings::get_option( 'version', false );
Collapse file

‎includes/classes/utils/class-search-callback-file-location.php‎

Copy file name to clipboardExpand all lines: includes/classes/utils/class-search-callback-file-location.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Axeptio\Plugin\Utils;
44

5-
use function Axeptio\Plugin\wp_memory_limit_in_bytes;
6-
75
class Search_Callback_File_Location {
86
/**
97
* Cache expiration time in seconds (1 week)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.