Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

403 Error when text is pasted in Custom Metabox Textarea

I gave your code a look over, and updated it to include proper escaping and sanitation. I suspect that the problem could have stemmed from the lack of escaping. I also applied some formatting and WP best practices, but otherwise the code is the same.

/**
 * Meta box display callback.
 *
 * @param WP_Post $post Current post object.
 */
function wpse_metabox_callback( $post ) {
    $service_title = get_post_meta( $post->ID, 'wpp_service_title', true );
    $service       = get_post_meta( $post->ID, 'service', false ); // get as an array ?>

    <div id="wpp_meta_inner">
    <div>
            <div class="wpp-input-container">
                <label><?php esc_html_e( 'Title', 'textdomain' ); ?></label>
                <input type="text" name="wpp_service_title" id="wpp_service_title" value="<?php echo esc_attr( $service_title ); ?>" />
                <p><?php esc_html_e( 'Will display default "Scope of Services" if empty.', 'textdomain' ); ?></p>
            </div>

            <div class="wpp-input-container">
                <label class="wpp-label-repeater"><?php _e( 'Service Items', 'textdomain' ); ?></label>
                <?php
                    wp_nonce_field( 'c_nonce_field', 'c_wpnonce' );
                    $c = 0;
                    if ( count( $service ) > 0 ) {
                        if ( ! empty( $service ) ) {
                            foreach( $service as $service_item_val ) {
                                foreach( $service_item_val as $service_item ) {
                                    if ( isset( $service_item['title'] ) || isset( $service_item['service_item'] ) ) {
                                        printf(
                                            '<div class="wpp-repeater-wrapper service">' .
                                                'Title: <input class="wpp-repeater-input service" type="text" name="service[%1$s]403 Error when text is pasted in Custom Metabox Textarea" value="%2$s" />' .
                                                'Description: <textarea class="wpp-repeater-input service" name="service[%1$s][service_item]" data-gramm_editor="false" value="">%3$s</textarea><span class="wpp-item-remove service">%4$s</span>' . 
                                            '</div>',
                                            esc_attr( $c ),
                                            esc_html( $service_item['title'] ),
                                            esc_textarea( $service_item['service_item'] ),
                                            esc_html( __( 'Remove', 'textdomain' ) )
                                        );
                                        $c += 1;
                                    }
                                }
                            }
                        }
                    }
                ?>
                <span id="services_here"></span>
                <div class="wpp-item-add services" style="visibility: hidden; margin-bottom: -20px;"><?php esc_html_e( 'Add Item', 'textdomain' ); ?></div>
                <div class="wpp-item-add services add-button"><?php esc_html_e( 'Add Service', 'textdomain' ); ?></div>
            </div>
        </div>

        <script>
            var $ =jQuery.noConflict();
            $(document).ready(function() {
                    var count = <?php echo esc_js( $c ); ?>;
                    $(".wpp-item-add.services").click(function() {
                            count = count + 1;
                            $('#services_here').append('<div class="wpp-repeater-wrapper service">Title: <input class="wpp-repeater-input service" type="text" name="service['+count+']403 Error when text is pasted in Custom Metabox Textarea" value="" placeholder="" />Description: <textarea class="wpp-repeater-input service" name="service['+count+'][service_item]" data-gramm_editor="false" value="" placeholder=""></textarea><span class="wpp-item-remove service">Remove</span></div>' );
                            return false;
                    });
                    $(".wpp-item-remove.service").live('click', function() {
                            $(this).parent().remove();
                    });
            });
        </script>
    </div><?php
}

When saving the metabox data, wp_kses_post() will be applied to each element of the $services array:

/**
 * Sanitize and save metabox data.
 */
add_action( 'save_post', 'wpse_save_meta_box' );
function wpse_save_meta_box( $post_id ) {
    if ( defined( 'DOING_AJAX' ) AND DOING_AJAX ) {
        return;
    }

    if ( ! current_user_can( 'edit_post', $post_id ) ) {
        return;
    }

    if ( ! isset( $_POST['c_wpnonce'] ) || ! wp_verify_nonce( $_POST['c_wpnonce'], 'c_nonce_field' ) ) {
        return;
    }

    $allowed_html = array (
        'a' => array(
            'href' => array()
    ) );

    $service = isset( $_POST['service'] ) && ! empty( $_POST['service'] ) ? array_map( 'wp_kses_post', $_POST['service'] ) : array();

    update_post_meta( $post_id, 'wpp_service_title', wp_kses( $_POST['wpp_service_title'], $allowed_html ) );
    update_post_meta( $post_id, 'service', $service );
}

For the sake of completeness, here is the code that registers the proposal post type:

/**
 * Register proposal post type.
 */
add_action( 'init', 'wpse_register_post_type_proposal' );
function wpse_register_post_type_proposal() {
    $args = [
            'label'             => __( 'Proposals', 'textdomain' ),
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'query_var'          => true,
            'rewrite'            => [ 'slug' => 'proposal' ],
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => [ 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ],
    ];
    register_post_type( 'proposal', $args );
}

and the meta box:

/**
 * Register meta box
 */
function wpse_register_meta_boxes() {
    add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'wpse_metabox_callback', 'proposal' );
}
add_action( 'add_meta_boxes', 'wpse_register_meta_boxes' );

Related Posts:

  1. Post meta vs separate database tables
  2. Save metabox with multiple checkbox array
  3. How to enable users to down-vote in this simple voting counter (that uses the post meta)?
  4. How can I free up the memory used by update_post_meta?
  5. Is there a way to list tags order by post_meta field
  6. Plugin development: get_post_meta is not working [closed]
  7. Ordering posts by metadata
  8. Act on user meta updated, but only once
  9. How to check if Woocommerce Order number equals to post ID?
  10. update post meta for checkbox in the admin when inserted in the front-end
  11. Saving value of a selection option in comment form as comment meta
  12. Add a Save Button to Custom Meta Box [duplicate]
  13. Plugin with action ‘save_post’ needs to press publish twice on order to publish
  14. Doubts about the use of metadata and how this can affect performance on WordPress
  15. update_post_meta not working in a loop
  16. Run Shortcode of post’s custom field in functions.php / Plugin
  17. Get draggable widgets on Edit Post page
  18. WP nonce field checkbox prints checked=’checked’ outside input field
  19. Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
  20. Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
  21. Using delete_post_meta for deleting multiple selected options
  22. Get audio metadata on file upload
  23. Plugin can’t be activated [closed]
  24. Any way to update_post_meta with html content? It gets stripped and becomes empty
  25. Remove Meta-boxes (Yoast SEO plugin) [duplicate]
  26. Is there a way to add a link with add_post_meta?
  27. Adjust query on single
  28. Why is $_POST empty when saving custom Meta Box?
  29. Condition to check previous next article post title
  30. register_meta not showing custom post type metabox data in rest api
  31. Insert, update or remove data from database (usermeta)
  32. Unexpected issue when using attachment_fields_to_edit filter
  33. WordPress delete mysql rows with string
  34. Saving post meta
  35. Displaying Custom Post Meta
  36. Include add_post_meta in a plugin
  37. A better way of getting draft posts that has a particular post meta using get_posts function
  38. Objective Best Practices for Plugin Development? [closed]
  39. add_menu_page() with different name for first submenu item
  40. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  41. How to include PHP files in plugins the correct way
  42. How can I add an image upload field directly to a custom write panel?
  43. A tool to analyze rewrite rules? [closed]
  44. Difference Between Filter and Action Hooks?
  45. framework for plugin/theme options panel? [closed]
  46. Creating a table in the admin-style?
  47. How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
  48. Settings API with arrays example
  49. How to get the path to the current theme?
  50. How to make a plugin require another plugin?
  51. ajaxurl not defined on front end
  52. What process do you use for WordPress development? [closed]
  53. What’s the difference between term_id and term_taxonomy_id
  54. Should I use wpdb prepare?
  55. Why does WordPress use outdated jQuery v1.12.4?
  56. Is there any plugin development framework
  57. Is it possible to reuse wp.media.editor Modal for dialogs other than media
  58. How to add a javascript snippet to the footer that requires jQuery
  59. Enhance Media Manager for Gallery
  60. How do I create a custom role capability?
  61. How do I add CSS options to my plugin without using inline styles?
  62. How do i best handle custom plugin page actions?
  63. Adding Custom Text Patterns in the WP 4.5 Visual Editor
  64. Automatically determine minimum WordPress version required for a plugin?
  65. What is the advantage of using wp_mail?
  66. How to make a WordPress plugin translation ready?
  67. How many times will this code run? (or, how rich is grandma?)
  68. How to create an API for my plugin?
  69. Is it ever okay to include inline CSS in plugins?
  70. Plugins in symlinked directories?
  71. How to override existing plugin action with new action
  72. How to include a file using get_template_part() in a plugin?
  73. Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
  74. How to store username and password to API in wordpress option DB?
  75. body_class hook for admin pages
  76. “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
  77. Is it mandatory to use $wpdb->prefix in custom tables
  78. Which hook should be used to add an action containing a redirect?
  79. add_action hook for completely new post?
  80. Why does WordPress add 0 (zero) to an Ajax response?
  81. What should I use instead of WP_CONTENT_DIR and WP_PLUGIN_DIR?
  82. How to enqueue JavaScripts in a plugin
  83. In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
  84. Plugin Form Submission Best Practice
  85. How to redirect to settings page once the plugin is activated?
  86. Is get_option function cached?
  87. Should Plugin Folders Include a Blank index.php File?
  88. Unit testing for plugin development
  89. Methods of Integrating Plugin Data with Themes
  90. What is the wordpress wp-includes folder for?
  91. WordPress Update Plugin Hook/Action? Since 3.9
  92. How to include jQuery and JavaScript files correctly?
  93. How come `wp_options` table does not have an index on `autoload`?
  94. PHP error with shortcode handler from a class
  95. Update Option Stored in Multi-Dimensional Array
  96. check if Gutenberg is currently in use
  97. Best way to abort plugin in case of insufficient PHP version?
  98. WordPress Plugin Development – Headers Already Sent Message
  99. WP 3.3 How to Add Menu Items to the Admin Bar?
  100. dbDelta not creating tables
Categories plugin-development Tags plugin-development, post-meta
Unable to disable Gutenberg with plugin Classic Editor or Disable Gutenberg
Validate custom fields before save using WordPress Rest API

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress