plugin development – Saving metabox updates causing fatal error


I’m teaching myself from a plugin tutorial dvd, everything was going fine.
I’ve setup custom_post_types and the metaboxes with no issues. The issue i have is a fatal error when i update/publish the post

Fatal error: Uncaught ArgumentCountError: Too few arguments to function mdb_save_metaboxes(), 1 passed in C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php on line 310 and exactly 3 expected in C:\xampp\htdocs\wordpress\wp-content\plugins\maxi_metaboxes\maxi_metabox_types.php:45 Stack trace: #0

To check i was not adapting the code incorrectly, I back tracked and used the tutors metaboxes and code that worked for him, but it still doesn’t.

I have a good idea it is to do with the verify_nonce check in the mdb_save_metaboxes function.
Any help will be greatly accepted.


 * Plugin Name:      Driver Bible metaboxes
 * Plugin URI:        
 * Description:      Adds metaboxes to Driver Bible
 * Version:           1.0
 * Author:            Fuzzy
 * Author URI:        
 * License:           GPL v2 or later
 * License URI:

  function mdb_add_metaboxes() {
    add_meta_box('mdb-metaboxes', 'Dealer Info', 'mdb_metaboxes_container', 'dealers', 'normal', 'high', 'null');
add_action('add_meta_boxes', 'mdb_add_metaboxes');

//Add metaboxes
function mdb_metaboxes_container($post) {

    wp_nonce_field(basename(__FILE__), "meta-box-nonce");
        <label for="input-metaboxes">Cal:</label>
        <input type="text" name="input-metabox" value="<?php echo get_post_meta($post->ID, "input-metabox", true); ?>">
        <label for="textarea-metaboxes">text area:</label>
        <textarea type="text" name="textarea-metabox"><?php echo get_post_meta($post->ID, "textarea-metabox", true); ?></textarea>


//Saving metabox updates

//permissions check
add_action('save_post', 'mdb_save_metaboxes');
function mdb_save_metaboxes($post_id, $post, $update){
    if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
        return $post_id;

    if(!current_user_can("edit_post", $post_id))
        return $post_id;

        return $post_id;

// save

$input_metabox ='';
$textarea_metabox ='';

if(isset($_POST["input-metabox"])) {
    $input_metabox = $_POST["input-metabox"];
update_post_meta($post_id, "input-metabox", $input_metabox );

if(isset($_POST["textarea-metabox"])) {
    $textarea_metabox = $_POST["textarea-metabox"];
update_post_meta($post_id, "textarea-metabox", $textarea_metabox );


fuzzy2023 2 months 2023-03-29T08:13:03-05:00 0 Answers 0 views 0

Leave an answer