User

The User field allows you to select one of your WordPress users from a searchable dropdown menu.

This field type is exclusive to Block Lab Pro.

Settings

  • Help Text: Instructions to describe the data needed in the field.
  • Placeholder Text: The helper text which appears when the input is empty.

PHP API Controls

  • name
  • label
  • control
  • type
  • order
  • location
  • width
  • help

Template Usage

To display the User field in your template, use the field name you provided.

<?php block_field( 'team-member' ); ?>

The API will return a WP_User object, and echo the user’s nicename (the name they’ve chosen to display publicly). See the WP_User class on WordPress.org.

Example template file /blocks/block-block-lab-example.php

<?php
// Block Lab Example User Field

Please ask <?php block_field( 'team-member' ); ?> for more information about this pet.

To use the block with the User field on your site, locate it in the blocks menu.

Screenshot showing the Block Lab custom block in the menu

It will then display within your post/page.

And on the front-end of your site.

Since you are pulling from the users on your WordPress site, you can take advantage of other attributes associated with them as well.

<?php
// Block Lab Example User Field

Please ask <?php block_field( 'team-member' ); ?> for more information about this pet.

<div>
    <?php
    $user = block_value( 'user' );
        echo get_avatar( $user->ID );
    ?>
</div>