-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add required_value attribute to s2MOP shortcode. #51
Conversation
if(empty($_g['_s2member_req']['type']) || !in_array($_g['_s2member_req']['type'], $attr['required_type'], TRUE)) | ||
return ''; | ||
|
||
if(isset($attr['required_value']) && ( count($attr['required_type']) !== 1 || !in_array($_g['_s2member_req'][$_g['_s2member_req']['type']], $attr['required_value'], TRUE))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaswsinc I'm not sure if there is a cleaner way referencing the value of one array ($_g['_s2member_req']['type']
) inside another, as I did here:
$_g['_s2member_req'][$_g['_s2member_req']['type']]
It looks hard to read, but the only alternative--assigning that value to a separate variable and then using the variable in the array--seemed like a lot of extra code (assigning the value and then unsetting the value).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fine to create another variable to help make this clearer. What you have is fine too. I just mean to say that (for me) I would be OK with another few lines of code if that makes it's easier to read, understand, and come back to in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fine to create another variable to help make this clearer.
Cool. Thanks! I've updated this line for clarity.
Cool! Love the way you set things up. I was looking at this line. I think we should add Also, in this block the use of |
- Add required_value attribute to shortcode_attrs() - Remove unnecessary isset() conditionals - Clarify required_value attribute conditional
Weird. I thought I added that there. Thanks for catching that.
Ah, good point. I removed the |
Add required_value attribute to s2MOP shortcode.
Great, thanks @raamdev 👍 |
Resolves wpsharks/s2member#305.
@jaswsinc I've tested this and it seems to work as expected but would appreciate a code review:
required_type=""
contains multiple values (e.g.,required_type="ccap|level"
), therequired_value=""
attribute is ignored.required_value=""
attribute supports multiple values (e.g.,required_value="0|1|2"
orrequired_value="ccap1|ccap2|ccap3"
)Tested with these shortcodes: