get_queried_object_id() ), $field, true ); if ( ! $custom_field ) { return ''; } # Return custom field, slashes stripped, sanitized if string return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) ); } /** * Save post meta / custom field data for a post or page. * * @since 1.0.0 */ function bizznis_save_custom_fields( array $data, $nonce_action, $nonce_name, $post, $post_id ) { # 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; } # Don't save if WP is creating a revision (same as DOING_AUTOSAVE?) if ( 'revision' == $post->post_type ) { 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 ); } } } /** * Merge term meta data into options table. * * @since 1.0.0 */ add_filter( 'get_term', 'bizznis_get_term_filter', 10, 2 ); #wp function bizznis_get_term_filter( $term, $taxonomy ) { # Stop here, if $term is not object if ( ! is_object( $term ) ) { return $term; } $db = get_option( 'bizznis-term-meta' ); $term_meta = isset( $db[$term->term_id] ) ? $db[$term->term_id] : array(); $term->meta = wp_parse_args( $term_meta, apply_filters( 'bizznis_term_meta_defaults', array( 'headline' => '', 'intro_text' => '', 'display_title' => 0, //* vestigial 'display_description' => 0, //* vestigial 'doctitle' => '', 'description' => '', 'layout' => '', 'noindex' => 0, 'nofollow' => 0, 'noarchive' => 0, ) ) ); # Sanitize term meta foreach ( $term->meta as $field => $value ) { $term->meta[$field] = apply_filters( 'bizznis_term_meta_' . $field, stripslashes_deep( wp_kses_decode_entities( $value ) ), $term, $taxonomy ); } $term->meta = apply_filters( 'bizznis_term_meta', $term->meta, $term, $taxonomy ); return $term; } /** * Add Bizznis term-meta data to functions that return multiple terms. * * @since 1.0.0 */ add_filter( 'get_terms', 'bizznis_get_terms_filter', 10, 2 ); #wp function bizznis_get_terms_filter( array $terms, $taxonomy ) { foreach( $terms as $term ) { $term = bizznis_get_term_filter( $term, $taxonomy ); } return $terms; } /** * Takes an array of new settings, merges them with the old settings, * and pushes them into the database. * * @since 1.0.0 */ function _bizznis_update_settings( $new = '', $setting = BIZZNIS_SETTINGS_FIELD ) { update_option( $setting, wp_parse_args( $new, get_option( $setting ) ) ); }