Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. <?php
  2. // ------------------------------------------------------------------
  3. // Add all your sections, fields and settings during admin_init
  4. // ------------------------------------------------------------------
  5. //
  6.  
  7. function eg_settings_api_init() {
  8. // Add the section to reading settings so we can add our
  9. // fields to it
  10. add_settings_section(
  11. 'eg_setting_section',
  12. 'Example settings section in reading',
  13. 'eg_setting_section_callback_function',
  14. 'reading'
  15. );
  16.  
  17. // Add the field with the names and function to use for our new
  18. // settings, put it in our new section
  19. add_settings_field(
  20. 'eg_setting_name',
  21. 'Example setting Name',
  22. 'eg_setting_callback_function',
  23. 'reading',
  24. 'eg_setting_section'
  25. );
  26.  
  27. // Register our setting so that $_POST handling is done for us and
  28. // our callback function just has to echo the <input>
  29. register_setting( 'reading', 'eg_setting_name' );
  30. } // eg_settings_api_init()
  31.  
  32. add_action( 'admin_init', 'eg_settings_api_init' );
  33.  
  34.  
  35. // ------------------------------------------------------------------
  36. // Settings section callback function
  37. // ------------------------------------------------------------------
  38. //
  39. // This function is needed if we added a new section. This function
  40. // will be run at the start of our section
  41. //
  42.  
  43. function eg_setting_section_callback_function() {
  44. echo '<p>Intro text for our settings section</p>';
  45. }
  46.  
  47. // ------------------------------------------------------------------
  48. // Callback function for our example setting
  49. // ------------------------------------------------------------------
  50. //
  51. // creates a checkbox true/false option. Other types are surely possible
  52. //
  53.  
  54. function eg_setting_callback_function() {
  55. echo '<input name="eg_setting_name" id="eg_setting_name" type="checkbox" value="1" class="code" ' . checked( 1, get_option( 'eg_setting_name' ), false ) . ' /> Explanation text';
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement