Skip to content

Instantly share code, notes, and snippets.

View cmcculloh's full-sized avatar

Christopher McCulloh cmcculloh

View GitHub Profile
@cmcculloh
cmcculloh / wpphpbbbridgefix
Created December 30, 2011 04:35
Fix for WP phpBB Bridge Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in wpbb_topics_widget.php on line 149
//all of this replaces line 147 (NOT 149!!)
$db_conn_uri = $dbhost;
if(isset($dbport) && !empty($dbport)){
$db_conn_uri .= ":" . $dbport;//could be improved by adding a check to make sure that $dbport doesn't start with ":" before tagging that on for them
}
$cn = @mysql_pconnect($db_conn_uri, $dbuser, $dbpasswd);
@cmcculloh
cmcculloh / gist:1387990
Created November 23, 2011 05:58
register fields
//you can have as many of these as you want...
your_prefix_register_field('field_id', 'field label', 'dashboard page', 'section_id', array('callback', 'params', 'can', 'go', 'here'));
your_prefix_register_field('field_id2', 'field label', 'dashboard page', 'section_id');
your_prefix_register_field('field_id3', 'field label', 'dashboard page', 'section_id');
your_prefix_register_field('field_ida', 'field label', 'dashboard page', 'section_id');
your_prefix_register_field('field_idz', 'field label', 'dashboard page', 'section_id');
@cmcculloh
cmcculloh / gist:1387988
Created November 23, 2011 05:57
register section
con_register_section('section_id', 'Visible Name To User');
@cmcculloh
cmcculloh / gist:1387983
Created November 23, 2011 05:55
global callback
function your_global_callback($field){
$selected = get_option($field["id"]);
if($field["type"] == "text"){
?>
<input type="text" name="<?php echo $field["id"]; ?>" id="<?php echo $field["id"]; ?>" value="<?php echo $selected ?>">
<?php
}else if($field["type"] == "checkbox"){
if($selected){
$selText = ' checked="checked" ';
@cmcculloh
cmcculloh / gist:1387981
Created November 23, 2011 05:55
register field
function your_prefix_register_field($id, $name, $section, $type, $filter = NULL){
add_settings_field($id,
$name,
"your_global_callback",
'media',
'your_prefix_' . $section,
array("id" => $id,
"name" => $name,
"type" => $type)
);
@cmcculloh
cmcculloh / gist:1387980
Created November 23, 2011 05:53
section callback
function your_prefix_your_section_callback_function(){
settings_fields('your_settings_group');//make hidden fields print out in form
echo "<p>Stuff for the user here</p>";
}
@cmcculloh
cmcculloh / gist:1387976
Created November 23, 2011 05:53
add section
function con_register_section($section, $title){
add_settings_section('your_prefix_' . $section,
$title,
'your_prefix_'.$section.'_callback_function',
'dashboard page');
}
@cmcculloh
cmcculloh / gist:1387974
Created November 23, 2011 05:52
init function
function your_init_function(){
//you will add stuff here later
}
@cmcculloh
cmcculloh / gist:1387972
Created November 23, 2011 05:52
add action
add_action('admin_init', 'your_init_function');
@cmcculloh
cmcculloh / full_example.php
Created November 23, 2011 05:50
Full Example
$thumb_sizes = array(
'breaking' => array( 'breaking', 80, 80, true ),
'slider1' => array( 'slider1', 390, 280, true ),
'slider1-wide' => array( 'slider1-wide', 450, 320, true ),
'slider1-thumbnail' => array( 'slider1-thumbnail', 120, 72, true ),
'slider2' => array( 'slider2', 710, 385, true ),
'slider2-wide' => array( 'slider2-wide', 880, 385, true ),
'slider3' => array( 'slider3', 455, 430, true ),
'slider3-wide' => array( 'slider3-wide', 630, 430, true ),