Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from TeemuSuoranta/master
Browse files Browse the repository at this point in the history
Add filter to create admin notice in shadow
  • Loading branch information
ottok committed Mar 6, 2017
2 parents 0e4e83c + 18b32b3 commit bfb019a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ Use the "WPIS-" -prefix followed by the name of your instance to name the consta
Use the hash part of your container name to define the constant value. If the name of
your container is "asdasd_123", use "123" to define the value.

## Filters

You can insert your own admin notice for users that are in shadow
```php
function my_shadow_admin_notice($admin_notice, $current_screen) {
return '<div class="notice notice-error"><p>This is staging. All content edited here will be lost. Return to production to create or edit content.</p></div>';
}
add_filter( 'wpp_instance_switcher_admin_notice', 'my_shadow_admin_notice', 10, 2 );
```
12 changes: 12 additions & 0 deletions wp-palvelu-instance-switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected function __construct(){
add_action('admin_footer', array( $this, 'render_shadow_indicator' ) );
add_action('wp_footer', array( $this, 'render_shadow_indicator' ) );
add_action('login_footer', array( $this, 'render_shadow_indicator' ) );
add_action('admin_notices', array( $this, 'render_shadow_admin_notice' ) );
}
}

Expand Down Expand Up @@ -179,6 +180,17 @@ public function render_shadow_indicator() {
<?php
}

/**
* Let plugins or themes display admin notice when inside a shadow
*/
public function render_shadow_admin_notice( $current_screen ) {
$current_screen = get_current_screen();
$admin_notice_content = apply_filters( 'wpp_instance_switcher_admin_notice', '', $current_screen );
if(!empty($admin_notice_content)) {
echo $admin_notice_content;
}
}

/**
* Load our textdomain
*/
Expand Down

0 comments on commit bfb019a

Please sign in to comment.