ballooninging
Forum Replies Created
-
Forum: Plugins
In reply to: [Simple Membership] Selectively Locking Hyperlinks from Non-MembersThe filters work is that you ALWAYS have to return the “content” that is passed to your function via the filter (whether you change it not).
If you don’t return anything then that means you modified the content and returned and empty string (because that’s allowed if that’s what you want to do).
So if you don’t return anything, it means you want to show nothing which is what it was doing when you weren’t returning it correctly.
Right, got it. Thanks much!
Forum: Plugins
In reply to: [Simple Membership] Selectively Locking Hyperlinks from Non-MembersFound the issue – I was not returning
$smb_contentat the end of the conditionals. Once that was returned, the login and registration pages began displaying the correct output:add_filter('the_content','smb_replace_content', 1, 1); function smb_replace_content($smb_content) { if (is_single()) { if(!SwpmMemberUtils::is_member_logged_in()) { $smb_content = preg_replace('/<a href="https:\/\/docs.google.com\/spreadsheets\/d\/.+"/', '<a href="#" hoho' ,$smb_content); } } return $smb_content; }I also removed the redundant “else” statement – I was wondering if I needed to specifically return
$smb_content, but it turns out that I just needed to return it outside the conditionals.Just curious, any idea why this is the case? Am happy to learn more about WP development.
Forum: Plugins
In reply to: [Simple Membership] Selectively Locking Hyperlinks from Non-MembersHello,
I did up a very simple, rough plugin that does the following:
1. Identifies if the current web page is a “post”
2. If it is, and if the link matches the regex, replace the link with another URL (it’s currently a placeholder)
3. If not, does nothing.Code as shown below:
add_filter('the_content','smb_replace_content'); function smb_replace_content($smb_content) { if (is_single()) { if(!SwpmMemberUtils::is_member_logged_in()) { $smb_content = preg_replace('/<a href="https:\/\/docs.google.com\/spreadsheets\/d\/.+"/', '<a href="#"' ,$smb_content); return $smb_content; } else { return $smb_content; } } }This works well so far. However, I realised that this line:
add_filter('the_content','smb_replace_content');is conflicting with the simple-membership-plugin, such that it refuses to display any content on the login page and the registration page.
Is it a priority issue? Were there cases where anyone has tried to extend this plugin by filtering through the
the_contenthook, and encountered this error?Any possible ways this may be resolved?
Thanks in advance!
Forum: Plugins
In reply to: [Simple Membership] Selectively Locking Hyperlinks from Non-MembersHi, you might like to check the following documentation. Here you will find some PHP tweaks that will help you with what you are trying to achieve.
Thanks! I’ve already went through this (which was how I got the utility
SwpmMemberUtils::is_member_logged_in()), I’m currently stopped by how to implement this in the first place – will keep this thread updated on how I solved this problem.