0

I'm using the latest version of Wordpress and I want to upload a small plugin - a metabox that lets editors add source links in their articles. The code looks like this:

 
/* Do something with the data entered */
add_action( 'save_post', 'wpse_source_link_save' );
 
/* Adds a box to the main column on the Post and Page edit screens */
function wpse_source_link() {
 
    add_meta_box(
        'source_link',
        __( 'Source-link', 'myplugin_textdomain' ), 
        'wpse_source_meta_box',
        'post',
        'side'
    );
}
 
/* Prints the box content */
function wpse_source_meta_box( $post ) {
 
  // Use nonce for verification
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
 
  // The actual fields for data entry
  echo '<label for="source-link">URL:</label> ';
  echo '<input type="text" id="source-link"" name="source_link" value="'.
    get_post_meta( $post->ID, '_source_link', true ) .'" size="25" />';
 
  echo '<label for="source-link-label">Label:</label> ';
  echo '<input type="text" id="source-link-label"" name="source_link_label" value="'.
    get_post_meta( $post->ID, '_source_link_label', true ) .'" size="25" />';
}
 
/* When the post is saved, saves our custom data */
function wpse_source_link_save( $post_id ) {
  // verify if this is an auto save routine. 
  // If it is our form has not been submitted, so we dont want to do anything
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
      return;
 
  // verify this came from the our screen and with proper authorization,
  // because save_post can be triggered at other times
 
  if ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )
      return;
 
 
  // Check permissions
 
  if ( current_user_can( 'edit_post', $post_id ) ) {
 
      update_post_meta( $post_id, '_source_link', sanitize_text_field( $_POST['source_link'] ) );
      update_post_meta( $post_id, '_source_link_label', sanitize_text_field( $_POST['source_link_label'] ) );
 
   }
} 

Metabox works fine and It's possible to add links along with anchors. The problem is, it doesn't show up in posts. I can't figure out what is wrong with this code. Does anyone have any ideas?

2

0

Browse other questions tagged or ask your own question.