mardi 22 mars 2016

I want to add an options page to my wp plugin

I want to add an options page to my wp plugin but it is not being displayed. I had copied this code from an earlier plugin of mine. Please notify if you see any discontinuation of code. A bunch of thanks in advance!

//Registering fields for the settings page
function SPIG_settings_init(  ) { 
register_setting( 'pluginPage', 'SPIG_settings' );
add_settings_section(
'SPIG_pluginPage_section', 
__( 'This is the options page for the Scattered Polaroid Image Gallery plugin.', 'wordpress' ), 
        'SPIG_settings_section_callback', 
        'pluginPage'
    );

    add_settings_field( 
        'SPIG_text_field_0', 
        __( 'Select the color of the overlay.', 'wordpress' ), 
        'SPIG_text_field_0_render', 
        'pluginPage', 
        'SPIG_pluginPage_section' 
    );

    add_settings_field( 
        'SPIG_text_field_1', 
        __( 'Select the color of the polaroid backgrounds.', 'wordpress' ), 
        'SPIG_text_field_1_render', 
        'pluginPage', 
        'SPIG_pluginPage_section' 
    );

    add_settings_field( 
        'SPIG_text_field_2', 
        __( 'Select the background color of the gallery section.', 'wordpress' ), 
        'SPIG_text_field_2_render', 
        'pluginPage', 
        'SPIG_pluginPage_section' 
    );


}
add_action( 'admin_init', 'SPIG_settings_init' );

//Callback function to display the overlay color field 
function SPIG_text_field_0_render(  ) { 

    $options = get_option( 'SPIG_settings' );
    ?>    

    <input class='color-field' type="text" name='SPIG_settings[SPIG_text_field_0]' value='<?php echo $options['SPIG_text_field_0']; ?>'/> 
    <?php

}

//Callback function to display the background color picker field 
function SPIG_text_field_1_render(  ) { 

    $options = get_option( 'SPIG_settings' );
    ?>
    <input type='text' class='color-field' name='SPIG_settings[SPIG_text_field_1]' value='<?php echo $options['SPIG_text_field_1']; ?>'>
    <?php

}

//Callback function to display the polaroid color picker field 
function SPIG_text_field_2_render(  ) { 

    $options = get_option( 'SPIG_settings' );
    ?>                               

    <input type='text' class='color-field' name='SPIG_settings[SPIG_text_field_2]' value='<?php echo $options['SPIG_text_field_2']; ?>'>
    <?php

}

//Callback function to display the subtext under the title
function SPIG_settings_section_callback(  ) { 

    echo __( 'This is the options page for the Scattered Polaroid Image Gallery plugin.', 'wordpress' );

}

//Creating the settings page
function SPIG_options_page(  ) { 

    ?>
    <form action='options.php' method='post'>
        <i class="dashicons dashicons-format-gallery"></i><h2>Scattered Polaroid Image Gallery</h2>

        <?php
        settings_fields( 'pluginPage' );
        do_settings_sections( 'pluginPage' );
        submit_button();
        ?>

    </form>
    <?php

}

function SPIG_menu_page(){
    add_menu_page('Scattered Polaroid Image Gallery','Scattered Polaroid Gallery','manage_options',__FILE__,'SPIG_options_page','dashicons-images-alt');
} 
add_action('admin_menu','SPIG_menu_page'); 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire