notifications_list[ $notification_group ] ) && ( is_array( $this->notifications_list[ $notification_group ] ) && count( $this->notifications_list[ $notification_group ] ) > 0 ) ) {
$notification_group_arr = [];
$notification_group_arr[ $notification_group ] = $this->notifications_list[ $notification_group ];
return $notification_group_arr;
}
return $this->notifications_list;
}
/**
* This is used to register a notification
*
* @param array $notification_value
* @param string $group
*
* @return array
*/
public function register_notification( $notification_value = [], $group = '' ) {
$error = [
'error' => 'Notification not register checkout your notification array or group name ',
];
if ( ( ! is_array( $notification_value ) || sizeof( $notification_value ) >= 2 ) || '' === $group ) {
$error['error'] = 'Check Your notification array format or notification group name';
return $error;
}
if ( ! is_array( $notification_value ) || count( $notification_value ) === 0 ) {
return $error;
}
$notice_key = key( $notification_value );
if ( isset( $this->notifications_list[ $group ][ $notice_key ] ) ) {
return $error;
}
$this->notifications_list[ $group ][ $notice_key ] = $notification_value[ $notice_key ];
return [
'success' => $notice_key . ' Key Set',
];
}
/**
* This is used to deregister a notification based on notification key and group
*
* @param string $notification_key
* @param string $notification_group
*
* @return array
*/
public function deregister_notification( $notification_key = '', $notification_group = '' ) {
$error = [
'error' => $notification_key . ' Key or notification group may be not Available.',
];
if ( '' === $notification_key || '' === $notification_group ) {
$error['error'] = 'Check your notification key and their group. Both are required for deletion';
return $error;
}
if ( ! isset( $this->notifications_list[ $notification_group ][ $notification_key ] ) || ! is_array( $this->notifications_list[ $notification_group ][ $notification_key ] ) || count( $this->notifications_list[ $notification_group ][ $notification_key ] ) === 0 ) {
return $error;
}
unset( $this->notifications_list[ $notification_group ][ $notification_key ] );
return [
'success' => $notification_key . ' Notices has been removed',
];
}
/**
* Display internal CSS
*/
public function notification_inline_style() {
?>
'failed',
'success' => 'false',
'msg' => 'Problem With dismiss',
);
check_ajax_referer( 'bwf_notice_dismiss', '_nonce' );
if ( ( isset( $_POST['noticeGroup'] ) && $_POST['noticeGroup'] !== '' ) && ( isset( $_POST['noticekey'] ) && $_POST['noticekey'] !== '' ) ) {
$noticeGroup = sanitize_text_field( $_POST['noticeGroup'] );
$noticekey = str_replace( 'wf-', '', sanitize_text_field( $_POST['noticekey'] ) );
$notices_display = get_option( 'wf_notification_list_' . $noticeGroup, [] );
$notice = $this->get_notification( $noticekey, $noticeGroup );
if ( ! is_array( $notices_display ) ) {
unset( $notices_display );
$notices_display = [];
}
if ( is_array( $notice ) && count( $notice ) > 0 ) {
$notices_display[] = $noticekey;
update_option( 'wf_notification_list_' . $noticeGroup, $notices_display );
}
$results = array(
'status' => 'success',
'success' => 'true',
'msg' => $noticekey . ' Notification Deleted',
);
}
wp_send_json( $results );
}
/**
* This will return the notification based on notification key and the group id
*
* @param string $notification_key
* @param string $notification_group
*
* @return array
*/
public function get_notification( $notification_key = '', $notification_group = '' ) {
$error = [
'error' => $notification_key . ' Key or Notification group may be Not Available.',
];
if ( '' === $notification_key || '' === $notification_group ) {
$error['error'] = 'Check your Notification Key and Their group. Both are required';
}
if ( isset( $this->notifications_list[ $notification_group ][ $notification_key ] ) && is_array( $this->notifications_list[ $notification_group ][ $notification_key ] ) && count( $this->notifications_list[ $notification_group ][ $notification_key ] ) > 0 ) {
return $this->notifications_list[ $notification_group ][ $notification_key ];
}
return $error;
}
/**
* Return the updated dismiss notification keys
*
* @param $group
*
* @return array|mixed|void
*/
public function get_dismiss_notification_key( $group ) {
if ( '' === $group ) {
return [
'error' => 'Need to a notice group for update key',
];
}
$notices_display = get_option( 'wf_notification_list_' . $group, [] );
if ( ! is_array( $notices_display ) ) {
$notices_display = [];
}
return $notices_display;
}
/**
* Display the notifications HTML
*
* @param $notifications_list
*/
public function get_notification_html( $notifications_list ) {
include dirname( dirname( __FILE__ ) ) . '/views/woofunnels-notifications.php';
}
}
}