Last active
February 14, 2024 17:13
-
-
Save indigetal/6667739f79e137182ebee62fdd312a7b to your computer and use it in GitHub Desktop.
Add filter's to Content Block's of the Blocksy Theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This snippet allows custom filtering based on a content block's ID. | |
* | |
* To use, create a content-blocks-controls.php file in the child theme and add the followng line to the functions.php file: | |
* require_once get_stylesheet_directory() . '/content-blocks-controls.php'; | |
*/ | |
// Add a filter to modify the condition match for Blocksy Pro content blocks | |
add_filter( | |
'blocksy:pro:content-blocks:condition-match', // Filter hook | |
function ($matches, $content_block_id) { // Callback function accepting $matches and $content_block_id parameters | |
// Check if the content block ID matches a specific value (e.g., 15054) | |
if ($content_block_id === 15054) { | |
// Get the ID of the current resume being queried | |
$resume_id = get_queried_object_id(); | |
// Check if the current user has permission to view the resume | |
if (!resume_manager_user_can_view_resume($resume_id)) { | |
// If user cannot view the resume, return false to include the access denied message | |
return false; | |
} | |
} | |
// If the content block ID does not match the specified value or if the user has permission to view the resume, return the original matches | |
return $matches; | |
}, | |
10, // Priority of the filter | |
2 // Number of parameters passed to the callback function | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code snippet was supplied by Andrei from Blocksy in order to add any filter to a specific content block in the Blocksy companion plugin using its ID. It's basically the code version of their conditions module that can be used when we bump up against the limitations of the conditions module for whatever reason, such as in this example.
The specific Content Block filter example used here is re-implementing the "View Resume Capability" setting of the WP Job Manager Resumes addon to a Content Block that is overriding the single resume post type of that plugin. However, any content block filter can be added inside the callback
function ($matches, $content_block_id) {}
. So this is very useful across many other similar situations where we will want to add a filter to any Content Block for any reason!