PluginProbe
WP Ultimate Post Grid / 4.1.1
WP Ultimate Post Grid v4.1.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / includes / public / api / class-wpupg-api-notices.php

class-wpupg-api-notices.php in WP Ultimate Post Grid 4.1.1, at includes/public/api/class-wpupg-api-notices.php

69 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * API for the admin notices.
4 *
5 * @link https://bootstrapped.ventures
6 * @since 3.0.0
7 *
8 * @package WP_Ultimate_Post_Grid
9 * @subpackage WP_Ultimate_Post_Grid/includes/public/api
10 */
11
12 /**
13 * API for the admin notices.
14 *
15 * @since 3.0.0
16 * @package WP_Ultimate_Post_Grid
17 * @subpackage WP_Ultimate_Post_Grid/includes/public/api
18 * @author Brecht Vandersmissen <brecht@bootstrapped.ventures>
19 */
20 class WPUPG_Api_Notices {
21
22 /**
23 * Register actions and filters.
24 *
25 * @since 3.1.0
26 */
27 public static function init() {
28 add_action( 'rest_api_init', array( __CLASS__, 'api_register_data' ) );
29 }
30
31 /**
32 * Register data for the REST API.
33 *
34 * @since 3.1.0
35 */
36 public static function api_register_data() {
37 if ( function_exists( 'register_rest_field' ) ) { // Prevent issue with Jetpack.
38 register_rest_route( 'wp-ultimate-post-grid/v1', '/notice', array(
39 'callback' => array( __CLASS__, 'api_dismiss_notice' ),
40 'methods' => 'DELETE',
41 'permission_callback' => '__return_true',
42 ));
43 }
44 }
45
46 /**
47 * Handle dismiss notice call to the REST API.
48 *
49 * @since 3.1.0
50 * @param WP_REST_Request $request Current request.
51 */
52 public static function api_dismiss_notice( $request ) {
53 // Parameters.
54 $params = $request->get_params();
55
56 $id = isset( $params['id'] ) ? $params['id'] : '';
57 $user_id = get_current_user_id();
58
59 if ( $id && $user_id ) {
60 add_user_meta( $user_id, 'wpupg_dismissed_notices', $id );
61 return true;
62 }
63
64 return false;
65 }
66 }
67
68 WPUPG_Api_Notices::init();
69