Advertisement
mikelittle

Second Visual Editor in CPT

Jul 12th, 2011
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. /* hooked to admin_init */
  2.  
  3. add_meta_box( 'z1_aec_event_other_text_metabox_id', __( 'Second Text Area', 'z1_aec' ),
  4.     array( 'zed1_aec_event', 'other_text_meta_box' ), Z1_AEC_EVENT_POST_TYPE, 'normal', 'high' );
  5.  
  6. /* the call back function */
  7. static function other_text_meta_box($post, $data) {
  8.     $other_title = get_post_meta( $post->ID, Z1_AEC_OTHER_TITLE_META_TAG, true );
  9.     if ( empty($other_title))
  10.         $other_title = 'Other Access';
  11.     $other_text = get_post_meta( $post->ID, Z1_AEC_OTHER_TEXT_META_TAG, true );
  12.  
  13.     echo '<div class="meta-options">';
  14.  
  15.     //wp_nonce_field( Z1_AEC_PLUGIN_NAME, 'z1_aec_meta_nonce' );
  16.  
  17.     echo '<p>Note: The editor above will be displayed with a "Description" heading. You do not need to add the heading yourself.<br />' . NL;
  18.     echo 'Add secondary information about the event. E.g. "Other Access" or "Access Details". If the editor box is empty, nothing will be displayed. Otherwise this heading (h2 tag) will be displayed followed by the text below.</p>' . NL;
  19.     echo '<label for="z1_aec_other_title">' . __( 'Title:' ) . '</label>';
  20.     echo '<input type="text" id="z1_aec_other_title" name="z1_aec_other_title" value="' . esc_attr( $other_title ) . '" /><br />';
  21.  
  22.     echo '<label for="z1_aec_other_text" class="screen-reader-text">' . __( 'Text:' ) . '</label>';
  23.  
  24.     echo '<p align="right">' . NL;
  25.     echo '  <a class="button toggleVisual">Visual</a>' . NL;
  26.     echo '  <a class="button toggleHTML">HTML</a>' . NL;
  27.     echo '</p>' . NL;
  28.     echo '<textarea id="z1_aec_other_text" name="z1_aec_other_text" cols="40" rows="6">' . esc_attr( $other_text ) . '</textarea>';
  29.  
  30.     echo '</div>';
  31.  
  32.  
  33. } // end other_text_meta_box
  34.  
  35. /* hooked on save post */
  36. static function save_post( $post_id ) {
  37. //....
  38.     $other_title = isset( $_POST['z1_aec_other_title'] ) ? trim($_POST['z1_aec_other_title']) : '';
  39.     if ( empty($other_title))
  40.         $other_title = 'Other Access';
  41.     update_post_meta( $post_id, Z1_AEC_OTHER_TITLE_META_TAG, $other_title );
  42.  
  43.     $other_text = isset( $_POST['z1_aec_other_text'] ) ? trim($_POST['z1_aec_other_text']) : '';
  44.     update_post_meta( $post_id, Z1_AEC_OTHER_TEXT_META_TAG, $other_text );
  45. //....
  46. }
  47.  
  48. /* in the js file for this CPT */
  49.  
  50. jQuery(document).ready( function($) {
  51.     jQuery("#z1_aec_other_text").addClass("mceEditor");
  52.     if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
  53.         jQuery("#z1_aec_other_text").wrap( "<div id='editorcontainer'></div>" );
  54.         tinyMCE.execCommand("mceAddControl", false, "z1_aec_other_text");
  55.     }
  56.  
  57.     $('a.toggleVisual').click( function() {
  58.         tinyMCE.execCommand('mceAddControl', false, 'z1_aec_other_text');
  59.     });
  60.  
  61.     $('a.toggleHTML').click( function() {
  62.         tinyMCE.execCommand('mceRemoveControl', false, 'z1_aec_other_text');
  63.     } );
  64.  
  65. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement