/** * Save the meta data. * * @wp-hook save_post * * @param int $post_id Post ID. * @param \WP_Post $post Post object. * * @return bool */ public function save($post_id, $post) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return FALSE; } if (wp_is_post_revision($post_id)) { return FALSE; } if ($post->post_type !== $this->post_type) { return FALSE; } if (!current_user_can('edit_post', $post_id)) { return FALSE; } if (!$this->nonce->is_valid()) { return FALSE; } $meta_value = isset($_POST[$this->meta_key]) ? $_POST[$this->meta_key] : ''; return (bool) update_post_meta($post_id, $this->meta_key, $meta_value); }
/** * Render the HTML. * * @param \WP_Post $post Post object. * * @return void */ public function render(\WP_Post $post) { $meta_value = get_post_meta($post->ID, $this->meta_key, TRUE); $this->nonce->print_field(); ?> <p> <?php esc_html_e('Please enter the URL of the external content.', 'external-content'); ?> </p> <table class="form-table"> <tbody> <tr> <th scope="row"> <label for="<?php echo $this->meta_key; ?> "> <?php esc_html_e('External URL', 'external-content'); ?> </label> </th> <td> <input type="url" name="<?php echo $this->meta_key; ?> " class="large-text" placeholder="http://example.com" value="<?php echo esc_attr($meta_value); ?> "> </td> </tr> </tbody> </table> <?php }