diff --git a/admin/class-yoast-notification-center.php b/admin/class-yoast-notification-center.php new file mode 100644 index 00000000000..cb7b6876c24 --- /dev/null +++ b/admin/class-yoast-notification-center.php @@ -0,0 +1,78 @@ + 0 ) { + foreach ( $json_notifications as $json_notification ) { + $notifications[] = new Yoast_Notification( $json_notification['message'], $json_notification['type'] ); + } + } + } + + return $notifications; + } + + /** + * Display the message + */ + public static function display_notices() { + + // Get the messages + $notifications = self::get_notifications_from_cookie(); + + // Display notifications + if ( count( $notifications ) > 0 ) { + foreach ( $notifications as $notification ) { + add_action( 'all_admin_notices', array( $notification, 'output' ) ); + } + } + + // Remove the cookie + setcookie( self::COOKIE_KEY, null, -1 ); + } + + /** + * Add notification to the cookie + * + * @param Yoast_Notification $notification + */ + public static function add_notice( Yoast_Notification $notification ) { + + // Get the messages + $notifications = self::get_notifications_from_cookie(); + + // Add the message + $notifications[] = $notification; + + // Create array with all notifications + $arr_notifications = array(); + + // Add each notification as array to $arr_notifications + foreach($notifications as $notification ) { + $arr_notifications[] = $notification->to_array(); + } + + // Set the cookie with notifications + setcookie( self::COOKIE_KEY, json_encode( $arr_notifications ), time() * 60 * 10 ); + } + +} \ No newline at end of file diff --git a/admin/class-yoast-notification.php b/admin/class-yoast-notification.php new file mode 100644 index 00000000000..143bf9ec58f --- /dev/null +++ b/admin/class-yoast-notification.php @@ -0,0 +1,66 @@ +message = $message; + $this->type = $type; + } + + /** + * @return String + */ + public function get_message() { + return $this->message; + } + + /** + * @param String $message + */ + public function set_message( $message ) { + $this->message = $message; + } + + /** + * @return String + */ + public function get_type() { + return $this->type; + } + + /** + * @param String $type + */ + public function set_type( $type ) { + $this->type = $type; + } + + /** + * Return the object properties as an array + * + * @return array + */ + public function to_array() { + return array( + 'message' => $this->get_message(), + 'type' => $this->get_type() + ); + } + + /** + * Output the message + */ + public function output() { + echo '

' . $this->get_message() . '

' . PHP_EOL; + } + +} \ No newline at end of file diff --git a/wp-seo-main.php b/wp-seo-main.php index 8f0877dc907..4570183bd7e 100644 --- a/wp-seo-main.php +++ b/wp-seo-main.php @@ -76,6 +76,9 @@ function wpseo_auto_load( $class ) { 'yoast_plugin_license_manager' => WPSEO_PATH . 'admin/license-manager/class-plugin-license-manager.php', 'yoast_product' => WPSEO_PATH . 'admin/license-manager/class-product.php', + 'yoast_notification_center' => WPSEO_PATH . 'admin/class-yoast-notification-center.php', + 'yoast_notification' => WPSEO_PATH . 'admin/class-yoast-notification.php', + 'wp_list_table' => ABSPATH . 'wp-admin/includes/class-wp-list-table.php', 'walker_category' => ABSPATH . 'wp-includes/category-template.php', 'pclzip' => ABSPATH . 'wp-admin/includes/class-pclzip.php', @@ -262,6 +265,9 @@ function wpseo_admin_init() { if ( $options['enablexmlsitemap'] === true ) { $GLOBALS['wpseo_sitemaps_admin'] = new WPSEO_Sitemaps_Admin; } + + // Display Yoast notifications + Yoast_Notification_Center::display_notices(); } add_action( 'plugins_loaded', 'wpseo_init', 14 );