~sajoupa/wordpress/wp-plugin-jetpack

« back to all changes in this revision

Viewing changes to json-endpoints/jetpack/class.jetpack-json-api-check-capabilities-endpoint.php

  • Committer: laurent.sesques at canonical
  • Date: 2017-06-14 13:02:28 UTC
  • Revision ID: laurent.sesques@canonical.com-20170614130228-bxf4a0cuovrtrmc7
[sajoupa] initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class Jetpack_JSON_API_Check_Capabilities_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
 
4
        // GET /sites/%s/me/capability
 
5
        public function callback( $path = '', $_blog_id = 0 ) {
 
6
                // Check minimum capability and blog membership first
 
7
                if ( is_wp_error( $error = $this->validate_call( $_blog_id, 'read', false ) ) ) {
 
8
                        return $error;
 
9
                }
 
10
 
 
11
                $args = $this->input();
 
12
 
 
13
                if ( ! isset( $args['capability'] ) || empty( $args['capability'] ) ) {
 
14
                        return new WP_Error( 'missing_capability', __( 'You are required to specify a capability to check.', 'jetpack' ), 400 );
 
15
                }
 
16
 
 
17
                $capability = $args['capability'];
 
18
                if ( is_array( $capability ) ) {
 
19
                        $results = array_map( 'current_user_can', $capability );
 
20
                        return array_combine( $capability, $results );
 
21
                } else {
 
22
                        return current_user_can( $capability );
 
23
                }
 
24
        }
 
25
}