Add filter hook for countries ( checkbox and select ) - mdhemalakhand1999/WordPressPluginDevelopment GitHub Wiki

For Add filter hook into countries ( checkbox and select ) you can use this code:


/**
* Declare countries
*/
$pqrc_countries = array(
    'Bangladesh',
    'Africa',
    'Malaysia',
    'Maldives',
    'New York',
    'Netherland',
    'Australia'
);
/**
* add into filter with init hook
*/
function pqrc_init() {
    global $pqrc_countries;
    $pqrc_countries = apply_filters("pqrc_country_list", $pqrc_countries);
}
add_action('init', 'pqrc_init');
/**
* add into country select 
*/
function pqrc_country_callback() {
    $selected_country = get_option('pqrc_country');
    global $pqrc_countries;
    printf("", 'pqrc_country', 'pqrc_country');
    foreach($pqrc_countries as $country) {
        $selected_country_selected = '';
        if($selected_country == $country) {
                $selected_country_selected = 'selected';
            }
            printf("%s", $country, $selected_country_selected, $country);
        }
    echo '';
}

/**
 * Create multiple select checkbox
 */

function ptc_multiple_select_checkbox() {
    add_settings_field('multiple_select_country', 'Select Your Country', 'multiple_select_country_callback', 'general');
    register_setting( 'general', 'multiple_select_country' );
}
add_action('admin_init', 'ptc_multiple_select_checkbox');
function multiple_select_country_callback() {
    $options = get_option('multiple_select_country');
    global $pqrc_countries;
    foreach($pqrc_countries as $country) {
        $country_checked = '';
        if(is_array($options) && in_array($country, $options)) {
            $country_checked = 'checked';
        }
        printf(" %s
", $country, $country_checked, $country); } }

Thats it! Happy coading.

⚠️ **GitHub.com Fallback** ⚠️