C:\xampp\htdocs\landing\wp-content\plugins\wordpress-seo\src\routes\alert-dismissal-route.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php

namespace Yoast\WP\SEO\Routes;

use 
WP_REST_Request;
use 
WP_REST_Response;
use 
Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use 
Yoast\WP\SEO\Conditionals\No_Conditionals;
use 
Yoast\WP\SEO\Main;

/**
 * Class Alert_Dismissal_Route.
 */
class Alert_Dismissal_Route implements Route_Interface {

    use 
No_Conditionals;

    
/**
     * Represents the alerts route prefix.
     *
     * @var string
     */
    
const ROUTE_PREFIX 'alerts';

    
/**
     * Represents the dismiss route.
     *
     * @var string
     */
    
const DISMISS_ROUTE self::ROUTE_PREFIX '/dismiss';

    
/**
     * Represents the full dismiss route.
     *
     * @var string
     */
    
const FULL_DISMISS_ROUTE Main::API_V1_NAMESPACE '/' self::DISMISS_ROUTE;

    
/**
     * Represents the alert dismissal action.
     *
     * @var Alert_Dismissal_Action
     */
    
protected $alert_dismissal_action;

    
/**
     * Constructs Alert_Dismissal_Route.
     *
     * @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action.
     */
    
public function __constructAlert_Dismissal_Action $alert_dismissal_action ) {
        
$this->alert_dismissal_action $alert_dismissal_action;
    }

    
/**
     * Registers routes with WordPress.
     *
     * @return void
     */
    
public function register_routes() {
        
$dismiss_route_args = [
            
'methods'             => 'POST',
            
'callback'            => [ $this'dismiss' ],
            
'permission_callback' => [ $this'can_dismiss' ],
            
'args'                => [
                
'key' => [
                    
'validate_callback' => [ $this->alert_dismissal_action'is_allowed' ],
                    
'required'          => true,
                ],
            ],
        ];

        \
register_rest_routeMain::API_V1_NAMESPACEself::DISMISS_ROUTE$dismiss_route_args );
    }

    
/**
     * Dismisses an alert.
     *
     * @param WP_REST_Request $request The request. This request should have a key param set.
     *
     * @return WP_REST_Response The response.
     */
    
public function dismissWP_REST_Request $request ) {
        
$success $this->alert_dismissal_action->dismiss$request['key'] );
        
$status  $success === ( true ) ? 200 400;

        return new 
WP_REST_Response(
            (object) [
                
'success' => $success,
                
'status'  => $status,
            ],
            
$status
        
);
    }

    
/**
     * Whether or not the current user is allowed to dismiss alerts.
     *
     * @return boolean Whether or not the current user is allowed to dismiss alerts.
     */
    
public function can_dismiss() {
        return \
current_user_can'edit_posts' );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586