Frontier Post – Actions & Hooks
The following hooks are available in Frontier Post:
- Filter: frontier_post_pre_update
- Filter: frontier_post_mod_cmt_update
- Action: frontier_post_post_save
- Action: frontier_post_form_standard
- Action: frontier_post_form_standard_top
- Action: frontier_post_form_standard_tax
- Action: frontier_post_form_quickpost
- Action: frontier_post_form_quickpost_top
- Action: frontier_post_list_top (Action fires before displaying posts)
- Action: frontier_post_list_record (Action fires before each post record)
- Action: frontier_post_list_botttom (Action fires after displaying posts)
- Filter: frontier_post_msg_output (Enable manipulation of output message $tmp_msg)
- Action: frontier_post_custom_msg (executes just after add/update messages are output)
Examples on how to use the Frontier Post form actions:
Filter: frontier_post_pre_update
Fires before post is saved.
//****************************************************************************************************
// Update post
//****************************************************************************************************
$tmp_post = array(
'ID' => $postid,
'post_type' => $tmp_post_type,
'post_title' => $tmp_title,
'post_status' => $post_status,
'post_content' => $tmp_content,
'post_excerpt' => $tmp_excerpt
);</code>
// Do not manage categories for page
if ( $tmp_post_type != 'page' )
{
$tmp_post['post_category'] = $tmp_categorymulti;
}
//****************************************************************************************************
// Apply filter before update of post
// filter: frontier_post_pre_update
// $tmp_post Array that holds the updated fields
// $tmp_task_new Equals true if the user is adding a post
// $_POST Input form
//****************************************************************************************************
$tmp_post = apply_filters( 'frontier_post_pre_update', $tmp_post, $tmp_task_new, $_POST );
Filter: frontier_post_mod_cmt_update
//****************************************************************************************************
// Apply filter before update of moderation comments
// filter: frontier_post_mod_cmt_update
// $fp_moderation_comments
// $my_post post record object
// $tmp_task_new Equals true if the user is adding a post
// $_POST Input form
// FRONTIER_POST_MODERATION_TEXT in $_POST is where the moderation momments are enterd
//****************************************************************************************************
$fp_moderation_comments = apply_filters( 'frontier_post_mod_cmt_update', $fp_moderation_comments, $my_post, $tmp_task_new, $_POST );
Action: frontier_post_post_save
Fires after post is saved, can be used to update custom fields
//****************************************************************************************************
// End updating post
//****************************************************************************************************
//Get the updated post
$my_post = get_post($postid);
//****************************************************************************************************
// Avtion fires after add/update of post, and after taxonomies are updated
// Do action frontier_post_post_save
// $my_post Post object for the post just updated
// $tmp_task_new Equals true if the user is adding a post
// $_POST Input form
//****************************************************************************************************
do_action('frontier_post_post_save', $my_post, $tmp_task_new, $_POST);
Example of how it is possible to use filter to add a validation.
If you want to ensure that the user select a valid category you can insert the below code in functions.php in your active theme. Please note that Frontier Post will set category equal to the default wordpress category (set in settings/writing), so the below example checks if category is empty or equal to the default category.
The below code will then set post status to draft and issue a warning:
Requires Frontier Post version > 3.4.3
// check if categories are empty or only contains default category - if so set status to draft and issue a warning message
function fp_cat_validation($tmp_post, $tmp_task_new, $_POST )
{
$tmp_cat = array_key_exists('post_category', $tmp_post) ? $tmp_post['post_category'] : array();
if (count($tmp_cat) == 0)
{
$tmp_post['post_status'] = 'draft';
frontier_post_set_msg("Warning: Category is empty, please select category - Status set to draft");
}
if (count($tmp_cat) == 1 && $tmp_cat[0] == get_option("default_category"))
{
$tmp_post['post_status'] = 'draft';
frontier_post_set_msg("Warning: Category is set to: ".get_cat_name(get_option("default_category")).", please select category - Status set to draft");
}
return $tmp_post;
}
add_filter('frontier_post_pre_update', 'fp_cat_validation',10,3);
- Filter: frontier_post_msg_output (Enable manipulation of output message $tmp_msg)
- Action: frontier_post_custom_msg (executes just after add/update messages are output)
function frontier_post_output_msg($tmp_msg_type = "default")
{
if ( fp_get_option_bool("fps_show_msg") )
{
$tmp_msg = isset($_REQUEST['frontier-post-msg']) ? $_REQUEST['frontier-post-msg'] : '';
//****************************************************************************************************
// Apply filter before output of message
// filter: frontier_post_msg_output
// $tmp_msg Array that holds the updated fields
// $tmp_msg_type Equals true if the user is adding a post
//****************************************************************************************************
$tmp_msg = apply_filters( 'frontier_post_msg_output', $tmp_msg, $tmp_msg_type );
echo '<div class="frontier_post_msg">'.$tmp_msg.'</div>';
}
// This way cusom messages can be output
do_action('frontier_post_custom_msg', $tmp_msg, $tmp_msg_type );
$_REQUEST['frontier-post-msg'] = null;
}
Comments
Frontier Post – Actions & Hooks — No Comments