Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Bug Hunt One [SOLVED]
<?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' );
@jahvi

This comment has been minimized.

Show comment Hide comment
@jahvi

jahvi Jan 9, 2012

options.pip in form action?

jahvi commented Jan 9, 2012

options.pip in form action?

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 9, 2012

Hey, nicely spotted!
You can also create a "fork" of the Gist and do your bug fixes on it and link to a bug-free version when you're done :)

Owner

EnvatoWP commented Jan 9, 2012

Hey, nicely spotted!
You can also create a "fork" of the Gist and do your bug fixes on it and link to a bug-free version when you're done :)

@twhitacre

This comment has been minimized.

Show comment Hide comment
@twhitacre

twhitacre Jan 9, 2012

If I have time later, I'll fork it and get a corrected version, but right at first glance....

Line 32 - missing closing '?>'
Line 63 - missing ','
Line 86 - missing ';'

Those are trivial mistakes and from reading through it the plugin isn't' going to actually do much other than create a link in the plugins menu and go to a blank page. I wish I had more time to spend playing around with it.

If I have time later, I'll fork it and get a corrected version, but right at first glance....

Line 32 - missing closing '?>'
Line 63 - missing ','
Line 86 - missing ';'

Those are trivial mistakes and from reading through it the plugin isn't' going to actually do much other than create a link in the plugins menu and go to a blank page. I wish I had more time to spend playing around with it.

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 9, 2012

Great! Most of the mistakes are trivial ones. It doesn't go to a blank page exactly, but you're right, it doesn't do much :)

Owner

EnvatoWP commented Jan 9, 2012

Great! Most of the mistakes are trivial ones. It doesn't go to a blank page exactly, but you're right, it doesn't do much :)

@gchp

This comment has been minimized.

Show comment Hide comment
@gchp

gchp Jan 9, 2012

line #36 - type="sumit" should be type="submit"

gchp commented Jan 9, 2012

line #36 - type="sumit" should be type="submit"

@pippinsplugins

This comment has been minimized.

Show comment Hide comment
@pippinsplugins

pippinsplugins Jan 10, 2012

Line 14 - "add_plugins_page" should be "add_options_page"

Line 14 - "add_plugins_page" should be "add_options_page"

@pippinsplugins

This comment has been minimized.

Show comment Hide comment
@pippinsplugins

pippinsplugins Jan 10, 2012

Line 70 should be

echo '<p>These are example settings for Bug Hunt One.</p>';

Line 70 should be

echo '<p>These are example settings for Bug Hunt One.</p>';

@pippinsplugins

This comment has been minimized.

Show comment Hide comment
@pippinsplugins

pippinsplugins Jan 10, 2012

Line 87 is missing an "s" at the end of bhone_register_setting

Line 87 is missing an "s" at the end of bhone_register_setting

@owldesign

This comment has been minimized.

Show comment Hide comment
@owldesign

owldesign Jan 10, 2012

line 87 needs to be "settings". The function has an "s" at the end

line 87 needs to be "settings". The function has an "s" at the end

@ManiSingh

This comment has been minimized.

Show comment Hide comment
@ManiSingh

ManiSingh Jan 10, 2012

Line 18 - 'bhone-settings', should read 'bhone_settings',

Line 18 - 'bhone-settings', should read 'bhone_settings',

@contrastlogic

This comment has been minimized.

Show comment Hide comment
@contrastlogic

contrastlogic Jan 10, 2012

Line 76 should be:

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';

Real simple, missing 2 single quotes

Line 76 should be:

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';

Real simple, missing 2 single quotes

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 10, 2012

Nearly there! Only 2 bugs left that haven't been mentioned yet.

@mordauk: Unless I'm mistaken Line 14 isn't a bug: http://codex.wordpress.org/Function_Reference/add_plugins_page
Nice spotting on the rest though! :)

Owner

EnvatoWP commented Jan 10, 2012

Nearly there! Only 2 bugs left that haven't been mentioned yet.

@mordauk: Unless I'm mistaken Line 14 isn't a bug: http://codex.wordpress.org/Function_Reference/add_plugins_page
Nice spotting on the rest though! :)

@paulruescher

This comment has been minimized.

Show comment Hide comment
@paulruescher

