PHP code example of rumur / wp-notice

1. Go to this page and download the library: Download rumur/wp-notice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rumur / wp-notice example snippets

 console vendor:publish --provider='Rumur\WordPress\Notice\NoticeServiceProvider'


// functions.php

// Clean WordPress installation.
\Rumur\WordPress\Notice\Notice::registerIntoWordPress();

// Alternative way of doing this.
add_action('admin_notices', [\Rumur\WordPress\Notice\Notice::class, 'render']); 

// Themosis 2.x or Sage 10.x Installation, after you've used `vendor:publish` command.
\Notice::registerIntoWordPress();

// Or there is another alternative way.
// Themosis 2.x or Sage 10.x Only
\Rumur\WordPress\Notice\Facades\Notice::registerIntoWordPress();

// Or even as a function
// Themosis 2.x or Sage 10.x Only
notice()->registerIntoWordPress();

/**
 * The notice function that just need to return a string.
 *
 * @return string    
 */
function rmr_notice_as_function() {
    return __('Hello From Function', 'text-domain');
}



// App/Notices/ExampleNotification.php

namespace App\Notices;

use Rumur\WordPress\Notice\Noticeable;

class ExampleNotification extends Noticeable
{
    public function message(): string
    {
        return __('I can change the info here', 'text-domain');
    }
}



use App\Notices\ExampleNotification;
use App\Domain\Orders\OrderRepository;
use Rumur\WordPress\Notice\Notice;

$order = OrderRepository::find(2020); 

if ($order->isPayed()) {
    // Simple way.
    Notice::info(__('Congrats', 'text-domain'));

    // Makes a success message from the Noticeable instance
    Notice::success(new ExampleNotification)
        // ⚠️ OPTIONAL ⚠️
        // Will be always displaying the notice, 
        // unless `DISABLE_NAG_NOTICES` defined and it's set as `true`
        // @link https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices#Disable_Nag_Notices
        ->nag()
        // ⚠️ OPTIONAL ⚠️
        // Makes a notice be dismissible. Adds a close button to the notice.
        ->dismissible()
        // ⚠️ OPTIONAL ⚠️
        // Makes a notice display it in an alternative way, 
        // by adding a background color that corresponds to its type.  
        ->asAlternative()
        // ⚠️ OPTIONAL ⚠️
        // This options tells to a notice to postpone itself and show only when time.
        ->showLater('tomorrow')
        // ⚠️ OPTIONAL ⚠️
        // This options tells to a notice to always show up until time.
        ->showUntil('next friday')
        // ⚠️ OPTIONAL ⚠️
        // Tells to a notice to show up only on this pages.
        ->showWhenPage('themes', 'tools' /*,...*/ )
        // ⚠️ OPTIONAL ⚠️
        // Tells to a notice to show up only if the logged in user has specific role.
        ->showWhenRole('subscriber', 'author' /*,...*/ )
        // ⚠️ OPTIONAL ⚠️
        // Tells to a notice to show up only if the logged in user has specific id.
        ->showWhenUser(1, get_user_by('id', 25) /*,...*/)
        // ⚠️ OPTIONAL ⚠️
        // Tells to a notice to show up only if the current screen is for specific taxonomies.
        ->showWhenTaxonomy('category', 'post_tag' /*,...*/ )
        // ⚠️ OPTIONAL ⚠️
        // Tells to a notice to show up only if the current screen is for specific post type.
        ->showWhenPostType('post', 'page' /*,...*/ );
}