Created
October 17, 2017 09:36
-
-
Save bulentsakarya/7dea0f0d4140cefb01f50914d7780556 to your computer and use it in GitHub Desktop.
Editörü özel alana ekleme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class dd_slider_meta { | |
| public function __construct() { | |
| if ( is_admin() ) { | |
| add_action( 'load-post.php', array( $this, 'init_metabox' ) ); | |
| add_action( 'load-post-new.php', array( $this, 'init_metabox' ) ); | |
| } | |
| } | |
| public function init_metabox() { | |
| add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) ); | |
| add_action( 'save_post', array( $this, 'save_metabox' ), 10, 2 ); | |
| } | |
| public function add_metabox() { | |
| add_meta_box( | |
| 'slider', | |
| __( 'Slider Options', 'text_domain' ), | |
| array( $this, 'render_metabox' ), | |
| 'post', | |
| 'normal', | |
| 'default' | |
| ); | |
| } | |
| public function render_metabox( $post ) { | |
| // Retrieve an existing value from the database. | |
| $slider_caption = get_post_meta( $post->ID, 'slider_caption', true ); | |
| $slider_link = get_post_meta( $post->ID, 'slider_link', true ); | |
| // Set default values. | |
| if( empty( $slider_caption ) ) $slider_caption = ''; | |
| if( empty( $slider_link ) ) $slider_link = ''; | |
| // Form fields. | |
| echo '<table class="form-table">'; | |
| echo ' <tr>'; | |
| echo ' <th><label for="slider_caption" class="slider_caption_label">' . __( 'Caption', 'text_domain' ) . '</label></th>'; | |
| echo ' <td>'; | |
| wp_editor( $slider_caption, 'slider_caption', array( 'media_buttons' => true ) ); | |
| echo ' <p class="description">' . __( 'Input your caption for slide (HTML tags are allowed).', 'text_domain' ) . '</p>'; | |
| echo ' </td>'; | |
| echo ' </tr>'; | |
| echo ' <tr>'; | |
| echo ' <th><label for="slider_link" class="slider_link_label">' . __( 'URL', 'text_domain' ) . '</label></th>'; | |
| echo ' <td>'; | |
| echo ' <input type="text" id="slider_link" name="slider_link" class="slider_link_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $slider_link ) . '">'; | |
| echo ' <p class="description">' . __( 'Input the slide URL (can be external link)', 'text_domain' ) . '</p>'; | |
| echo ' </td>'; | |
| echo ' </tr>'; | |
| echo '</table>'; | |
| } | |
| public function save_metabox( $post_id, $post ) { | |
| // Sanitize user input. | |
| $slider_new_caption = isset( $_POST[ 'slider_caption' ] ) ? wp_kses_post( $_POST[ 'slider_caption' ] ) : ''; | |
| $slider_new_link = isset( $_POST[ 'slider_link' ] ) ? sanitize_text_field( $_POST[ 'slider_link' ] ) : ''; | |
| // Update the meta field in the database. | |
| update_post_meta( $post_id, 'slider_caption', $slider_new_caption ); | |
| update_post_meta( $post_id, 'slider_link', $slider_new_link ); | |
| } | |
| } | |
| new dd_slider_meta; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment