Multiple Admin Emails Retrieval

User
public static function get_admin_email() {
$admin_email = get_option( 'admin_email' );

return apply_filters( 'geodir_admin_email', $admin_email );
}
overright above set 2 admin emails

Assistant
If you want to override the `get_admin_email` function to return two admin emails instead of just one, you can modify it to return an array of email addresses. However, since the function retrieves the email from the WordPress options, you'll need to either store both emails in a single option (comma-separated or serialized) or fetch an additional option.

Here’s an example of how you can override it to return two admin emails:

### Method 1: Hardcoding the Emails
If the emails are fixed, you can directly return them as an array:

public static function get_admin_email() {
    $admin_emails = [
        'admin1@example.com',
        'admin2@example.com',
    ];

    return apply_filters('geodir_admin_email', $admin_emails);
}

### Method 2: Using WordPress Options
If you want the emails to be dynamic, you can save multiple emails in a single option, separated by commas:
1. Set the admin emails in the WordPress database:

update_option('geodir_admin_emails', 'admin1@example.com,admin2@example.com');

2. Modify the function to retrieve and split them:

public static function get_admin_email() {
       $admin_emails = get_option('geodir_admin_emails');
       $emails_array = explode(',', $admin_emails);

       return apply_filters('geodir_admin_email', $emails_array);
   }

### Method 3: Supporting Fallback to Single Email
If you want to maintain compatibility with the original single-email setup, you can use a fallback mechanism:

public static function get_admin_email() {
    $admin_emails = get_option('geodir_admin_emails');
    if (empty($admin_emails)) {
        // Fallback to default single email
        $admin_email = get_option('admin_email');
        $emails_array = [$admin_email];
    } else {
        $emails_array = explode(',', $admin_emails);
    }

    return apply_filters('geodir_admin_email', $emails_array);
}

### Important Notes:
– **Filter Usage:** Ensure that the filters applied (`geodir_admin_email`) are updated to handle arrays if you are passing multiple emails.
– **Validation:** Validate the email addresses to avoid issues with invalid data being returned.
– **Backward Compatibility:** Be cautious about changes if other parts of your code expect a single email string instead of an array. You might need to refactor those parts accordingly.

Leave a Comment

Your email address will not be published. Required fields are marked *