paulruescher Jan 10, 2012

icon-options-general, not icon-options-generale

icon-options-general, not icon-options-generale

@pippinsplugins

This comment has been minimized.

Show comment Hide comment
@pippinsplugins

pippinsplugins Jan 10, 2012

@EnvatoWP - oh shoot, you're right. I wasn't sure there was an add_plugins_page(), and I did find it in the codex (somehow?), so I thought it was a bug :P

@EnvatoWP - oh shoot, you're right. I wasn't sure there was an add_plugins_page(), and I did find it in the codex (somehow?), so I thought it was a bug :P

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 10, 2012

@mordauk ;)

And thanks @paulruescher, that leaves one bug left!

Owner

EnvatoWP commented Jan 10, 2012

@mordauk ;)

And thanks @paulruescher, that leaves one bug left!

@contrastlogic

This comment has been minimized.

Show comment Hide comment
@contrastlogic

contrastlogic Jan 10, 2012

Line 2: the docBlock should start with /**, no?
Not really a bug, per se...

Line 2: the docBlock should start with /**, no?
Not really a bug, per se...

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 10, 2012

@contrastlogic Convention says you're correct there, but no, that's not the last bug.

Owner

EnvatoWP commented Jan 10, 2012

@contrastlogic Convention says you're correct there, but no, that's not the last bug.

@ManiSingh

This comment has been minimized.

Show comment Hide comment
@ManiSingh

ManiSingh Jan 10, 2012

Line 41: has a random <?php there lol

Line 41: has a random <?php there lol

@johnnypea

This comment has been minimized.

Show comment Hide comment
@johnnypea

johnnypea Jan 10, 2012

Line 82: "trim( $input['setting_example'] );" NOT "trim( $options['setting_example'] );" ;)

Line 82: "trim( $input['setting_example'] );" NOT "trim( $options['setting_example'] );" ;)

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 10, 2012

Done! Thanks, @johnnypea

@ManiSingh that's not so random, it breaks out on Line 25 :)

Owner

EnvatoWP commented Jan 10, 2012

Done! Thanks, @johnnypea

@ManiSingh that's not so random, it breaks out on Line 25 :)

@owldesign

This comment has been minimized.

Show comment Hide comment
@paulruescher

This comment has been minimized.

Show comment Hide comment
@paulruescher

paulruescher Jan 10, 2012

$options['setting_example'] = trim( isset( $input['setting_example'] ) );

$options['setting_example'] = trim( isset( $input['setting_example'] ) );

@ManiSingh

This comment has been minimized.

Show comment Hide comment
@ManiSingh

ManiSingh Jan 10, 2012

@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.

@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.

@johnnypea

This comment has been minimized.

Show comment Hide comment
@johnnypea

johnnypea Jan 10, 2012

@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

@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

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 10, 2012

Solution posted!

@ManiSingh ah I see what you mean, if you look at Line 32, that's where the missing closing tag is ;)

Owner

EnvatoWP commented Jan 10, 2012

Solution posted!

@ManiSingh ah I see what you mean, if you look at Line 32, that's where the missing closing tag is ;)

@ManiSingh

This comment has been minimized.

Show comment Hide comment
@ManiSingh

ManiSingh Jan 10, 2012

@johnnypea and @EnvatoWP thanks for clearing that up for me!

@johnnypea and @EnvatoWP thanks for clearing that up for me!

@owldesign

This comment has been minimized.

Show comment Hide comment
@owldesign

owldesign Jan 10, 2012

Line 18 still has spelling. Shouldn't it be 'bhone_settings'

Line 18 still has spelling. Shouldn't it be 'bhone_settings'

@paulruescher

This comment has been minimized.

Show comment Hide comment
@paulruescher

paulruescher Jan 10, 2012

better yet $options['setting_example'] = trim( intval( $input['setting_example'] ) );

better yet $options['setting_example'] = trim( intval( $input['setting_example'] ) );

@EnvatoWP

This comment has been minimized.

Show comment Hide comment
@EnvatoWP

EnvatoWP Jan 10, 2012

@owldesign No, but I probably should've used a less ambiguous name for the menu slug there.

@paulruescher Yes! Great suggestion.

Owner

EnvatoWP commented Jan 10, 2012

@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