Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Define the custom box */
- add_action( 'add_meta_boxes', 'wpse_source_link' );
- /* 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'] ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement