-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreadme.txt
More file actions
134 lines (107 loc) · 3.2 KB
/
readme.txt
File metadata and controls
134 lines (107 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
=== if-elseif-else Shortcode ===
Contributors: n8kowald
Donate link: https://www.paypal.me/nkowald
Tags: shortcode
Requires at least: 4.5
Tested up to: 5.2.2
Stable tag: 0.1.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Allows you to use if-elseif-else conditions in your editor content via an [if] shortcode.
== Description ==
This plugin adds a new shortcode [if] that allows you to use if-elseif-else shortcodes in your editor content.
```
[if is_super_admin]
Hello Admin
[elseif is_user_logged_in]
Hello registered user
[else]
Hello, please log in
[/if]
```
The following callables are allowed by default.
```
comments_open
is_404
is_admin
is_archive
is_author
is_category
is_day
is_feed
is_front_page
is_home
is_month
is_page
is_search
is_single
is_singular
is_sticky
is_super_admin
is_tag
is_tax
is_time
is_user_logged_in
is_year
pings_open
```
To allow other callables you can use the `if_elseif_else_shortcode_allowed_callables` filter.
```
<?php
add_filter( 'if_elseif_else_shortcode_allowed_callables', function( $whitelist ) {
$whitelist[] = 'your_callable_here';
return $whitelist;
});
```
== Installation ==
1. Upload plugin to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
== Frequently Asked Questions ==
= What callables are supported? =
String callables are supported:
* Function names: is_user_logged_in
* Static class method calls (>=PHP 5.2.3): MyClass::myCallbackMethod
```
[if is_user_logged_in]
Hello user
[elseif UserAccessControl::is_member_logged_in]
Hello member
[else]
Hello, please log in
[/if]
```
Note: in the above example, you would need to add `UserAccessControl::is_member_logged_in` to the allowed callables whitelist.
You can do this using the `if_elseif_else_shortcode_allowed_callables` filter.
= Can I pass parameters to callables? =
Yes.
```
[if is_singular books]
Related books here.
[/if]
```
If your callable accepts multiple parameters you can pass them in as a space separated string.
```
function is_garfield( $animal, $colour ) {
return $animal === 'cat' && $colour === 'orange';
}
[if is_garfield cat orange]
Yes, this is garfield.
[/if]
```
== Screenshots ==
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot
== Changelog ==
= 0.1.0 =
* Committed the plugin
== Upgrade Notice ==
== Testing ==
If you want to simplify the if_elseif_else_statement() function, a WordPress test class exists for you to test your refactored code.
*Install test framework and database*
`./bin/install-wp-tests.sh {db-name} {db-user} {db-pass} [db-host] [wp-version] [skip-database-creation]`
*Example*
Run this from the plugin directory:
`./bin/install-wp-tests.sh wordpress_tests mysql_username mysql_password`