Bannerspace Slideshow
New feature: UI for the "link" post meta (2 posts)

  1. BramNL
    Posted 2 years ago #

    Hi Dean Oakley,

    I have created an new functionality that you might like. I needed an user interface to add the link post meta for my users. This is what I came up with. View a screenshot (Dutch!).
    The text says:

    The following URL makes the full slide clickable.
    Enter the URL manually or select a page below. Leave the field empty to disable the link.
    Selecting a page will overwrite the manually entered URL when post is updated.

    Users can type the URL themselves, or select a page from the drop down.

    At the very end of "bannerspace.php" add:

    // If in administrator back-end, load the post meta box
    if (is_admin()) {

    Create a new file, named "bm_admin_meta_box.php" and paste the following code:

    /* Define the custom box */
    add_action( 'add_meta_boxes', 'bm_bs_add_post_meta_box' );
    /* Do something with the data entered */
    add_action( 'save_post', 'bm_bs_post_meta_box_save' );
    /* Adds a box to the main column on the Post and Page edit screens */
    function bm_bs_add_post_meta_box() {
    		__('Bannerspace full slide hyperlink'),
    /* Prints the box content */
    function bm_bs_post_meta_box_html( $post ) {
    	// Use nonce for verification
    	wp_nonce_field( plugin_basename( __FILE__ ), 'bm_bs_post_meta_nonce' );
    	// The actual fields for data entry
    	// Use get_post_meta to retrieve an existing value from the database and use the value for the form
    	$value = get_post_meta( $post->ID, 'link', true );
    		<label for="bm_bs_post_meta_box_link">
    		<?php _e('The following URL makes the full slide clickable.<br />Enter the URL manually or select a page below. Leave the field empty to disable the link.'); ?>
    		</label><br />
    		<input type="text" id="bm_bs_post_meta_box_link" name="bm_bs_post_meta_box_link" value="<?php echo esc_attr($value) ?>" style="width:100%" />
    		<label for="bm_bs_post_meta_box_page">
    		<?php _e('Selecting a page will overwrite the manually entered URL when post is updated.', 'bannerspace'); ?>
    		</label><br />
    			// Prepare the arguments
    			$args = array (
    				'name' => 'bm_bs_post_meta_box_page',
    				'show_option_none' => __('Select a page', 'bannerspace'),
    				'option_none_value' => '0',
    			// Get the pages from the content site
    			wp_dropdown_pages( $args );
    /* When the post is saved, saves our custom data */
    function bm_bs_post_meta_box_save( $post_id ) {
    	// First we need to check if the current user is authorised to do this action.
    	if ( 'bannerspace_post' != $_REQUEST['post_type'] ) {
    		// Only edit post_type "bannerspace_post"
    	} else {
    		if ( ! current_user_can( 'edit_post', $post_id ) )
    	// Secondly we need to check if the user intended to change this value.
    	if ( ! isset( $_POST['bm_bs_post_meta_nonce'] ) || ! wp_verify_nonce( $_POST['bm_bs_post_meta_nonce'], plugin_basename( __FILE__ ) ) )
    	// Thirdly we can save the value to the database
    	//if saving in a custom table, get post_ID
    	$post_ID = $_POST['post_ID'];
    	//sanitize user input
    	$post_meta_page_id = (int)$_POST['bm_bs_post_meta_box_page'];
    	if ($post_meta_page_id > 0) {
    		$post_meta_link = get_permalink( $post_meta_page_id );
    		// Replace to real domain, if needed
    		// Used with WP Multi-site and WordPress MU Domain Mapping plugin.
    		if (function_exists('domain_mapping_post_content'))	{
    			$post_meta_link = domain_mapping_post_content($post_meta_link);
    	} else {
    		$post_meta_link = sanitize_text_field( $_POST['bm_bs_post_meta_box_link'] );
    	// Update post meta
    	add_post_meta($post_ID, 'link', $post_meta_link, true) or
    	update_post_meta($post_ID, 'link', $post_meta_link);


  2. THRIVE - Web Design Gold Coast
    Plugin Author

    Posted 2 years ago #

    Thanks I'll check this out!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Bannerspace Slideshow
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic