PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / abilities / class-ability-get-gallery.php
foogallery / includes / abilities Last commit date
class-abilities.php 2 months ago class-ability-create-gallery.php 2 months ago class-ability-get-gallery-layout-schema.php 2 months ago class-ability-get-gallery.php 2 months ago class-ability-list-galleries.php 2 months ago class-ability-list-gallery-layouts.php 2 months ago class-ability-media-search.php 2 months ago class-ability-update-gallery-attachments.php 2 months ago class-ability-update-gallery.php 2 months ago functions.php 2 months ago index.php 2 months ago
class-ability-get-gallery.php
110 lines
1 <?php
2 /**
3 * Get gallery ability.
4 */
5
6 if ( ! class_exists( 'FooGallery_Ability_Get_Gallery' ) ) {
7
8 class FooGallery_Ability_Get_Gallery {
9
10 const ID = 'foogallery/get-gallery';
11
12 /**
13 * Register the ability.
14 */
15 public function __construct() {
16 if ( foogallery_abilities_wp_api_available() ) {
17 add_action( 'foogallery_register_abilities', array( $this, 'register' ) );
18 }
19 }
20
21 /**
22 * Register the ability with the WordPress core Abilities API.
23 */
24 public function register() {
25 wp_register_ability(
26 self::ID,
27 array(
28 'category' => FooGallery_Abilities::CATEGORY,
29 'label' => __( 'Get Gallery', 'foogallery' ),
30 'description' => __( 'Return one FooGallery gallery by `gallery_id`. Set `include_attachment_detail` to `true` only when full attachment metadata is needed; otherwise the response includes attachment IDs only.', 'foogallery' ),
31 'input_schema' => array(
32 'type' => 'object',
33 'required' => array( 'gallery_id' ),
34 'properties' => array(
35 'gallery_id' => array(
36 'type' => 'integer',
37 'description' => __( 'The numeric ID of the FooGallery gallery to fetch.', 'foogallery' ),
38 ),
39 'include_attachment_detail' => array(
40 'type' => 'boolean',
41 'default' => false,
42 'description' => __( 'When `true`, include the full `attachments` array with attachment metadata. When `false`, return only `attachment_ids`.', 'foogallery' ),
43 ),
44 ),
45 'additionalProperties' => false,
46 ),
47 'output_schema' => array(
48 'type' => 'object',
49 'properties' => array(
50 'gallery' => array_merge(
51 foogallery_abilities_get_gallery_detail_schema( true ),
52 array(
53 'description' => __( 'The requested gallery record with normalized settings and, optionally, full attachment details.', 'foogallery' ),
54 )
55 ),
56 ),
57 ),
58 'execute_callback' => array( $this, 'execute' ),
59 'permission_callback' => array( $this, 'can_execute' ),
60 'meta' => array(
61 'annotations' => array(
62 'readonly' => true,
63 'idempotent' => true,
64 ),
65 'show_in_rest' => true,
66 ),
67 )
68 );
69 }
70
71 /**
72 * Check if the current user can execute the ability.
73 *
74 * @param array $args Ability arguments.
75 *
76 * @return bool
77 */
78 public function can_execute( $args ) {
79 $args = foogallery_abilities_normalize_input( $args );
80
81 $gallery_id = isset( $args['gallery_id'] ) ? absint( $args['gallery_id'] ) : 0;
82
83 return $gallery_id > 0 && current_user_can( 'edit_post', $gallery_id );
84 }
85
86 /**
87 * Execute the ability.
88 *
89 * @param array $args Ability arguments.
90 *
91 * @return array|WP_Error
92 */
93 public function execute( $args ) {
94 $args = foogallery_abilities_normalize_input( $args );
95
96 $include_attachment_detail = isset( $args['include_attachment_detail'] ) ? wp_validate_boolean( $args['include_attachment_detail'] ) : false;
97
98 $gallery = foogallery_abilities_get_gallery( isset( $args['gallery_id'] ) ? $args['gallery_id'] : 0 );
99
100 if ( is_wp_error( $gallery ) ) {
101 return $gallery;
102 }
103
104 return array(
105 'gallery' => foogallery_abilities_prepare_gallery_details( $gallery, $include_attachment_detail ),
106 );
107 }
108 }
109 }
110