[ label, type, group ] */ function abddir_get_meta_fields() { return [ // Contact Info 'abddir_address' => [ 'label' => 'Street Address', 'type' => 'text', 'group' => 'contact' ], 'abddir_address2' => [ 'label' => 'Address Line 2', 'type' => 'text', 'group' => 'contact' ], 'abddir_community' => [ 'label' => 'Community / Township (optional)', 'type' => 'text', 'group' => 'contact' ], 'abddir_city' => [ 'label' => 'City', 'type' => 'text', 'group' => 'contact' ], 'abddir_state' => [ 'label' => 'State', 'type' => 'text', 'group' => 'contact' ], 'abddir_zip' => [ 'label' => 'ZIP Code', 'type' => 'text', 'group' => 'contact' ], 'abddir_phone' => [ 'label' => 'Phone', 'type' => 'tel', 'group' => 'contact' ], 'abddir_email' => [ 'label' => 'Email', 'type' => 'email', 'group' => 'contact' ], 'abddir_website' => [ 'label' => 'Website URL', 'type' => 'text', 'group' => 'contact' ], 'abddir_contact_name' => [ 'label' => 'Contact Name (optional)', 'type' => 'text', 'group' => 'contact' ], // Description 'abddir_description' => [ 'label' => 'Business Description', 'type' => 'textarea', 'group' => 'info' ], // Social Media 'abddir_facebook' => [ 'label' => 'Facebook URL', 'type' => 'text', 'group' => 'social' ], 'abddir_instagram' => [ 'label' => 'Instagram URL', 'type' => 'text', 'group' => 'social' ], 'abddir_twitter' => [ 'label' => 'X / Twitter URL', 'type' => 'text', 'group' => 'social' ], 'abddir_linkedin' => [ 'label' => 'LinkedIn URL', 'type' => 'text', 'group' => 'social' ], 'abddir_youtube' => [ 'label' => 'YouTube URL', 'type' => 'text', 'group' => 'social' ], 'abddir_tiktok' => [ 'label' => 'TikTok URL', 'type' => 'text', 'group' => 'social' ], 'abddir_pinterest' => [ 'label' => 'Pinterest URL', 'type' => 'text', 'group' => 'social' ], // Logo 'abddir_logo' => [ 'label' => 'Logo / Photo', 'type' => 'image', 'group' => 'logo' ], // Display order 'abddir_sort_order' => [ 'label' => 'Sort Order', 'type' => 'number', 'group' => 'display' ], ]; } // Register meta boxes function abddir_add_meta_boxes() { // Logo box label adapts to directory type $dir_type = 'business'; $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only, used only to determine directory type for meta box label if ( $post_id ) { $dir_id = intval( get_post_meta( $post_id, 'abddir_directory_id', true ) ); $dir_s = abddir_get_directory_settings( $dir_id ); $dir_type = $dir_s['type'] ?? 'business'; } $logo_box_label = ( $dir_type === 'member' || $dir_type === 'employee' ) ? 'Avatar / Photo' : 'Business Logo'; add_meta_box( 'abddir_logo_box', $logo_box_label, 'abddir_render_meta_box_logo', 'abddir_listing', 'side', 'high', [ 'dir_type' => $dir_type ] ); add_meta_box( 'abddir_contact_info', 'Contact Information', 'abddir_render_meta_box_contact', 'abddir_listing', 'normal', 'high' ); add_meta_box( 'abddir_social_links', 'Social Media Links', 'abddir_render_meta_box_social', 'abddir_listing', 'normal', 'default' ); add_meta_box( 'abddir_display_opts', 'Display Options', 'abddir_render_meta_box_display', 'abddir_listing', 'side', 'default' ); } add_action( 'add_meta_boxes', 'abddir_add_meta_boxes' ); function abddir_render_meta_box_logo( $post, $metabox ) { wp_enqueue_media(); $logo = get_post_meta( $post->ID, 'abddir_logo', true ); $dir_type = $metabox['args']['dir_type'] ?? 'business'; $is_people = ( $dir_type === 'member' || $dir_type === 'employee' ); $btn_label = $is_people ? 'Select Photo' : 'Select Logo'; // Stored value can be an attachment ID or a direct URL $preview_src = ''; if ( $logo && is_numeric( $logo ) ) { $preview_src = wp_get_attachment_image_url( intval( $logo ), 'medium' ) ?: ''; } elseif ( $logo ) { $preview_src = $logo; } ?>
Listings without an image show a colored initials avatar.
| '; if ( $field['type'] === 'textarea' ) { echo ''; } else { echo ''; } echo ' | |
| '; echo ''; echo ' |
| '; echo ''; echo ' | |
| '; echo ''; echo ' |
';
echo '