WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Feb 21 2011

How to Write a Simple update_ms_option() Function for WordPress Multisite

For WordPress Multisite, I needed a function that worked like update_option(). So here's a simple one I wrote.

[php]function update_ms_option($blogID, $option_name, $option_value) {
global $wpdb;

$wpdb->query( $wpdb->prepare( "
INSERT INTO `".DB_NAME."`.`".$wpdb->get_blog_prefix($blogID)."options`
(
`option_id` ,
`blog_id` ,
`option_name` ,
`option_value` ,
`autoload`
)
VALUES (NULL, '0', '%s', '%s', 'yes')
ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = '%s', `autoload` = VALUES(`autoload`)",
array($option_name, $option_value, $option_value) ) );
[/php]

Written by Travis Smith · Categorized: Tutorials

Feb 18 2011

How to Write a Simple get_ms_option() That Reflects get_option() for WordPress Multisite

For WordPress Multisite, I needed a function that worked like get_option(). So here's a simple one I wrote.

[php]function get_ms_option($blogID, $option_name) {
global $wpdb;

$select_statement = "SELECT *
FROM `".DB_NAME."`.`".$wpdb->get_blog_prefix($blogID)."options`
WHERE `option_name` LIKE '".$option_name."'";
$sql = $wpdb->prepare($select_statement);
$option_value = $wpdb->get_results( $sql, ARRAY_A );
return $option_value[0]['option_value'];
}
[/php]

Another option is to use $wpdb->get_var (thanks to Kawauso from #WordPress IRC):
[php]function get_ms_option($blogID, $option_name) {
global $wpdb;

$select_statement = "SELECT *
FROM `".DB_NAME."`.`".$wpdb->get_blog_prefix($blogID)."options`
WHERE `option_name` LIKE '".$option_name."'";
$sql = $wpdb->prepare($select_statement);
$option_value = $wpdb->get_var( $sql, 3 );
return $option_value;
}
[/php]

Written by Travis Smith · Categorized: Tutorials

Feb 17 2011

How to Write a Simple get_ms_sites() Function

This will return an array of sites from WordPress Multisite.

Simple Version

[php]function get_ms_sites() {
global $wpdb;

$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
$query .= " ORDER BY {$wpdb->blogs}.blog_id ";
$order = "ASC";
$query .= $order;
$sql = $wpdb->prepare($query);
$blog_list = $wpdb->get_results( $sql, ARRAY_A );

return $blog_list;
}
[/php]

"Complicated Version"

[php]function get_ms_sites() {
global $wpdb;
$include_public_only = true; // 1 is public; 0 is private
$include_archived = false; // 1 is archived;0 is not
$include_mature = false; // 1 is mature;0 is not
$include_spam = false; // 1 is spam;0 is not
$include_deleted = false; // 1 is deleted;0 is not

$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
//Options
$query .= " AND {$wpdb->blogs}.public = ". (($include_public_only) ? "'1'" : "'0'");
$query .= " AND {$wpdb->blogs}.archived = ". (($include_archived) ? "'1'" : "'0'");
$query .= " AND {$wpdb->blogs}.mature = ". (($include_mature) ? "'1'" : "'0'");
$query .= " AND {$wpdb->blogs}.spam = ". (($include_spam) ? "'1'" : "'0'");
$query .= " AND {$wpdb->blogs}.deleted = ". (($include_deleted) ? "'1'" : "'0'");

//Query Order
$qorder = " ORDER BY {$wpdb->blogs}.blog_id "; //Next lines contain other options
//$qorder = " ORDER BY last_updated ";
//$qorder = " ORDER BY domain ";
$query .= $qorder;

//Order ASC = ascending; DESC = descending;
$order.= "ASC"; //can also be "DESC"
$query .= $order;
$sql = $wpdb->prepare($query);
$blog_list = $wpdb->get_results( $sql, ARRAY_A );

return $blog_list;
}[/php]

Written by Travis Smith · Categorized: Tutorials

Feb 10 2011

Permenantly Fix Genesis's Admin Metabox Widths

In the StudioPress Support Forum, Charles Clarkson helped me with a problem that I've had for some time now. I have wanted StudioPress to change their .genesis-metaboxes .metabox-holder from its default of 800px to auto on the Theme Settings under Genesis tab (http://yourdomain.com/wp-admin/admin.php?page=genesis).

Genesis Default (800px): Click Image for Larger Image

However, after every upgrade I had to edit the admin.css to make this happen.

My Preference (auto): Click Image for Larger Image

So finally I posted this in the forums and Charles gave me the following code to free me from remembering to do that. And here it is:

[php]
add_action( 'admin_footer', 'child_widen_theme_settings' );
function child_widen_theme_settings() { ?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
$( '.genesis-metaboxes, .genesis-metaboxes .metabox-holder' ).css( 'width', 'auto' );
//]]>
});
</script>
<?php
} [/php]

