Advertisement
longnguyenwp

Save Wysiwyg content as post_content

Jul 22nd, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. add_action( 'init', function () {
  2.     // Remove the editor for the post type.
  3.     remove_post_type_support( 'post', 'editor' ); // Change 'post' to your custom post type.
  4. } );
  5.  
  6. add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
  7.  
  8. function your_prefix_register_meta_boxes( $meta_boxes ) {
  9.     $prefix = '';
  10.     $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
  11.     $post_content = get_post_field( 'post_content', $post_id );
  12.  
  13.  
  14.     $meta_boxes[] = array (
  15.         'title' => esc_html__( 'Code Snippet Before', 'text-domain' ),
  16.         'id' => 'code-snippet-before',
  17.         'post_types' => array(
  18.             0 => 'post',
  19.         ),
  20.         'context' => 'after_title',
  21.         'priority' => 'high',
  22.         'fields' => array(
  23.             array (
  24.                 'id' => 'content',
  25.                 'name' => esc_html__( 'Reason for snippet', 'text-domain' ),
  26.                 'type' => 'wysiwyg',
  27.                 'desc' => '###Why did I need to use this?
  28. This field is also used as the Excerpt for the post.###',
  29.                 'class' => 'reason-for-snippet',
  30.                 'std' => $post_content,
  31.             ),
  32.             array (
  33.                 'id' => 'what-it-does',
  34.                 'name' => esc_html__( 'What It Does', 'text-domain' ),
  35.                 'type' => 'wysiwyg',
  36.             ),
  37.             array (
  38.                 'id' => 'actual-code-snippet',
  39.                 'name' => esc_html__( 'Actual Code Snippet', 'text-domain' ),
  40.                 'type' => 'wysiwyg',
  41.                 'sanitize_callback' => 'none',
  42.             ),
  43.             array (
  44.                 'id' => 'before-the-snippet',
  45.                 'type' => 'single_image',
  46.                 'name' => esc_html__( 'Before the snippet', 'text-domain' ),
  47.             ),
  48.             array (
  49.                 'id' => 'after-the-snippet',
  50.                 'type' => 'single_image',
  51.                 'name' => esc_html__( 'After the snippet', 'text-domain' ),
  52.             ),
  53.             array (
  54.                 'id' => 'custom_html_sbvmvz193m',
  55.                 'type' => 'custom_html',
  56.                 'std' => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>',
  57.             ),
  58.         ),
  59.         'style' => 'seamless',
  60.     );
  61.  
  62.     return $meta_boxes;
  63. }
  64.  
  65. // Set the value for the 'content' field.
  66. add_filter( 'rwmb_content_field_meta', function() {
  67.     $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
  68.     return get_post_field( 'post_content', $post_id );
  69. } );
  70.  
  71. // Do not save to post meta.
  72. add_filter( 'rwmb_content_value', '__return_empty_string' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement