-
Notifications
You must be signed in to change notification settings - Fork 203
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
Enhance : Admin Notice Show gloablly & extand API #2446
base: develop
Are you sure you want to change the base?
Changes from all commits
22d192e
c446b6b
6332d23
69bb50b
aeda084
0ca4711
b286593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use WeDevs\Dokan\Admin\Notices\Helper; | ||
use WP_REST_Response; | ||
use WP_REST_Server; | ||
use WP_REST_Request; | ||
use WeDevs\Dokan\Abstracts\DokanRESTAdminController; | ||
|
||
/** | ||
|
@@ -36,6 +37,14 @@ public function register_routes() { | |
'methods' => WP_REST_Server::READABLE, | ||
'callback' => [ $this, 'dokan_get_admin_notices' ], | ||
'permission_callback' => [ $this, 'check_permission' ], | ||
'args' => [ | ||
'scope' => [ | ||
'description' => __( 'Notice context', 'dokan-lite' ), | ||
'type' => 'string', | ||
'required' => false, | ||
'default' => 'all', | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the default value. |
||
], | ||
], | ||
] | ||
); | ||
|
@@ -53,11 +62,13 @@ public function register_routes() { | |
|
||
/** | ||
* Get dokan specific notices | ||
* @param WP_REST_Request $request | ||
* | ||
* @return WP_REST_Response | ||
*/ | ||
public function dokan_get_admin_notices() { | ||
$notices = Helper::dokan_get_admin_notices(); | ||
public function dokan_get_admin_notices( WP_REST_Request $request ) { | ||
$notice_scope = $request->get_param( 'scope' ); | ||
$notices = Helper::dokan_get_admin_notices( $notice_scope ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retrieve all notices and perform filter operation here. |
||
|
||
return rest_ensure_response( $notices ); | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -62,6 +62,10 @@ export default { | |||||
type: Number, | ||||||
default: 5000 | ||||||
}, | ||||||
scope: { | ||||||
type: String, | ||||||
default: '' | ||||||
} | ||||||
}, | ||||||
|
||||||
data() { | ||||||
|
@@ -83,7 +87,7 @@ export default { | |||||
methods: { | ||||||
fetch() { | ||||||
$.ajax( { | ||||||
url: `${dokan_promo.rest.root}${dokan_promo.rest.version}/admin/notices/${this.endpoint}`, | ||||||
url: `${dokan_promo.rest.root}${dokan_promo.rest.version}/admin/notices/${this.endpoint}?scope=${this.scope}`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encode URL parameters to prevent injection. The scope parameter should be properly encoded when used in the URL. -url: `${dokan_promo.rest.root}${dokan_promo.rest.version}/admin/notices/${this.endpoint}?scope=${this.scope}`,
+url: `${dokan_promo.rest.root}${dokan_promo.rest.version}/admin/notices/${this.endpoint}?scope=${encodeURIComponent(this.scope)}`, 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass |
||||||
method: 'get', | ||||||
beforeSend: function ( xhr ) { | ||||||
xhr.setRequestHeader( 'X-WP-Nonce', dokan_promo.rest.nonce ); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script setup> | ||
|
||
import AdminNotice from "admin/components/AdminNotice.vue"; | ||
</script> | ||
|
||
<template> | ||
<AdminNotice | ||
scope="global" | ||
:interval="10000" | ||
endpoint="admin" | ||
/> | ||
|
||
</template> | ||
|
||
<style scoped lang="less"> | ||
|
||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import App from './App.vue'; | ||
const { jQuery: $ } = window; | ||
import Vue from 'vue'; | ||
|
||
if ( $( '#dokan-admin-notices' ).length ) { | ||
new Vue( { | ||
el: '#dokan-admin-notices', | ||
render: ( h ) => h( App ), | ||
} ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls do not modify this files. Undo all changes.