Actions and Filters (Hooks) in Frontier Post
Actions and Filters are made available for your use, but is not supported, meaning I can not help you implementing Actions and Filters
The following hooks are available in Frontier Post:
Examples of use of Actions and Filters is made available as a demo plugin: Frontier Post – Extension Plugin ()
Download plugin file: frontier-post-my-extensions
Add / Edit Posts
- Filter: frontier_post_pre_update (file: frontier-submit-form.php)
- From v. 3.4.5
- Allows manipulation of $tmp_post that inserts/updates post
- Filter: frontier_post_mod_cmt_update (file: frontier-submit-form.php)
- From v. 4.4.0
- Allows manipulation of the Post Moderation Comments, $fp_moderation_comments
- Filter: frontier_post_msg_output (function: frontier_post_output_msg(), file: frontier-post-util.php )
- From v. 4.4.0
- Enable manipulation of output message $tmp_msg – input 2 variables:
- $tmp_msg: The message retrieved from the form ($_REQUEST[‘frontier-post-msg’])
- $tmp_msg_type: Message type
- Action: frontier_post_post_save (file: frontier-submit-form.php)
- From v. 4.4.0
- Action fires after Post is saved, and all other processing is completed, to allow to additional updates (eg. custom fields) action passes 3 variables for use:
- $my_post: Post object for the post just updated
- $tmp_task_new: Equals true if the user is adding a post
- $_POST Input form
- Action: frontier_post_form_standard_init (file: frontier_post_form_standard.php)
- From v.5.1.6
- Allows insert of html, fires just after form is defined, before fields – Passes 3 variables
- $thispost: Post object for the post
- $tmp_task_new: Equals true if the user is adding a post
-
$fpost_sc_parms: Shortcode parameters
- Action: frontier_post_form_standard_top (file: frontier_post_form_standard.php)
- From v. 3.8.1
- Allows insert of html, fires after status and before text editor – Passes 2 variables
- $thispost: Post object for the post
- $tmp_task_new: Equals true if the user is adding a post
- Action: frontier_post_form_standard_tax (file: frontier_post_form_standard.php)
- From v. 4.4.0
- Allows insert of html, fires before displays of each of the taxonomies (category, tens etc) – Passes 3 variables
- $thispost: Post object for the post
- $tmp_task_new: Equals true if the user is adding a post
- $tmp_tax_name: Name of Taxonomy (ex category”)
- Action: frontier_post_form_standard (file: frontier_post_form_standard.php)
- From v. 3.8.1
- Allows insert of html, fires just before submit buttons – Passes 2 variables
- $thispost: Post object for the post
- $tmp_task_new: Equals true if the user is adding a post
- Action: frontier_post_form_quickpost_top (file: frontier_post_form_quickpost.php)
- From v. 4.3.3
- Allows insert of html, fires after status and before text editor – Passes 2 variables
- $thispost: Post object for the post
- $tmp_task_new: Equals true if the user is adding a post
- Action: frontier_post_form_quickpost (file: frontier_post_form_quickpost.php)
- From v. 4.3.3
- Allows insert of html, fires just before submit buttons – Passes 2 variables
- $thispost: Post object for the post
- $tmp_task_new: Equals true if the user is adding a post
- Action: frontier_post_custom_msg
- From v. 4.4.0
- (executes just after add/update messages are output)
- Filter: frontier_post_prepare_post (frontier-add-edit.php)
- From v. 5.1.6
- Allows manipulation of new clean post.
List Posts
- Filter: frontier_post_list_query (file: frontier-list-posts.php)
- From v. 5.1.5
- Makes it possible to manipulate the query ($args) used to retrieve post – 2 Variables
- $args: Query args for list (must be returned)
- $fpost_sc_parms: Frontier Post Parameters
- Action: frontier_post_list_top (file: frontier_post_form_list_detail.php & frontier_post_form_list.php)
- From v. 4.4.0
- Action fires before displaying posts, parses 1 variable
- $user_posts: Post objects for list
- Action: frontier_post_list_record (file: frontier_post_form_list_detail.php & frontier_post_form_list.php)
- From v. 4.4.0
- Action fires before each post record is displayed, parses 1 variable
- $post: Post object
- Action: frontier_post_list_botttom (file: frontier_post_form_list_detail.php & frontier_post_form_list.php)
- From v. 4.4.0
- Action fires before displaying posts, parses 1 variable
- $user_posts: Post objects for list
Additional
- Filter: frontier_post_clone (file: frontier-clone-post.php)
- From v. 5.1.2
- Apply filter before insert of closed post – 2 variables:
- $tmp_post Array that holds the updated fields for the cloned post
- $old_post The post being cloed (Object)
- Action: frontier_post_clone_past_insert (file: frontier-clone-post.php)
- From v. 5.1.2
- Action fires after insert and processing of the cloned post – 2 variables
- $new_post: Post object for the post just inserted
- $old_post: Post that was cloned from
.
.
Examples of the code inside Frontier Post
Filter: frontier_post_pre_update
//****************************************************************************************************
// 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
//****************************************************************************************************
// 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
Actions and Filters (Hooks) in Frontier Post — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>