WordPress.org

Ready to get started?Download WordPress

Forums

Undefined index: _noncename !wp_verify_nonce with meta box (2 posts)

  1. Cerzky
    Member
    Posted 1 year ago #

    Please help. The following two errors are generated while using my plugin with debug=true.
    Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/wordpress2/wp-content/plugins/Employee/EmployeePostType.php on line 155

    Notice: Undefined index: _noncename in /Applications/XAMPP/xamppfiles/htdocs/wordpress2/wp-content/plugins/Employee/EmployeePostType.php on line 155

    /***************MY CODE ************************\

    function save_postdata( $post_id ) {
    global $post, $new_meta_boxes;
    
    foreach($new_meta_boxes as $meta_box) {
    	// Verify
    		if ( !wp_verify_nonce( $_POST[$new_meta_box['name'].'_noncename'], plugin_basename(__FILE__) )){
    				return $post_id;
    			}
    		if ( 'page' == $_POST['post_type'] ) {
    			if ( !current_user_can( 'edit_page', $post_id ))
    			return $post_id;
    			} else {
    			if ( !current_user_can( 'edit_post', $post_id ))
    			return $post_id;
    			}
    
    			$data = $_POST[$meta_box['name']];
    
    			if(get_post_meta($post_id, $meta_box['name']) == "")
    			add_post_meta($post_id, $meta_box['name'], $data, true);
    			elseif($data != get_post_meta($post_id, $meta_box['name'], true))
    			update_post_meta($post_id, $meta_box['name'], $data);
    			elseif($data == "")
    			delete_post_meta($post_id, $meta_box['name'], get_post_meta($post_id, $meta_box['name'], true));
    			}
    		}
    add_action('admin_menu', 'create_meta_box');
    add_action('save_post', 'save_postdata');
  2. Cerzky
    Member
    Posted 1 year ago #

    Line 155 is @
    if ( !wp_verify_nonce( $_POST[$new_meta_box['name'].'_noncename'], plugin_basename(__FILE__) )){

Topic Closed

This topic has been closed to new replies.

About this Topic