Posted By

oneupdzn on 06/30/13


Tagged


Versions (?)

Wordpress Settings Api [incomplete]


 / Published in: PHP
 

Wordpress settings API backup

  1. <?php
  2.  
  3. define('THEME_SHORTNAME', 'testing-ground'); // Used to prefix the individual setting field ids
  4. define('THEME_BASE_NAME', 'testing-ground-settings'); // The settings page slug
  5. $theme_domain = 'testing-ground-domain'; // The domain for localization (http://codex.wordpress.org/Translating_WordPress)
  6.  
  7. function testing_ground_get_options() { // Helper function, not needed but helpful to have.
  8. $output = array(); // Create an array to contain the helper variables
  9.  
  10. // put together the output array
  11. $output['testing_ground_option_name'] = 'testing_ground_option'; // the option name as used in the get_option() call
  12. $output['testing_ground_page_title'] = __( 'Testing Ground Settings Page', $theme_domain); // the settings page title
  13. $output['testing_ground_page_sections'] = ''; // the setting section
  14. $output['testing_ground_page_fields'] = ''; // the setting fields
  15. $output['testing_ground_contextual_help'] = ''; // the contextual help
  16.  
  17. return $output; // return the $output array
  18. }
  19.  
  20. function testing_ground_register_settings() { // Registers the settings to allow them to be valid and available in Wordpress
  21. $settings_output = testing_ground_get_options();
  22. $testing_ground_option_name = $settings_output['testing_ground_option_name'];
  23.  
  24. //registering the setting
  25. //register_setting( $option_group, $option_name, $sanitize_callback = '' );
  26. register_setting( $testing_ground_option_name, $testing_ground_option_name, 'testing_ground_validate_options' );
  27. }
  28.  
  29. function testing_ground_settings_page_fn() { // The callback function we defined in testing_ground_add_menu(). Is run automatically
  30. $settings_output = testing_ground_get_options(); // Getting the array from testing_ground_get_options() and storing it in the $settings_output variable
  31. // essc_attr_e() used below to create a translatable, escaped string (http://codex.wordpress.org/Function_Reference/esc_attr_e)
  32. // Closing PHP to output HTMl ?>
  33.  
  34. <div class="wrap">
  35. <div class="icon32" id="icon-options-general"></div>
  36. <h2><?php echo $settings_output['testing_ground_page_title']; ?></h2>
  37.  
  38. <form action="options.php" method="post">
  39. <p class="submit">
  40. <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes', $theme_domain); ?>" />
  41. </p>
  42. </form>
  43. </div><!-- end wrap -->
  44.  
  45. <?php } // Closing testing_ground_settings_page_fn()
  46.  
  47. add_action( 'admin_menu', 'testing_ground_add_menu' ); // Hooks the function in to the 'admin_menu' Wordpress hook.
  48. add_action( 'admin-init', 'testing_ground_validate_options' );
  49. function testing_ground_add_menu() {
  50. //Adding settings page to the Wordpress admin menu (http://codex.wordpress.org/Function_Reference/add_theme_page);
  51. //add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' );
  52. $testing_ground_settings_page = add_theme_page( __('Testing Ground Options', $theme_domain) , __('Testing Ground Options', $theme_domain), 'manage_options', THEME_BASE_NAME, 'testing_ground_settings_page_fn' );
  53. }
  54.  
  55. ?>

Report this snippet  

You need to login to post a comment.