| Server IP : 104.21.28.229 / Your IP : 216.73.216.142 Web Server : Apache/2 System : Linux hosting8537.lvs 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : mienphi ( 1014) PHP Version : 8.2.14 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/mienphi/public_html/wp-content/plugins/woocommerce/src/Admin/API/ |
Upload File : |
<?php
/**
* REST API Notice controller
*
* Handles requests to /notice/
*/
namespace Automattic\WooCommerce\Admin\API;
use Automattic\WooCommerce\Admin\PluginsHelper;
defined( 'ABSPATH' ) || exit;
/**
* Notice Controller.
*
* @internal
* @extends WC_REST_Data_Controller
*/
class Notice extends \WC_REST_Data_Controller {
/**
* Endpoint namespace.
*
* @var string
*/
protected $namespace = 'wc-admin';
/**
* Route base.
*
* @var string
*/
protected $rest_base = 'notice';
/**
* Register the routes for admin notes.
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/dismiss',
array(
array(
'methods' => 'POST',
'callback' => array( $this, 'dissmiss_notice' ),
'permission_callback' => array( $this, 'get_permission' ),
),
)
);
}
/**
* Save notice dismiss information in user meta.
*
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error
*/
public function dissmiss_notice( $request ) {
if ( ! isset( $request['dismiss_notice_nonce'] )
|| ! wp_verify_nonce( $request['dismiss_notice_nonce'], 'dismiss_notice' ) ) {
return new WP_Error( 'unauthorized', 'Invalid nonce.', array( 'status' => 401 ) );
}
$notice_id = isset( $request['notice_id'] ) ? sanitize_text_field( wp_unslash( $request['notice_id'] ) ) : '';
$dismissed = false;
switch ( $notice_id ) {
case 'woo-subscription-expired-notice':
update_user_meta( get_current_user_id(), PluginsHelper::DISMISS_EXPIRED_SUBS_NOTICE, time() );
$dismissed = true;
break;
case 'woo-subscription-expiring-notice':
update_user_meta( get_current_user_id(), PluginsHelper::DISMISS_EXPIRING_SUBS_NOTICE, time() );
$dismissed = true;
break;
case 'woo-disconnect-notice':
update_user_meta( get_current_user_id(), PluginsHelper::DISMISS_DISCONNECT_NOTICE, time() );
$dismissed = true;
break;
}
return rest_ensure_response(
array(
'success' => $dismissed,
)
);
}
/**
* Check user has the necessary permissions to perform this action.
*
* @return bool
*/
public function get_permission(): bool {
return current_user_can( 'manage_woocommerce' );
}
}