values from the same metabox (and therefore same nonce) into the $data argument, * repeated checks against the nonce, request and permissions are avoided. * * @since 1.0.0 */ function bizznis_save_custom_fields( array $data, $nonce_action, $nonce_name, $post, $post_id ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '1.1.0' ); } # Verify the nonce if ( ! isset( $_POST[ $nonce_name ] ) || ! wp_verify_nonce( $_POST[ $nonce_name ], $nonce_action ) ) { return; } # Don't try to save the data under autosave, ajax, or future post. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( defined( 'DOING_CRON' ) && DOING_CRON ) { return; } # Grab the post object if ( ! is_null( $deprecated ) ) { $post = get_post( $deprecated ); } else { $post = get_post( $post ); } # Don't save if WP is creating a revision (same as DOING_AUTOSAVE?) if ( 'revision' == get_post_type( $post ) ) { return; } # Check that the user is allowed to edit the post if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; } # Cycle through $data, insert value or delete field foreach ( (array) $data as $field => $value ) { # Save $value, or delete if the $value is empty if ( $value ) { update_post_meta( $post_id, $field, $value ); } else { delete_post_meta( $post_id, $field ); } } } /** * Takes an array of new settings, merges them with the old settings, and pushes them into the database. * * @since 1.1.0 * * @uses BIZZNIS_SETTINGS_FIELD * * @param string|array $new New settings. Can be a string, or an array. * @param string $setting Optional. Settings field name. Default is BIZZNIS_SETTINGS_FIELD. */ function bizznis_update_settings( $new = '', $setting = BIZZNIS_SETTINGS_FIELD ) { $old = get_option( $setting ); $settings = wp_parse_args( $new, $old ); //* Allow settings to be deleted foreach ( $settings as $key => $value ) { if ( 'unset' == $value ) { unset( $settings[ $key ] ); } } return update_option( $setting, $settings ); }