WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

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

Feb 08 2011

How to Add a Custom Login/Logout Message in WordPress

In a previous post, How to Add a Custom Message on the Login or Register Screen, I talked about how to add a custom message to either the login screen or the register screen. Recently, I was asked how to create a custom message for logging out. Since WordPress uses the wp-login.php file to logout as well, then it isn't as simple as the last post.

So, to add a custom message to your logout screen, you need to add the following to your functions.php file.

[php]function custom_login_head() //outputs the CSS needed to blend custom-message with the normal message
{?>
<style type="text/css">
#login_error, .message { display:none; }
.custom-message {
-moz-border-radius:3px 3px 3px 3px;
border-style:solid;
border-width:1px;
margin:0 0 16px 8px;
padding:12px;
}
.login .custom-message {
background-color:#FFFFE0;
border-color:#E6DB55;
}
</STYLE><?php
}

add_action('login_head','custom_login_head');

function custom_logout_message() {
if ( isset($_GET['loggedout']) && TRUE == $_GET['loggedout'] ) //check to see if it's the logout screen
{
$message = "<p class='custom-message'>Custom logged out Message.</p><br />";
}
else //they are logged in
{
$message = "<p class='custom-message'>Custom Login Message.</p><br />";
}

return $message;
}
add_filter('login_message', 'custom_logout_message');[/php]

Written by Travis Smith · Categorized: Tutorials

  • « Previous Page
  • 1
  • …
  • 53
  • 54
  • 55
  • 56
  • 57
  • …
  • 60
  • Next Page »

Need Help?

Please let us know how we can help you!

Get Help

Recommendations

Genesis WordPress Framework
Sucuri Security
Gravity Forms
GetSoliloquy
Get Envira
Scribe SEO
BackupBuddy
WordPress Video User Manuals

Recent Posts

  • Solving WordPress 5XX Server Errors on SiteGround
  • Hiding an User in the WordPress Admin
  • Custom Rewrite Rules for Custom Post Types and Taxonomies
  • WordPress JavaScript Manager Native Functions
  • Causes of WordPress Site Performance Slowdown

About Travis

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

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