We want to implement a filter for messages sent through the Better Messages plugin in WordPress. The filter should block messages containing specific keywords (e.g., “E-Mail”, “Telefon”, “@”, “au?erhalb”), while allowing all other messages to go through without issue. The goal is to prevent users from sharing contact information by blocking messages that contain these restricted terms.
Challenges Encountered:
Unfortunately, our current implementation either blocks all messages or allows all messages, without accurately filtering based on the specified keywords. Here is a detailed list of what we’ve tried so far and the issues with each approach:
Attempts Made
1. Using the better_messages_message_before_save Hook:
? Initially, we used the better_messages_message_before_save hook, provided by the Better Messages plugin, with a PHP function that checks for the specified keywords.
? Code Example:
function filter_and_block_messages($message_data) {
$blocked_keywords = array(‘E-Mail’, ‘Telefon’, ‘@’, ‘au?erhalb’);
if (isset($message_data[‘message’])) {
$message_text = $message_data[‘message’];
foreach ($blocked_keywords as $keyword) {
if (stripos($message_text, $keyword) !== false) {
wp_die(‘Your message contains restricted contact information and has been blocked.’);
}
}
}
return $message_data;
}
add_filter(‘better_messages_message_before_save’, ‘filter_and_block_messages’);
? Outcome:
Unfortunately, this code either blocked all messages (even those without the restricted keywords) or allowed all messages without filtering, depending on slight adjustments we made.
? Suspected Issue:
It appears that the hook better_messages_message_before_save does not behave as expected or may not provide access to the message content in a way that allows for accurate keyword checking.
2. Testing with Alternative Hooks (e.g., wp_insert_post_data):
? We then attempted to use WordPress’s general post-insertion hook, wp_insert_post_data, to capture messages before they are saved. We adjusted the code to focus specifically on the message post type to avoid interfering with other content.
? Outcome:
Messages were not blocked as expected, and the hook did not seem to capture Better Messages content reliably. All messages went through without filtering.
? Suspected Issue:
The Better Messages plugin may not use the standard wp_insert_post_data workflow for saving messages, and as a result, this hook did not work.
3. Client-Side JavaScript Filtering:
? As an alternative, we tried adding JavaScript to filter messages on the client side before they are sent. This involved detecting the message content in the text area and blocking the send button if restricted keywords were found.
? Outcome:
While technically effective in some scenarios, this solution is not reliable. JavaScript-based filtering can easily be bypassed by users with minimal technical knowledge, and it does not provide the security or reliability of a server-side filter.
? Limitation:
Client-side filtering is generally not recommended for secure content filtering, as it is more vulnerable to bypass methods and doesn’t guarantee that messages will be blocked once they reach the server.
4. Debugging the Hook and Reviewing Output Logs:
? We included debugging statements to verify whether the better_messages_message_before_save hook was even running as expected and to confirm that the message content was accessible at that point.
? Outcome:
Debugging outputs showed inconsistent behavior, indicating that the hook might not be designed to handle content filtering in the way we intended, or it might be overridden by the Better Messages plugin’s internal processing.
Summary of the Issue
After numerous attempts with different hooks, custom PHP functions, and JavaScript, we are unable to achieve the desired outcome of blocking messages based on specific keywords. Either all messages are blocked, or none are filtered based on the keywords, which suggests that the better_messages_message_before_save hook may not be functioning as expected, or that Better Messages handles message content differently.
Request for Help
We are looking for guidance on the following points:
1. Confirmation of the Appropriate Hook:
Is better_messages_message_before_save the correct hook for filtering message content before it’s saved? If not, is there an alternative hook or method within Better Messages to achieve this?
2. Example Code or Best Practice:
If possible, an example of how to properly intercept and filter message content within Better Messages based on specific keywords would be highly appreciated.
3. Documentation or Further Support:
Any additional documentation or references on how Better Messages handles message content storage and filtering would be very helpful.
We appreciate any insights or suggestions from the community or the developers of Better Messages to help us achieve this functionality.
]]>I need help with my author page. It sends nofollow links to my blogposts and I would like to switch them into dofollow links.
How can I edit the author page and the outgoing links?
Thanks in advance.
Melissa
Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/ea-php73) in /home/fordhoow/public_html/wp-content/plugins/custom-sidebars/inc/external/wpmu-lib/inc/class-thelib.php on line 145
Notice: add_submenu_page was called incorrectly. The seventh parameter passed to add_submenu_page() should be an integer representing menu position. Please see Debugging in WordPress for more information. (This message was added in version 5.3.0.) in /home/fordhoow/public_html/wp-includes/functions.php on line 4986
]]>I am facing issue with the WP Ocean theme – more specifically, when the theme is activated, logo does not display on the website even after I’ve tried different logo sizes (thinking that might be the issue as my previous logo was too big).
When I deactivate the theme or even when I use custom logo widget for Elementor , the logo is displayed properly. This seems to be a common issue with the theme. Please help. I am using Elementor widget for the time being.
Thanks in advance.
Rishabh
]]>I hope you can help me. I am using Ocean WP theme.
I have some ‘Build Your Own’ products using Woo Commerce extensions.
I would like to change the layout so that when you click on the second tab in the form (choose your macarons), the 30 products are not in a long un-user friendly list but in a nice grid, rows/columns (or scrolling carousel).
I know within the Woocommerce bundled products there is an option to change the view to ‘grid’ but it seems either that this theme is incompatible with it, or the composite product (which the bundled products sit in) is incompatible with it. Instead of a nice grid of say 6 rows of 5 products, it is showing 1 product at a time fulltime in a vertical list.
Is there anything I can do about this?
Thank you!
]]>I hope you can help me.
I have some ‘Build Your Own’ products using Woo Commerce extensions.
I would like to change the layout so that when you click on the second tab in the form (choose your macarons), the 30 products are not in a long un-user friendly list but in a nice grid, rows/columns (or scrolling carousel).
I know within the Woocommerce bundled products there is an option to change the view to ‘grid’ but it seems this theme is incompatible with it. Instead of a nice grid of say 6 rows of 5 products, it is showing 1 product at a time fulltime in a vertical list.
Is there anything I can do about this?
]]>Pls have a look at my site, and as it shows, it’s not the correct layout. While I set the theme to Twenty Seventeen. the layout comes right.
May I know are there any problem with the theme or my settings?
Regards
]]>