| 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 |
|