/* Set endpoint of url */
add_rewrite_endpoint('download', EP_PERMALINK);
function pixabin_download()
{
add_rewrite_endpoint('download', EP_PERMALINK);
}
add_action('init', 'pixabin_download');
/* Set custom Safelink page template */
function pixabin_download_template()
{
global $wp_query;
// if the request is fail it will back to the main post
if (!isset($wp_query->query_vars['download']) || !is_singular()) return;
// include the custom safelink (download) template
include get_template_directory() . '/template/download.php';
exit;
}
add_action('template_redirect', 'pixabin_download_template');
/* Meta box in posts edit */
function download_details() {
global $post;
$download_name = get_post_meta($post->ID, 'download_name', true);
$download_link = get_post_meta($post->ID, 'download_link', true);
?>
<b style="text-transform:capitalize">Download Link Title</b>
<p><input style="width:98%" type="text" name="download_name" value="<?= $download_name ?>" /></p>
<b style="text-transform:capitalize">Download Link/URL</b>
<p><input style="width:98%" type="text" name="download_link" value="<?= $download_link ?>" /></p>
<?php }
function add_post_metaboxes() {
add_meta_box('download_details', 'Download Link Box', 'download_details', 'post', 'normal', 'high');
}
add_action( 'add_meta_boxes', 'add_post_metaboxes', 0 );
function wpwm_save_postdata( $post_id ) {
// First we need to check if the current user is authorised to do this action.
if ( 'page' == @$_REQUEST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
}
$wpwm_meta = array( 'download_name', 'download_link', );
//if saving in a custom table, get post_ID
$post_ID = @$_POST['post_ID'];
foreach ($wpwm_meta as $meta_key) {
if(isset($_POST[$meta_key])) update_post_meta($post_ID, $meta_key, $_POST[$meta_key]);
}
}
add_action( 'save_post', 'wpwm_save_postdata' );