Frontier Post – Extension Plugin ()
I have created a Demo plugin to show how Actions and Filters can be used in Frontier Post.
Please be aware that this is for Demo purpose, and I do not help with Actions and Filters. To be able to utilise this you will need to have programming experience.
You can download the plugin here (zip file): frontier-post-my-extensions version 1.1
//***************************************************************************************
//* Add default content
//***************************************************************************************
if (false) //Switch to false if you want to disable
{
function fp_my_template_content($tmp_post , $fpost_sc_parms)
{
// $fpost_sc_parms holds short code parameters
// set post content & title
if ($tmp_post->post_content < " ")
$tmp_post->post_content = 'Replace this with your template post content
and you are good to go';
if ($tmp_post->post_title < " ")
$tmp_post->post_title = 'Replace this with your template post title';
return $tmp_post;
}
add_filter('frontier_post_prepare_post', 'fp_my_template_content',10,2);
}
//***************************************************************************************
//* Start output row to hold additional fields
//***************************************************************************************
// New table ROW containing additional fields
// Fields will be shown in bottom of form, if top instead use action frontier_post_form_standard_top (also for actions below)
function fp_ext_start_row( )
{
echo '';
}
add_action( 'frontier_post_form_standard', 'fp_ext_start_row', 10, 2 );
//***************************************************************************************
//* Comment Status
//***************************************************************************************
if (true) //Switch to false if you want to disable
{
function fp_ext_comment_status_field( $thispost, $tmp_task_new)
{
// Exit (so no field on form if not user is editor or admin)
if ( !current_user_can('edit_others_posts') )
return;
// New table cell containing additional fields
echo '';
echo '';
echo ' ';
}
// add the display action
add_action( 'frontier_post_form_standard', 'fp_ext_comment_status_field', 10, 2 );
function fp_ext_save_comment_status($tmp_post, $tmp_task_new, $input_values )
{
// save Comment status
if ( array_key_exists('fp_comment_status', $input_values) )
$tmp_post['comment_status'] = $input_values['fp_comment_status'];
return $tmp_post;
} // end function Save comment status
add_filter('frontier_post_pre_update', 'fp_ext_save_comment_status',10,3);
} // end if comment status
//***************************************************************************************
//* Ping Status
//***************************************************************************************
if (false) //Switch to true if you want to enable
{
function fp_ext_ping_status_field( $thispost, $tmp_task_new)
{
// Exit (so no field on form if not user is editor or admin)
if ( !current_user_can('edit_others_posts') )
return;
// New table cell containing additional fields
echo '';
echo '';
echo ' ';
}
// add the display action
add_action( 'frontier_post_form_standard', 'fp_ext_ping_status_field', 10, 2 );
function fp_ext_save_ping_status($tmp_post, $tmp_task_new, $input_values )
{
// save ping status
if ( array_key_exists('fp_ping_status', $input_values) )
$tmp_post['ping_status'] = $input_values['fp_ping_status'];
return $tmp_post;
} // end function Save comment status
add_filter('frontier_post_pre_update', 'fp_ext_save_ping_status',10,3);
} // end if Ping status
//***************************************************************************************
//* Sticky post
//***************************************************************************************
if (true) //Switch to false if you want to disable
{
function fp_ext_sticky_field( $thispost, $tmp_task_new)
{
// Exit (so no field on form if not user is editor or admin)
if ( !current_user_can('edit_others_posts') )
return;
// New table cell containing additional fields
echo '';
echo '';
echo ' ';
}
// add the display action
add_action( 'frontier_post_form_standard', 'fp_ext_sticky_field', 10, 2 );
function fp_ext_save_sticky_status($tmp_post, $tmp_task_new, $input_values )
{
// save Sticky status
$tmp_sticky = get_option('sticky_posts');
$tmp_sticky_id = 0;
if ( array_key_exists('fp_sticky_status', $input_values) && $input_values['fp_sticky_status'] == "Sticky")
{
// Add post id to sticky posts
if (!in_array($tmp_post->ID, $tmp_sticky))
array_push($tmp_sticky, $tmp_post->ID);
}
else
{
// remove post id if exists in sticky posts
if (($key = array_search($tmp_post->ID, $tmp_sticky)) !== false)
{
unset($tmp_sticky[$key]);
}
}
update_option('sticky_posts',$tmp_sticky);
} // end function Save Stick post function
// Save the Sticky post status
// using frontier_post_post_save action as sticky post is not on post record, but the post id is stored in an option array.
add_action( 'frontier_post_post_save', 'fp_ext_save_sticky_status', 10, 3 );
} // end if Sticky
//***************************************************************************************
//* Author
//***************************************************************************************
if (true) //Switch to false if you want to disable
{
function fp_ext_author_field( $thispost, $tmp_task_new)
{
// Exit (so no field on form if not user is admin)
if ( !current_user_can('manage_options') )
return;
// New table cell containing additional fields
echo '';
echo '';
echo ' ';
}
// add the display action
add_action( 'frontier_post_form_standard', 'fp_ext_author_field', 10, 2 );
function fp_ext_save_author($tmp_post, $tmp_task_new, $input_values )
{
if ( array_key_exists('fp_author_id', $input_values) )
{
$tmp_author_id = absint($input_values['fp_author_id']);
if ($tmp_author_id > 0)
{
$tmp_post['post_author'] = $tmp_author_id;
//error_log("Saving author: ".$tmp_author_id );
}
}
return $tmp_post;
} // end function Save author
// ** send $tmp_post back with author id
// Using filter frontier_post_pre_update to ensure that save goes through the normal validation, instead of update Auther after post is saved.
add_filter('frontier_post_pre_update', 'fp_ext_save_author',10,3);
} // end if Author
//***************************************************************************************
//* Future posts - Show post date field, and save
//***************************************************************************************
if (true) //Switch to false if you want to disable
{
// Exit (so no field on form if not user is editor or admin)
//if ( !current_user_can('edit_others_posts') )
//return;
// ***********************************
// ** load jquery datepicker **
// ***********************************
function fp_ext_my_datepick()
{
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('e2b-admin-ui-css','https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
}
add_action('wp_enqueue_scripts', 'fp_ext_my_datepick');
// ***********************************
// ** Add fields to post form **
// ***********************************
function fp_ext_post_date_field( $thispost, $tmp_task_new)
{
// js script to set class for datepicker
echo '';
// New table cell containing additional fields
echo '';
echo '';
echo ' ';
}
// add the display action
add_action( 'frontier_post_form_standard', 'fp_ext_post_date_field', 10, 2 );
// add save post date
function fp_ext_save_post_date($tmp_post, $tmp_task_new, $input_values )
{
// Check if post date field is in the imput form
if ( array_key_exists('fp_post_date', $input_values) )
{
$tmp_post_date = $input_values['fp_post_date'];
$tmp_post_hour = zeroise(intval($input_values['fp_post_hour']),2);
$tmp_post_minute = zeroise(intval($input_values['fp_post_minute']),2);
$tmp_year = substr($tmp_post_date ,0,4);
$tmp_month = substr($tmp_post_date ,5,2);
$tmp_day = substr($tmp_post_date ,8,2);
$tmp_publish_time = $tmp_post_date." ".$tmp_post_hour.":".$tmp_post_minute;
// Check if valid date time
if ( !checkdate($tmp_month, $tmp_day, $tmp_year) || $tmp_post_hour>23 || $tmp_post_minute>59 )
{
frontier_post_set_msg('post_date: Error Invalid date or time: '.$tmp_publish_time.'');
}
else
{
$tmp_post['post_date'] = $tmp_publish_time;
// set status to future, if post_date is in the future
if ( strtotime(get_gmt_from_date($tmp_publish_time)) > strtotime('now') && in_array($tmp_post['post_status'], array('future', 'publish')) )
{
$tmp_post['post_status'] = 'future';
// edit_date & post_date_gmt is neccssary for future post scheduling to work, not logical, but WordPress :)
$tmp_post['edit_date'] = true;
$tmp_post['post_date_gmt'] = get_gmt_from_date( $tmp_post['post_date'] );
}
else
{
//If post status is Futue, but time is in the past we better publish the post
if ($tmp_post['post_status'] === 'future' )
{
$tmp_post['edit_date'] = true;
$tmp_post['post_status'] = 'publish';
}
}
} // end validate date / time
} // end check date
return $tmp_post;
} // end function Save post date
add_filter('frontier_post_pre_update', 'fp_ext_save_post_date',10,3);
} // *** End display frontier Post Date Field
//***************************************************************************************
//* Rating (Custom field)
//***************************************************************************************
if (true) //Switch to false if you want to disable
{
function fp_ext_rating_field( $thispost, $tmp_task_new)
{
// Exit (so no field on form if not user is editor or admin)
if ( !current_user_can('manage_options') )
return;
// New table cell containing additional fields
echo '';
echo '';
echo ' ';
}
// add the display action
add_action( 'frontier_post_form_standard', 'fp_ext_rating_field', 10, 2 );
function fp_ext_save_rating($tmp_post, $tmp_task_new, $input_values )
{
// save Rating
if ( array_key_exists('fp_rating', $input_values) )
{
update_post_meta($tmp_post->ID, 'fp_rating', intval($input_values['fp_rating']) );
}
} // end Save rating function
// Save the rating
// using frontier_post_post_save action as Rating is not on post record, but the post id is stored as a custom Field.
add_action( 'frontier_post_post_save', 'fp_ext_save_rating', 10, 3 );
} // end if Sticky
//***************************************************************************************
//* Close output row to hold additiuonal fields
//***************************************************************************************
// Close table ROW containing additional fields
function fp_ext_close_row( )
{
echo '
';
}
add_action( 'frontier_post_form_standard', 'fp_ext_close_row', 10, 2 );