Guest User

Untitled

a guest
Mar 30th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2. add_action( 'init', function() {
  3.     remove_post_type_support( 'code-snippet', 'excerpt' );
  4.     remove_post_type_support( 'code-snippet', 'editor' );
  5. } );
  6.  
  7. // Now create 2 fields for excerpt and content.
  8. // I'll show a way to use code and a way to use Builder.
  9.  
  10. add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
  11.     $meta_boxes[] = [
  12.         'title'      => 'Code Snippet Before',
  13.         'post_types' => 'code-snippet',
  14.         'fields'     => [
  15.             [
  16.                 'type' => 'wysiwyg',
  17.                 'id'   => 'content', // This is the must!
  18.                 'name' => 'Reason for snippet',
  19.             ],
  20.             [
  21.                 'type' => 'wysiwyg',
  22.                 'id'   => 'excerpt', // This is the must!
  23.                 'name' => 'Snippet Excerpt',
  24.             ],
  25.             // Custom style to overwrite the editor style set by WordPress.
  26.             [
  27.                 'type' => 'custom_html',
  28.                 'std'  => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>',
  29.             ],
  30.         ],
  31.     ];
  32.  
  33.     return $meta_boxes;
  34. } );
  35.  
  36. // This is for content
  37. add_filter( 'rwmb_content_field_meta', function() {
  38.     $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
  39.     return get_post_field( 'post_content', $post_id );
  40. } );
  41. add_filter( 'rwmb_content_value', '__return_empty_string' );
  42.  
  43. // This is for excerpt only.
  44. add_filter( 'rwmb_excerpt_field_meta', function() {
  45.     $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
  46.     return get_post_field( 'post_excerpt', $post_id );
  47. } );
  48. add_filter( 'rwmb_excerpt_value', '__return_empty_string' );
Advertisement
Add Comment
Please, Sign In to add comment