Notes on advanced usage of iPROS24 Notices plugin. Ready-to-go examples.
Contents
Adding custom conditions
You may add any number of custom conditions in Dashboard › Settings › Notices. Condition names may contain alphanumeric characters, spaces and underscores and start with a letter or underscore.
All custom conditions are false by default. You need to add a filter for a server-side condition and set a variable for a client-side one.
- Notices – Plugin settings
Examples
Let’s add a server-side condition which is true when a user is logged in and is an administrator.
- Go to Dashboard › Settings › Notices.
- Enter Is admin condition name in Custom server-side conditions section.
- Click Add.
The name of the filter appears in WordPress filter column.
- Add the following lines to Server-side script:
function ipros24_notices_is_admin () { global $current_user; return in_array ("administrator", $current_user->roles); } add_filter ('ipros24_notices_is_admin', 'ipros24_notices_is_admin');
- Click Save Changes.
Done. Now we have a condition we can use e.g. to preview notices on a production site.
Now let’s add a client-side condition which is true when it’s Christmas in user’s timezone.
- Go to Dashboard › Settings › Notices.
- Enter Is Xmas condition name in Custom client-side conditions section.
- Click Add.
The name of the variable appears in JavaScript variable column.
- Add the following lines to Client-side script:
$ (window).on ("ipros24-notices-filter", function () { var today = new Date (); ipros24_notices.is_xmas = (today.getMonth () == 11 && today.getDate () == 25); });
- Click Save Changes.
We have a condition we can use to greet our visitors on a Christmas day.
Creating notices
Go to Dashboard › Notices and Add New notice. Notices are implemented as a custom post type so adding a notice is not much different from adding a post.
After you finish editing select the conditions to be met in Notice Attributes box.
NB: Use server-side conditions to filter sensitive notices.
- Notices – Editing a notice
Examples
Let’s add a warning some features of the site won’t work if cookies are disabled in user’s browser.
- Go to Dashboard › Notices and click Add New.
- Enter the notice. E.g. You have to enable cookies for this site to work properly.
- Select Cookies enabled › False in Notice Attributes box.
- Click Update.
Done.
Personalising the notices
There’s a shortcode you can use to personalise your notices. It will be replaced with the user’s display name or the text between the tags if the user hasn’t logged in yet.
- Notices – Personalised and password protected notices
Examples
Merry Xmas, [ipros24_user]friend[/ipros24_user]!
Notes on security
Only administrators of single site installations have the capability to edit server-side scripts. In multisite only the Super Admin has this capability. To completely disable server-side scripts editing add to wp-config.php:
define ('ALLOW_EDIT_SERVER_SIDE_SCRIPTS', FALSE);