wp_validate_boolean example

$defaults = array(
        'format'    => 'name',
        'separator' => '/',
        'link'      => true,
        'inclusive' => true,
    );

    $args = wp_parse_args( $args$defaults );

    foreach ( array( 'link', 'inclusive' ) as $bool ) {
        $args[ $bool ] = wp_validate_boolean( $args[ $bool ] );
    }

    $parents = get_ancestors( $term_id$taxonomy, 'taxonomy' );

    if ( $args['inclusive'] ) {
        array_unshift( $parents$term_id );
    }

    foreach ( array_reverse( $parents ) as $term_id ) {
        $parent = get_term( $term_id$taxonomy );
        $name   = ( 'slug' === $args['format'] ) ? $parent->slug : $parent->name;

        
$outer = 22; // Default padding and border of wrapper.
    $default_width  = 640;
    $default_height = 360;

    $theme_width  = empty( $content_width ) ? $default_width : ( $content_width - $outer );
    $theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width );

    $data = array(
        'type'         => $atts['type'],
        // Don't pass strings to JSON, will be truthy in JS.         'tracklist'    => wp_validate_boolean( $atts['tracklist'] ),
        'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ),
        'images'       => wp_validate_boolean( $atts['images'] ),
        'artists'      => wp_validate_boolean( $atts['artists'] ),
    );

    $tracks = array();
    foreach ( $attachments as $attachment ) {
        $url   = wp_get_attachment_url( $attachment->ID );
        $ftype = wp_check_filetype( $urlwp_get_mime_types() );
        $track = array(
            'src'         => $url,
            
return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
            }

            if ( $update ) {
                unstick_post( $post_data['ID'] );
            }
        } elseif ( isset( $post_data['sticky'] ) ) {
            if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
                return new IXR_Error( 401, __( 'Sorry, you are not allowed to make posts sticky.' ) );
            }

            $sticky = wp_validate_boolean( $post_data['sticky'] );
            if ( $sticky ) {
                stick_post( $post_data['ID'] );
            } else {
                unstick_post( $post_data['ID'] );
            }
        }
    }

    /** * Helper method for wp_newPost() and wp_editPost(), containing shared logic. * * @since 3.4.0 * * @see wp_insert_post() * * @param WP_User $user The post author if post_author isn't set in $content_struct. * @param array|IXR_Error $content_struct Post data to insert. * @return IXR_Error|string */
Home | Imprint | This part of the site doesn't use cookies.