Written by Travis Smith · Categorized: Genesis

Feb 10 2011

Web Accessibility: Making Genesis Accessible

Recently, in the StudioPress forums, there was a conversation regarding Web Accessibility. Spiking my interest, I wondered how accessible Genesis was. If you were to run Genesis through the WAVE Web Accessibility Evaluation Tool as I did to StudioPress's Demo of Genesis (report here). There are three accessibility errors, and all three have to do with a missing label: search form (Genesis), enews and updates form (Genesis), and categories form (dropdown) (WordPress Core). While I am not sure if StudioPress will incorporate these label fixes into their core, they can be easily fixed.

Search Form

To fix the search form label, open search.php in your genesis > lib > structure folder. At line 18, change $form from
[php]$form = '
<form method="get" class="searchform" action="' . get_option('home') . '/" >
<input type="text" value="'. $search_text .'" name="s" class="s"'. $onfocus . $onblur .' />
<input type="submit" class="searchsubmit" value="'. $button_text .'" />
</form>
'; [/php]
to the following:
[php]$form = '
<form method="get" class="searchform" action="' . get_option('home') . '/" >
<label for="s" style="display:none;">Search</label>
<input type="text" value="'. $search_text .'" name="s" id="s" class="s"'. $onfocus . $onblur .' />
<input type="submit" class="searchsubmit" value="'. $button_text .'" />
</form>
'; //added <label for="s" style="display:none;">Search</label> to $form & id="s" [/php]

eNews and Updates Form

To fix the enews and updates form label, open enews-widget.php in your genesis > lib > widgets folder. At line 36, change the <form> from:
[php]<form id="subscribe" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo esc_js( $instance['id'] ); ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"><input type="text" value="<?php echo esc_attr( $instance['input_text'] ); ?>" id="subbox" onfocus="if (this.value == '<?php echo esc_js( $instance['input_text'] ); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo esc_js( $instance['input_text'] ); ?>';}" name="email"/><input type="hidden" value="<?php echo esc_attr( $instance['id'] ); ?>" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="<?php echo esc_attr( $instance['button_text'] ); ?>" id="subbutton" /></form>
<?php } [/php]
to the following:
[php]<form id="subscribe" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo esc_js( $instance['id'] ); ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"><label for="subbox" style="display:none;">enews</label><input type="text" value="<?php echo esc_attr( $instance['input_text'] ); ?>" id="subbox" onfocus="if (this.value == '<?php echo esc_js( $instance['input_text'] ); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo esc_js( $instance['input_text'] ); ?>';}" name="email"/><input type="hidden" value="<?php echo esc_attr( $instance['id'] ); ?>" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="<?php echo esc_attr( $instance['button_text'] ); ?>" id="subbutton" /></form>
<?php } //added <label for="subbox" style="display:none;">enews</label>[/php]

Dropdown Categories

The last error is actually a WordPress core accessibility "error" and has nothing to do with Genesis. First, this is a WordPress core file and edit this at your own risk and as always backup everything before you edit. If you open category-template.php in your wp-includes folder. So you want to edit line 334 as follows:
ORIGINAL:
[php]$output = "<label for='$id' style='display:none;'>$name</label><select name='$name' id='$id' class='$class' $tab_index_attribute>n"; //added <label for='$id' style='display:none;'>$name</label>[/php]
MODIFIED for Accessibility:
[php]$output = "<label for='$id' style='display:none;'>$name</label><select name='$name' id='$id' class='$class' $tab_index_attribute>n"; //added <label for='$id' style='display:none;'>$name</label>[/php]

Now, I need to suggest this at WordPress trac. Oh dear! DONE: Trac Ticket: http://core.trac.wordpress.org/ticket/16527

Written by Travis Smith · Categorized: WordPress

  • « Previous Page
  • 1
  • …
  • 54
  • 55
  • 56
  • 57
  • 58
  • …
  • 61
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in