Last active
April 8, 2019 13:01
-
-
Save eto4detak/d1d2257aac3b91f14e17077dd7857616 to your computer and use it in GitHub Desktop.
wp php register_setting field-general
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function divie_add_option_field_to_general_admin_page(){ | |
$option_name = 'divie_company_location'; | |
register_setting( 'general', $option_name ); | |
add_settings_field( | |
'myprefix_setting-id', | |
'Локация компании', | |
'divie_setting_callback_location_gen_opt', | |
'general', | |
'default', | |
array( | |
'id' => 'divie_company_location', | |
'option_name' => $option_name | |
) | |
); | |
} | |
add_action('admin_menu', 'divie_add_option_field_to_general_admin_page'); | |
function divie_setting_callback_location_gen_opt( $val ){ | |
$id = $val['id']; | |
$option_name = $val['option_name']; | |
?> | |
<input class="regular-text" | |
type="text" | |
name="<? echo $option_name ?>" | |
id="<? echo $id ?>" | |
value="<? echo esc_attr( get_option($option_name) ) ?>" | |
rows="5" | |
/> | |
<? | |
} | |
/*======================================================== | |
* админинка, добавить поле | |
========================================================*/ | |
add_action( 'admin_init', 'art_for_woo_api_init' ); | |
function art_for_woo_api_init() { | |
// Добавляем блок опций на базовую страницу "Чтение" | |
add_settings_section( | |
'eg_setting_section', // секция | |
'Настройки для woocomerce', | |
'', | |
'reading' // страница | |
); | |
add_settings_field( | |
'art_view_all_product', | |
'Скрыть цены на woocommerce', | |
'art_for_woo_setting_callback_function', // можно указать '' | |
'reading', // страница | |
'eg_setting_section' // секция | |
); | |
register_setting( 'reading', 'art_view_all_product' ); | |
} | |
function art_for_woo_setting_callback_function() { | |
echo '<input | |
name="art_view_all_product" | |
type="checkbox" | |
' . checked( 1, get_option( 'art_view_all_product' ), false ) . ' | |
value="1" | |
class="code" | |
/>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment