PluginProbe
CatFolders – WordPress Media Library Folders & Categories / trunk
CatFolders – WordPress Media Library Folders & Categories vtrunk
2.5.6 2.5.5 trunk 1.6.1 1.8 1.9 2.0 2.2 2.3.1 2.3.2 2.4.4 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4
catfolders / includes / Rest / Controllers / BlockController.php

BlockController.php in CatFolders – WordPress Media Library Folders & Categories trunk, at includes/Rest/Controllers/BlockController.php

41 lines 963 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace CatFolders\Rest\Controllers;
3
4 use CatFolders\Blocks\GalleryBlock;
5
6 defined( 'ABSPATH' ) || exit;
7
8 class BlockController {
9 public function register_routes() {
10 register_rest_route(
11 CATF_ROUTE_NAMESPACE,
12 '/get-attachments-from-folders',
13 array(
14 array(
15 'methods' => \WP_REST_Server::READABLE,
16 'callback' => array( $this, 'get_attachments_from_folders' ),
17 'permission_callback' => array( $this, 'permission_callback' ),
18 ),
19 )
20 );
21 }
22
23 public function permission_callback() {
24 if ( ! is_user_logged_in() ) {
25 return false;
26 }
27 if ( ! current_user_can( 'upload_files' ) ) {
28 return false;
29 }
30 return true;
31 }
32
33 public function get_attachments_from_folders( \WP_REST_Request $request ) {
34 $folders = explode( ',', $request->get_param( 'folders' ) );
35
36 $data = GalleryBlock::instance()->get_attachments( array( 'folders' => $folders ) );
37
38 return new \WP_REST_Response( $data );
39 }
40 }
41