Differenze tra le versioni di "WordPress:Sezione di una pagina di amministrazione"

 
(2 versioni intermedie di uno stesso utente non sono mostrate)
Riga 4: Riga 4:
  
 
[[File: sdvsbdrvuydvbuiy5g.png|frame|center]]
 
[[File: sdvsbdrvuydvbuiy5g.png|frame|center]]
 +
 +
<pre>
 +
add_action( 'admin_init', 'my_settings_init' );
 +
 +
function my_settings_init() {
 +
 +
    add_settings_section(
 +
        'sample_page_setting_section',
 +
        __( 'Custom settings', 'my-textdomain' ),
 +
        'my_setting_section_callback_function',
 +
        'sample-page'
 +
    );
 +
 +
add_settings_field(
 +
  'my_setting_field',
 +
  __( 'My custom setting field', 'my-textdomain' ),
 +
  'my_setting_markup',
 +
  'sample-page',
 +
  'sample_page_setting_section'
 +
);
 +
 +
register_setting( 'sample-page', 'my_custom_settings_options' );
 +
}
 +
 +
function my_setting_section_callback_function() {
 +
    echo '<p>Intro text for our settings section</p>';
 +
}
 +
 +
function my_setting_markup() {
 +
    ?>
 +
    <label for="my_setting_field"><?php _e( 'My Input', 'my-textdomain' ); ?></label>
 +
    <input type="text" id="my_setting_field" name="my_setting_field">
 +
    <?php
 +
}
 +
</pre>
 +
fonte: https://themes.artbees.net/blog/custom-setting-page-in-wordpress/

Versione attuale delle 20:32, 5 set 2021

← ritorno

Sdvsbdrvuydvbuiy5g.png
add_action( 'admin_init', 'my_settings_init' );

function my_settings_init() {

    add_settings_section(
        'sample_page_setting_section',
        __( 'Custom settings', 'my-textdomain' ),
        'my_setting_section_callback_function',
        'sample-page'
    );

	add_settings_field(
	   'my_setting_field',
	   __( 'My custom setting field', 'my-textdomain' ),
	   'my_setting_markup',
	   'sample-page',
	   'sample_page_setting_section'
	);

	register_setting( 'sample-page', 'my_custom_settings_options' );
}

function my_setting_section_callback_function() {
    echo '<p>Intro text for our settings section</p>';
}

function my_setting_markup() {
    ?>
    <label for="my_setting_field"><?php _e( 'My Input', 'my-textdomain' ); ?></label>
    <input type="text" id="my_setting_field" name="my_setting_field">
    <?php
}

fonte: https://themes.artbees.net/blog/custom-setting-page-in-wordpress/