Advertisement
Guest User

Wysiwyg field in cf7

a guest
Jul 7th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.12 KB | None | 0 0
  1. define( 'WYSIWYG_META_BOX_ID', 'wpcf7ev_popup_options' );
  2. define( 'WYSIWYG_EDITOR_ID', 'myeditor' ); //Important for CSS that this is different
  3. define( 'WYSIWYG_META_KEY', 'extra-content-form' );
  4.  
  5. add_action( 'wpcf7_add_meta_boxes', 'wysiwyg_register_meta_box' );
  6.  
  7. function wysiwyg_register_meta_box() {
  8.     add_meta_box( WYSIWYG_META_BOX_ID, __( 'Popup text', 'wysiwyg' ), 'wysiwyg_render_meta_box', null, 'additional_settings', 'core' );
  9. }
  10.  
  11. function wysiwyg_render_meta_box() {
  12.  
  13.     $post = wpcf7_get_current_contact_form();
  14.  
  15.     $meta_box_id = WYSIWYG_META_BOX_ID;
  16.     $editor_id   = WYSIWYG_EDITOR_ID;
  17.  
  18.     //Add CSS & jQuery goodness to make this work like the original WYSIWYG
  19.     echo "
  20.                <style type='text/css'>
  21.                        #$meta_box_id #edButtonHTML, #$meta_box_id #edButtonPreview {background-color: #F1F1F1; border-color: #DFDFDF #DFDFDF #CCC; color: #999;}
  22.                        #$editor_id{width:100%;}
  23.                        #$meta_box_id #editorcontainer{background:#fff !important;}
  24.                        #$meta_box_id #$editor_id_fullscreen{display:none;}
  25.                </style>
  26.            
  27.                <script type='text/javascript'>
  28.                        jQuery(function($){
  29.                                $('#$meta_box_id #editor-toolbar > a').click(function(){
  30.                                        $('#$meta_box_id #editor-toolbar > a').removeClass('active');
  31.                                        $(this).addClass('active');
  32.                                });
  33.                                
  34.                                if($('#$meta_box_id #edButtonPreview').hasClass('active')){
  35.                                        $('#$meta_box_id #ed_toolbar').hide();
  36.                                }
  37.                                
  38.                                $('#$meta_box_id #edButtonPreview').click(function(){
  39.                                        $('#$meta_box_id #ed_toolbar').hide();
  40.                                });
  41.                                
  42.                                $('#$meta_box_id #edButtonHTML').click(function(){
  43.                                        $('#$meta_box_id #ed_toolbar').show();
  44.                                });
  45.  
  46.                 //Tell the uploader to insert content into the correct WYSIWYG editor
  47.                 $('#media-buttons a').bind('click', function(){
  48.                     var customEditor = $(this).parents('#$meta_box_id');
  49.                     if(customEditor.length > 0){
  50.                         edCanvas = document.getElementById('$editor_id');
  51.                     }
  52.                     else{
  53.                         edCanvas = document.getElementById('content');
  54.                     }
  55.                 });
  56.                        });
  57.                </script>
  58.        ";
  59.     //Create The Editor
  60.     $content = get_post_meta( $post->id, WYSIWYG_META_KEY, true );
  61.     wp_editor( $content, $editor_id );
  62.  
  63.     //Clear The Room!
  64.     echo "<div style='clear:both; display:block;'></div>";
  65. }
  66.  
  67. add_action( 'wpcf7_save_contact_form', 'wysiwyg_save_meta' );
  68.  
  69. function wysiwyg_save_meta( $post ) {
  70.  
  71.     $editor_id   = WYSIWYG_EDITOR_ID;
  72.     $meta_key    = WYSIWYG_META_KEY;
  73.     if ( isset( $_REQUEST[ $editor_id ] ) ) {
  74.         update_post_meta( $post->id, $meta_key, $_REQUEST[ $editor_id ] );
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement