values from the same meta box (and therefore same nonce) into the $data argument, * repeated checks against the nonce, request and permissions are avoided. * * @since 1.9.0 * * @param array $data Key/Value pairs of data to save in '_field_name' => 'value' format. * @param string $nonce_action Nonce action for use with wp_verify_nonce(). * @param string $nonce_name Name of the nonce to check for permissions. * @param WP_Post|int $post Post object or ID. * @param int $deprecated Deprecated (formerly accepted a post ID). * @return void Return early if permissions are incorrect, doing autosave, Ajax or future post. */ function genesis_save_custom_fields( array $data, $nonce_action, $nonce_name, $post, $deprecated = null ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '2.0.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 ( 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 2.1.0 * * @param string|array $new New settings. Can be a string, or an array. * @param string $setting Optional. Settings field name. Default is GENESIS_SETTINGS_FIELD. * @return bool `true` if option was updated, `false` otherwise. */ function genesis_update_settings( $new = '', $setting = GENESIS_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 ); }