Created
January 9, 2012 11:13
-
-
Save EnvatoWP/1582533 to your computer and use it in GitHub Desktop.
Bug Hunt One [SOLVED]
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 | |
/* | |
* Plugin Name: EnvatoWP Bug Hunt One | |
* Plugin URI: https://gist.github.com/ | |
* Description: Bug Hunt One - Find all the bugs in this basic plugin | |
* Version: 0.1 | |
* Author: EnvatoWP | |
* Author URI: http://envatowp.github.com/ | |
* License: GPL2 | |
*/ | |
function bhone_add_menu() | |
{ | |
$bhone_settings_page = add_plugins_page( | |
__( 'Bug Hunt One Settings' ), | |
__( 'Bug Hunt One' ), | |
'manage_options', | |
'bhone-settings', | |
'bhone_settings_page' | |
); | |
} | |
function bhone_settings_page() | |
{ | |
?> | |
<div class="wrap"> | |
<div class="icon32" id="icon-options-general"></div> | |
<h2><?php _e( 'EnvatoWP Bug Hunt One Settings' ); ?></h2> | |
<form action="options.php" method="post"> | |
<?php settings_fields( 'bhone_settings' ); ?> | |
<?php do_settings_sections( 'bhone_settings_page' ); ?> | |
<p class="submit"> | |
<input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes' ); ?>" /> | |
</p> | |
</form> | |
</div> | |
<?php | |
} | |
function bhone_register_settings() | |
{ | |
register_setting( | |
'bhone_settings', | |
'bhone_settings', | |
'bhone_settings_sanitize' | |
); | |
add_settings_section( | |
'bhone_settings_section', | |
__( 'Bug Hunt One Settings' ), | |
'bhone_settings_output', | |
'bhone_settings_page' | |
); | |
add_settings_field( | |
'bhone_setting_example', | |
__( 'Bug Hunt One Example Setting' ), | |
'bhone_setting_example_output', | |
'bhone_settings_page', | |
'bhone_settings_section' | |
); | |
} | |
function bhone_settings_output() | |
{ | |
echo '<p>These are example settings for Bug Hunt One.</p>'; | |
} | |
function bhone_setting_example_output() | |
{ | |
$options = get_option( 'bhone_settings' ); | |
echo '<input name="bhone_settings[setting_example]" id="bhone_setting_example" type="checkbox" value="1" class="code" ' . checked( 1, $options["setting_example"], false ) . ' /> An example option for Bug Hunt One'; | |
} | |
function bhone_settings_sanitize( $input ) | |
{ | |
$options = get_option( 'bhone_settings' ); | |
$options['setting_example'] = trim( $input['setting_example'] ); | |
return $options; | |
} | |
add_action( 'admin_menu', 'bhone_add_menu' ); | |
add_action( 'admin_init', 'bhone_register_settings' ); |
@ManiSingh you don't have to put PHP closing tag in the end of the file http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html
Solution posted!
@ManiSingh ah I see what you mean, if you look at Line 32, that's where the missing closing tag is ;)
@johnnypea and @EnvatoWP thanks for clearing that up for me!
Line 18 still has spelling. Shouldn't it be 'bhone_settings'
better yet $options['setting_example'] = trim( intval( $input['setting_example'] ) );
@owldesign No, but I probably should've used a less ambiguous name for the menu slug there.
@paulruescher Yes! Great suggestion.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@EnvatoWP sorry I might be a bit of a noob right now lol but shouldn't each opening tag have a closing one? I count 4 <?php and only 3 closing tags.