WordPress.org

Codex

User:MichaelH/MyPlugins

Contents

Use Parent Category Template

Save this code to a file called use_parent_category_template.php in the wp-content/plugins folder and activate the plugin. See also related plugins:

And see this post: http://brassblogs.com/blog/making-child-categories-recognize-parent-displays

<?php
/*
Plugin Name: Use Parent Category Template
Plugin URI: http://wordpress.org/support/topic/234874
Description: 
Author: MichaelH modified original from Mark Jaquith
Version: 0.0
Author URI: 
*/

/* GPL goes here */
/* Plugin uses parent category template for child category.  Doesn't work for child of child categories.  */

function use_parent_category_template() {

    if ( !is_category() || is_404() ) return; // we only care about category views

    $cat = get_query_var('cat');
    $category = get_category ($cat);
      
    if ( !($category) ) return; // no category with which to work

        if ( file_exists(TEMPLATEPATH . '/category-' . $category->cat_ID . '.php') ) {
            include(TEMPLATEPATH . '/category-' . $category ->cat_ID . '.php');
            exit; }
        elseif ( file_exists(TEMPLATEPATH . '/category-' . $category->category_parent . '.php') ) {
            include(TEMPLATEPATH . '/category-' . $category->category_parent . '.php');
            exit; }
}
add_action('template_redirect', 'use_parent_category_template');
?>

ChangeRegister

Save this code to file called saveregister.php in the wp-content/plugins folder and activate the plugin.

<?php
/*
Plugin Name: ChangeRegister
Plugin URI: http://wordpress.org/support/topic/23058
Description: change the text Register to Login for the wp_register function
Version: 1.0
Author: MichaelH
Author URI: http://codex.wordpress.org/User:MichaelH

*/

add_filter('register', 'change_register');
function change_register($link) {
$link = str_replace("Register", "Signup", $link);
return $link;
}
?>

Dashboard: Pages Recently Updated

Save this code to file called dashboard-pages-recently-updated.php in the wp-content/plugins folder and activate the plugin.

 
<?php 
/*
Plugin Name:  Dashboard: Pages Recently Updated
Plugin URI:   http://codex.wordpress.org/User:MichaelH/MyPlugins 
Description:  Displays recently updated pages on your WordPress 2.7+ dashboard.
Version:      2.1
Author:       modified for Recent Pages by MichaelH orginally by Ricardo González Castro http://rick.jinlabs.com/code/ 
Author URI:   http://codex.wordpress.org/User:MichaelH/MyPlugins
*/

/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
The license is also available at http://www.gnu.org/copyleft/gpl.html
*/


// Load up the localization file if we're using WordPress in a different language
// Place it in this plugin's folder and name it "dashboard-recent-pages-updated-[value in wp-config].mo"
load_plugin_textdomain( 'dashboard-recent-pages-updated', '/wp-content/plugins/dashboard-recent-pages-updated' );


	function DashboardRecentPagesUpdated() {

	// Add the widget to the dashboard
  
  global $wpdb;
  
  $widget_options = DashboardRecentPagesUpdated_Options();
	
  $request = "SELECT $wpdb->posts.*, display_name as name FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->posts.post_author=$wpdb->users.ID WHERE post_status IN ('publish') AND post_type ='page' ";
	$request .= "ORDER BY post_modified DESC LIMIT ".$widget_options['items'];
	$posts = $wpdb->get_results($request);	

		if ( $posts ) {
			echo "				<ul id='dashboard-recent-pages-updated-list'>\n";

			foreach ( $posts as $post ) {
				$post_meta = sprintf('%s', '<a href="post.php?action=edit&post=' . $post->ID . '">' . get_the_title($post->ID) . '</a> ' );

        if($widget_options['showauthor']) {				
          $post_meta.= sprintf( __('by %s', 'dashboard-recent-pages-updated'),'<strong>'. $post->name .'</strong> ' );
          }
          				
        if($widget_options['showtime']) {				
          $time = get_post_modified_time('G', true);

          if ( ( abs(time() - $time) ) < 86400 )
            $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
          else
            $h_time = mysql2date(__('Y/m/d H:i:s'), $post->post_modified);


          $post_meta.= sprintf( __('— %s', 'dashboard-recent-pages-updated'),'<abbr title="' . get_post_modified_time(__('Y/m/d H:i:s')) . '">' . $h_time . '</abbr>' );
          }
          
?>
					<li class='post-meta'>
						<?php echo $post_meta; ?>
					</li>
<?php
			}

			echo "				</ul>\n";
		} else {
				echo '				<p>' . __( "Sorry! You don't have any pages in your database!", 'dashboard-recent-pages-updated' ) . "</p>\n";
		}

}


