epl_elementor_agent_id: which agent the Elementor agent widgets show
Description #
Filters the agent EPL's Elementor agent widgets show for a listing, one position at a time. The Author Box, Photo, Name, Position, Contact, Social, Bio and Staff Listings widgets use the first agent; the Agents widget uses up to four.
EPL reads the listing's agent field for that position (property_agent, property_second_agent, property_third_agent, property_fourth_agent). When the Staff Directory extension stores staff details in Directory posts, the ID is the Directory post found for that username (see epl_elementor_directory_agent). Otherwise it's the WordPress user with that login, or the value itself when it's a number. For the first agent EPL falls back to the listing's author. Return 0 for no agent at that position.
When the listing itself is a Staff Directory post, that post is the first agent and this filter doesn't run for it.
Part of the Elementor integration, which is in beta. See Elementor widgets and templates (beta) for how the widgets and templates fit together.
Usage #
add_filter( 'epl_elementor_agent_id', 'my_function', 10, 4 );
Parameters #
$id (int)
The agent's ID: a WordPress user ID, or a Directory post ID when Staff Directory stores staff in Directory posts. 0 when none was found.
$raw (mixed)
The listing's agent field for this position, as saved.
$index (int)
The position: 0 for the first agent, up to 3 for the fourth.
$property (EPL_Property_Meta)
The listing.
Examples #
Show the "office" user for listings imported with the agent name "Sales Team":
function my_epl_map_agent( $id, $raw, $index, $property ) {
if ( 'Sales Team' === $raw ) {
$user = get_user_by( 'login', 'office' );
return $user ? $user->ID : $id;
}
return $id;
}
add_filter( 'epl_elementor_agent_id', 'my_epl_map_agent', 10, 4 );
Source #
lib/page-builders/elementor/class-epl-elementor.php, in EPL_Elementor::get_listing_agent(). Since 3.6.