| 1 |
<?php |
| 2 |
/** |
| 3 |
* This class responsible for database work |
| 4 |
* using wordpress functionality |
| 5 |
* get_option and update_option. |
| 6 |
*/ |
| 7 |
class NotificationX_DB { |
| 8 |
/** |
| 9 |
* Get all the notification |
| 10 |
* saved in options table. |
| 11 |
* @return array |
| 12 |
*/ |
| 13 |
public static function get_notifications(){ |
| 14 |
$notifications = get_option( 'notificationx_data', true ); |
| 15 |
return is_array( $notifications ) ? $notifications : []; |
| 16 |
} |
| 17 |
/** |
| 18 |
* Update notifications. |
| 19 |
* @param array $new_value |
| 20 |
* @return boolean |
| 21 |
*/ |
| 22 |
public static function update_notifications( $new_value ){ |
| 23 |
return update_option( 'notificationx_data', $new_value ); |
| 24 |
} |
| 25 |
/** |
| 26 |
* Get all settings value from options table. |
| 27 |
* or, get settings for a specific $key |
| 28 |
* |
| 29 |
* @param string $name |
| 30 |
* @return array |
| 31 |
*/ |
| 32 |
public static function get_settings( $name = '' ){ |
| 33 |
$settings = get_option( 'notificationx_settings', true ); |
| 34 |
|
| 35 |
if( ! empty( $name ) && isset( $settings[ $name ] ) ) { |
| 36 |
return $settings[ $name ]; |
| 37 |
} |
| 38 |
|
| 39 |
if( ! empty( $name ) && ! isset( $settings[ $name ] ) ) { |
| 40 |
return ''; |
| 41 |
} |
| 42 |
|
| 43 |
return is_array( $settings ) ? $settings : []; |
| 44 |
} |
| 45 |
/** |
| 46 |
* Update settings |
| 47 |
* @param array $value |
| 48 |
* @return boolean |
| 49 |
*/ |
| 50 |
public static function update_settings( $value ){ |
| 51 |
return update_option( 'notificationx_settings', $value ); |
| 52 |
} |
| 53 |
} |