PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Abilities / Read / GetNotification.php

GetNotification.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar trunk, at includes/Abilities/Read/GetNotification.php

80 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ability: get a single NotificationX notification with its full configuration.
4 *
5 * @package NotificationX\Abilities\Read
6 */
7
8 namespace NotificationX\Abilities\Read;
9
10 use NotificationX\Abilities\AbilityBase;
11 use NotificationX\Abilities\BuilderInfo;
12 use NotificationX\Core\PostType;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Returns the full stored configuration of one notification.
20 */
21 class GetNotification extends AbilityBase {
22
23 protected $id = 'notificationx/get-notification';
24 protected $label = 'Get notification';
25 protected $description = 'Get the full configuration of a single NotificationX notification by its id (nx_id), including type, source, theme, content and display settings.';
26
27 public function input_schema() {
28 return array(
29 'type' => 'object',
30 'required' => array( 'nx_id' ),
31 'properties' => array(
32 'nx_id' => array(
33 'type' => 'integer',
34 'description' => 'The notification id to fetch.',
35 ),
36 ),
37 );
38 }
39
40 public function output_schema() {
41 return array(
42 'type' => 'object',
43 'properties' => array(
44 'enabled' => array( 'type' => 'boolean' ),
45 'theme_valid' => array( 'type' => 'boolean' ),
46 'notification' => array( 'type' => 'object' ),
47 ),
48 );
49 }
50
51 public function execute( $input ) {
52 $nx_id = (int) $input['nx_id'];
53 $post_type = PostType::get_instance();
54 $post = $post_type->get_post( $nx_id );
55
56 if ( empty( $post ) ) {
57 return new \WP_Error(
58 'nx_mcp_not_found',
59 /* translators: %d: notification id. */
60 sprintf( __( 'No notification found with id %d.', 'notificationx' ), $nx_id ),
61 array( 'status' => 404 )
62 );
63 }
64
65 // Authoritative active state (from the enabled-source map, not the blob).
66 $enabled = (bool) $post_type->is_enabled( $nx_id );
67 // Whether the stored theme actually exists for this source (a false here
68 // is the usual reason a notification saves but renders nothing).
69 $source = isset( $post['source'] ) ? $post['source'] : '';
70 $theme = isset( $post['themes'] ) ? $post['themes'] : ( isset( $post['theme'] ) ? $post['theme'] : '' );
71 $theme_valid = $source && $theme ? BuilderInfo::is_valid_theme( $source, $theme ) : false;
72
73 return array(
74 'enabled' => $enabled,
75 'theme_valid' => $theme_valid,
76 'notification' => $post,
77 );
78 }
79 }
80