PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | _inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-top-posts.php +12 -24 13.0.2 → 16.3-a.7 View file →
@@ -4,8 +4,12 @@
4 4 *
5 5 * @package automattic/jetpack
6 6 */
7 7
8 +if ( ! defined( 'ABSPATH' ) ) {
9 + exit( 0 );
10 +}
11 +
8 12 /**
9 13 * Top Posts & Pages block endpoint.
10 14 */
11 15 class WPCOM_REST_API_V2_Endpoint_Top_Posts extends WP_REST_Controller {
@@ -13,12 +17,8 @@
13 17 * Constructor.
14 18 */
15 19 public function __construct() {
16 20 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
17 -
18 - if ( ! class_exists( 'Jetpack_Top_Posts_Helper' ) ) {
19 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-top-posts-helper.php';
20 - }
21 21 }
22 22
23 23 /**
24 24 * Register endpoint routes.
@@ -46,9 +46,11 @@
46 46 array(
47 47 array(
48 48 'methods' => WP_REST_Server::READABLE,
49 49 'callback' => array( $this, 'get_top_posts' ),
50 - 'permission_callback' => '__return_true',
50 + 'permission_callback' => function () {
51 + return current_user_can( 'edit_posts' );
52 + },
51 53 'args' => array(
52 54 'period' => array(
53 55 'description' => __( 'Timeframe for stats.', 'jetpack' ),
54 56 'type' => array( 'string', 'integer' ),
@@ -56,24 +58,8 @@
56 58 'validate_callback' => function ( $param ) {
57 59 return is_numeric( $param ) || is_string( $param );
58 60 },
59 61 ),
60 - 'number' => array(
61 - 'description' => __( 'Number of posts to display.', 'jetpack' ),
62 - 'type' => 'integer',
63 - 'required' => false,
64 - 'validate_callback' => function ( $param ) {
65 - return is_numeric( $param );
66 - },
67 - ),
68 - 'types' => array(
69 - 'description' => __( 'Types of content to include.', 'jetpack' ),
70 - 'type' => 'string',
71 - 'required' => false,
72 - 'validate_callback' => function ( $param ) {
73 - return is_string( $param );
74 - },
75 - ),
76 62 ),
77 63 ),
78 64 )
79 65 );
@@ -105,12 +91,14 @@
105 91 *
106 92 * @return array Data on top posts.
107 93 */
108 94 public function get_top_posts( $request ) {
95 + if ( ! class_exists( 'Jetpack_Top_Posts_Helper' ) ) {
96 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-top-posts-helper.php';
97 + }
98 +
109 99 $period = $request->get_param( 'period' );
110 - $number = $request->get_param( 'number' );
111 - $types = $request->get_param( 'types' );
112 - return Jetpack_Top_Posts_Helper::get_top_posts( $period, $number, $types );
100 + return Jetpack_Top_Posts_Helper::get_top_posts( $period );
113 101 }
114 102 }
115 103
116 104 wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Top_Posts' );