API
1 month ago
Blocks
10 months ago
License
1 month ago
AdminNotice.php
3 weeks ago
AdminNotices.php
3 weeks ago
AjaxActions.php
3 weeks ago
Blocks.php
1 year ago
Compatibility.php
10 months ago
Learn.php
1 month ago
Menu.php
1 month ago
Migrations.php
1 year ago
NpsSurvey.php
5 months ago
Onboarding.php
3 weeks ago
Player.php
3 days ago
PluginInstaller.php
1 month ago
PreloadService.php
1 year ago
ProCompatibility.php
1 month ago
ReusableVideos.php
2 weeks ago
RewriteRulesManager.php
1 year ago
Scripts.php
2 weeks ago
Settings.php
1 month ago
Shortcodes.php
1 month ago
Streamer.php
3 weeks ago
Translation.php
3 weeks ago
Usage.php
3 weeks ago
VideoPostType.php
2 weeks ago
AdminNotice.php
94 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Temporary admin notice service. |
| 4 | * |
| 5 | * @package PrestoPlayer |
| 6 | */ |
| 7 | |
| 8 | namespace PrestoPlayer\Services; |
| 9 | |
| 10 | /** |
| 11 | * Stores and displays a one-time admin notice. |
| 12 | */ |
| 13 | class AdminNotice { |
| 14 | |
| 15 | const NOTICE_FIELD = 'presto_player_temp_admin_notice'; |
| 16 | |
| 17 | /** |
| 18 | * Display the stored admin notice, then remove it. |
| 19 | * |
| 20 | * @return void |
| 21 | */ |
| 22 | public static function displayAdminNotice() { |
| 23 | $option = get_option( self::NOTICE_FIELD ); |
| 24 | $message = isset( $option['message'] ) ? $option['message'] : false; |
| 25 | $notice_level = ! empty( $option['notice-level'] ) ? $option['notice-level'] : 'notice-error'; |
| 26 | |
| 27 | if ( $message ) { |
| 28 | printf( |
| 29 | '<div class="notice %s is-dismissible"><p>%s</p></div>', |
| 30 | esc_attr( $notice_level ), |
| 31 | wp_kses_post( $message ) |
| 32 | ); |
| 33 | delete_option( self::NOTICE_FIELD ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Queue an error notice. |
| 39 | * |
| 40 | * @param string $message Notice message. |
| 41 | * @return void |
| 42 | */ |
| 43 | public static function displayError( $message ) { |
| 44 | self::updateOption( $message, 'notice-error' ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Queue a warning notice. |
| 49 | * |
| 50 | * @param string $message Notice message. |
| 51 | * @return void |
| 52 | */ |
| 53 | public static function displayWarning( $message ) { |
| 54 | self::updateOption( $message, 'notice-warning' ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Queue an info notice. |
| 59 | * |
| 60 | * @param string $message Notice message. |
| 61 | * @return void |
| 62 | */ |
| 63 | public static function displayInfo( $message ) { |
| 64 | self::updateOption( $message, 'notice-info' ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Queue a success notice. |
| 69 | * |
| 70 | * @param string $message Notice message. |
| 71 | * @return void |
| 72 | */ |
| 73 | public static function displaySuccess( $message ) { |
| 74 | self::updateOption( $message, 'notice-success' ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Store the notice message and level for later display. |
| 79 | * |
| 80 | * @param string $message Notice message. |
| 81 | * @param string $notice_level Notice CSS level class. |
| 82 | * @return void |
| 83 | */ |
| 84 | protected static function updateOption( $message, $notice_level ) { |
| 85 | update_option( |
| 86 | self::NOTICE_FIELD, |
| 87 | array( |
| 88 | 'message' => $message, |
| 89 | 'notice-level' => $notice_level, |
| 90 | ) |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 |