function DashboardRecentPagesUpdated_Init() {
	wp_add_dashboard_widget( 'DashboardRecentPagesUpdated', __( 'Dashboard: Pages Recently Updated' ), 'DashboardRecentPagesUpdated', 'DashboardRecentPagesUpdated_Setup');
}

function DashboardRecentPagesUpdated_Options() {
	$defaults = array( 'items' => 5, 'showtime' => 1, 'showauthor' => 1);
	if ( ( !$options = get_option( 'DashboardRecentPagesUpdated' ) ) || !is_array($options) )
		$options = array();
	return array_merge( $defaults, $options );
}



function DashboardRecentPagesUpdated_Setup() {

	$options = DashboardRecentPagesUpdated_Options();


	if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) && isset( $_POST['widget_id'] ) && 'DashboardRecentPagesUpdated' == $_POST['widget_id'] ) {
		foreach ( array( 'items', 'showtime', 'showauthor' ) as $key )
				$options[$key] = $_POST[$key];
		update_option( 'DashboardRecentPagesUpdated', $options );
	}
		
?>
	<p>
		<label for="items"><?php _e('How many recently updated pages would you like to display?', 'dashboard-recent-pages-updated' ); ?>
			<select id="items" name="items">
				<?php
					for ( $i = 5; $i <= 20; $i = $i + 1 )
						echo "<option value='$i'" . ( $options['items'] == $i ? " selected='selected'" : '' ) . ">$i</option>";
				?>
			</select>
		</label>
	</p>

   <p>
		<label for="showauthor">
			<input id="showauthor" name="showauthor" type="checkbox" value="1"<?php if ( 1 == $options['showauthor'] ) echo ' checked="checked"'; ?> />
			<?php _e('Show page author?', 'dashboard-recent-pages-updated' ); ?>
		</label>
	</p>
	
   <p>
		<label for="showtime">
			<input id="showtime" name="showtime" type="checkbox" value="1"<?php if ( 1 == $options['showtime'] ) echo ' checked="checked"'; ?> />
			<?php _e('Show page modified date/time?', 'dashboard-recent-pages-updated' ); ?>
		</label>
	</p>
	
<?php
	}


/**
 * use hook, to integrate new widget
 */
add_action('wp_dashboard_setup', 'DashboardRecentPagesUpdated_Init');
?>

Echo Query

Don't remember where this plugin came from but putting it here. Save to wp-content/plugins folder as echo-query.php and activate. Visit the blog page where the query you want to dissect is used, then view source and look at the bottom of the source for the query.

<?php /*
Plugin Name: Echo Query
Version: 0.1
Description: Prints the posts query in an html comment
*/

//No rights reserved. :-)

function get_query($query) { //set the database query as a global variable
	global $query_comment;
    $query_comment = $query;
	return $query;
}

function echo_query() { //print it into the footer
	global $query_comment;
	echo "<!-- {$query_comment} -->";
}

add_filter('posts_request', 'get_query');
add_action('wp_footer', 'echo_query');

?>

Custom Login Message (for a theme's function.php)

Beginning with Version 2.8 can use this to present a message on the login screen. Just put this code in your theme's function.php file.

function custom_login_message() { 
$message = "Welcome to my blog, you need to be registered to see content";
return $message;
}
add_filter('login_message', 'custom_login_message');

Edit your pages and posts only

Also see: http://code.mincus.com/41/manage-your-posts-only-in-wordpress/ for a variation

<?php
/*
Plugin Name: Edit only Your Posts and Pages
Version: 1.0
Plugin URI: http://wordpress.org/support/topic/287591?replies=24#post-1214104
Description: Only show pages for current user in edit posts/pages
Author: t31os_  
Author URI: http://wordpress.org/support/topic/287591?replies=24#post-1214104
*/

function posts_for_current_author($query) {

	if( is_admin() ) {

		global $user_ID;
		$query->set('author',  $user_ID);
	}
	return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
?>

Set Post Order In Admin

<?php
/*
Plugin Name: Set Post Order In Admin
Version: 0.1
Plugin URI: http://wordpress.org/support/topic/336715/
Description: In Posts->Edit, display posts in title order.
Author: MichaelH
Author URI: http://codex.wordpress.org/User:MichaelH/MyPlugins
*/
//this will also work for pages

function set_post_order_in_admin( $wp_query ) {
  if ( is_admin() ) {
    $wp_query->set( 'orderby', 'title' );  // can use any query_posts orderby argument here
    $wp_query->set( 'order', 'ASC' );
  }
}
add_filter('pre_get_posts', 'set_post_order_in_admin' );
?>