disable-adminbar-menus.php
7 months ago
hide-notice.php
7 months ago
index.php
8 years ago
restore-notice.php
7 months ago
hide-notice.php
64 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Hides notifications |
| 4 | * |
| 5 | * Github: https://github.com/alexkovalevv |
| 6 | * |
| 7 | * @author Alexander Kovalev <alex.kovalevv@gmail.com> |
| 8 | * @copyright (c) 2018 Webraftic Ltd |
| 9 | * @version 1.0 |
| 10 | */ |
| 11 | |
| 12 | // Exit if accessed directly |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | function wbcr_dan_ajax_hide_notices() { |
| 18 | check_ajax_referer( WDN_Plugin::app()->getPluginName() . '_ajax_hide_notices_nonce', 'security' ); |
| 19 | |
| 20 | if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_network' ) ) { |
| 21 | $notice_id = WDN_Plugin::app()->request->post( 'notice_id', null, true ); |
| 22 | $notice_html = WDN_Plugin::app()->request->post( 'notice_html', null ); |
| 23 | $hide_target = WDN_Plugin::app()->request->post( 'target', 'user' ); |
| 24 | //$notice_text = wp_kses( $notice_html, [] ); |
| 25 | |
| 26 | if ( empty( $notice_id ) ) { |
| 27 | wp_send_json_error( [ 'error_message' => __( 'Unable to process request: notice ID is missing. Please try again.', 'disable-admin-notices' ) ] ); |
| 28 | } |
| 29 | |
| 30 | switch ( $hide_target ) { |
| 31 | case 'all': |
| 32 | $get_hidden_notices = WDN_Plugin::app()->getPopulateOption( 'hidden_notices', [] ); |
| 33 | |
| 34 | if ( ! is_array( $get_hidden_notices ) ) { |
| 35 | $get_hidden_notices = []; |
| 36 | } |
| 37 | |
| 38 | $get_hidden_notices[ $notice_id ] = wp_kses_post( rtrim( trim( wp_unslash( $notice_html ) ) ) ); |
| 39 | |
| 40 | WDN_Plugin::app()->updatePopulateOption('hidden_notices', $get_hidden_notices ); |
| 41 | break; |
| 42 | case 'user': |
| 43 | default: |
| 44 | $current_user_id = get_current_user_id(); |
| 45 | $get_hidden_notices = get_user_meta( $current_user_id, WDN_Plugin::app()->getOptionName( 'hidden_notices' ), true ); |
| 46 | |
| 47 | if ( ! is_array( $get_hidden_notices ) ) { |
| 48 | $get_hidden_notices = []; |
| 49 | } |
| 50 | |
| 51 | $get_hidden_notices[ $notice_id ] = wp_kses_post( rtrim( trim( $notice_html ) ) ); |
| 52 | |
| 53 | update_user_meta( $current_user_id, WDN_Plugin::app()->getOptionName( 'hidden_notices' ), $get_hidden_notices ); |
| 54 | break; |
| 55 | } |
| 56 | |
| 57 | wp_send_json_success(); |
| 58 | } else { |
| 59 | wp_send_json_error( [ 'error_message' => __( 'You don\'t have permission to perform this action. Please contact your administrator.', 'disable-admin-notices' ) ] ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | add_action( 'wp_ajax_wbcr-dan-hide-notices', 'wbcr_dan_ajax_hide_notices' ); |
| 64 |