Last active
April 11, 2025 09:16
-
-
Save mlbd/ed400b5cd581bc2718e73718d19ca7d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Filter to modify the 'oasiswf_placeholders' site option after it's retrieved. | |
* This ensures that our custom placeholder (%post_id%) is always available | |
* alongside the existing ones. | |
* | |
* @param array $value The existing array of placeholders. | |
* @return array Modified array with the additional %post_id% placeholder. | |
*/ | |
add_filter( 'site_option_oasiswf_placeholders', 'modify_existing_oasiswf_placeholders' ); | |
function modify_existing_oasiswf_placeholders( $value ) { | |
// Ensure we have an array to work with | |
if ( ! is_array( $value ) ) { | |
$value = []; | |
} | |
// Add the custom placeholder without removing existing ones | |
$value['%post_id%'] = 'Post ID'; | |
return $value; | |
} | |
/** | |
* Filter to handle the value replacement for custom placeholders used by Oasis Workflow. | |
* When the %post_id% placeholder is used, it will be replaced with the current post ID. | |
* | |
* @param WP_Post $post The current post object being processed. | |
* @return array Array of custom placeholder keys and their corresponding values. | |
*/ | |
add_filter( 'oasiswf_custom_placeholders_handler', 'ow_get_submitter_placeholder_value', 10, 1 ); | |
function ow_get_submitter_placeholder_value( $post ) { | |
$custom_placeholders_values = array( | |
'%post_id%' => $post->ID, | |
); | |
return $custom_placeholders_values; | |
} | |
/** | |
* Filter to provide values for custom email placeholders in Oasis Workflow. | |
* This function adds support for replacing the `{post_id}` placeholder with the actual post ID | |
* in email templates sent by the plugin. | |
* | |
* @param int $post_id The ID of the post being processed. | |
* @return array Array of placeholder-value pairs used in email content. | |
*/ | |
add_filter( 'oasiswf_emails_placeholders_handler', 'ow_emails_placeholders_handler', 10, 1 ); | |
function ow_emails_placeholders_handler( $post_id ) { | |
$custom_placeholders_values = array( | |
'{post_id}' => $post_id, // Replace {post_id} in emails with the actual post ID | |
); | |
return $custom_placeholders_values; | |
} | |
/** | |
* Filter to register custom placeholders available for use in Oasis Workflow email templates. | |
* This adds `{post_id}` to the list of supported email placeholders in the plugin's settings or UI. | |
* | |
* @param array $list Existing list of email placeholders. | |
* @return array Modified list with the new {post_id} placeholder. | |
*/ | |
add_filter( 'oasiswf_emails_placeholders', 'ow_emails_placeholders_list', 10, 1 ); | |
function ow_emails_placeholders_list( $list ) { | |
// Ensure we have an array to work with | |
if ( ! is_array( $list ) ) { | |
$list = []; | |
} | |
// Add our custom placeholder to the list of email placeholders | |
$list['{post_id}'] = esc_html__( 'Post ID', 'oasisworkflow' ); | |
return $list; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment