Category Archives: Wordpress

Redirect url to a page after importing posts

After importing posts from one WordPress site to another, you need to set the htaccess file to direct the pages and images. Here’s what I used:

The old site where I exported posts is easterniowasportsandrec.com. I created a new page that will be a section page for these posts at http://thegazette.com/sports/more/. So I need to redirect the old homepage, the old stories and the images. I added these three rules to the htaccess file on easterniowasportsandrec.com.

# redirect old homepage to new page
RewriteCond %{HTTP_HOST} ^easterniowasportsandrec.com$ [NC]
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule ^(.*)$ http://thegazette.com/sports/more/ [L,R=301]

# redirect files from old site /files/ to new site /wp-content/uploads/
RewriteCond %{HTTP_HOST} ^easterniowasportsandrec.com$ [NC]
RewriteRule ^(.*/)?files/(.*)$ http://thegazette.com/wp-content/uploads/$2 [R=301,L]

# redirect every other page to match the post’s permalink on new site
RewriteCond %{HTTP_HOST} ^easterniowasportsandrec.com$ [NC]
RewriteRule ^(.*)$ http://thegazette.com/$1 [L,R=301]

These are the example redirects:
redirect the homepage to a page
http://easterniowasportsandrec.com/

redirect an image
http://easterniowasportsandrec.com/files/2012/01/Iowa-vs.-Norhtwestern131-128×128.jpg

redirect a story
http://easterniowasportsandrec.com/2011/10/16/feels-like-spring-as-kernels-hold-pa-on-field-tryouts/

Adding or Removing Profile Fields


function my_contactmethods( $contactmethods ) {

	// add
	$contactmethods['twitter'] = 'Twitter';
	$contactmethods['facebook'] = 'Facebook';
	$contactmethods['blog'] = 'Blog';
	
	// remove
	unset($contactmethods['aim']);
	unset($contactmethods['jabber']);
	unset($contactmethods['yim']);

	return $contactmethods;
}
add_filter('user_contactmethods','my_contactmethods',10,1);

Adding a meta_box to all Post Types

$post_types = get_post_types( array( '_builtin' => false ), 'objects' );  // Gets all custom types
       array_push( $post_types, get_post_type_object( 'post' ), get_post_type_object( 'page')  ); // Adds back the 'post' and 'page' types while ommitting attachments, revisions, menus, etc.
       foreach ( $post_types as $type ) {
               add_meta_box( . . . );
       }

WP-o-Matic breaks WordPress Related Links

function adminInit() {
		auth_redirect();

		// force display of a certain section
		$this->section = ($this->setup) ? ((isset($_REQUEST['s']) && $_REQUEST['s']) ? $_REQUEST['s'] : $this->sections[0]) : 'setup';
		
//    if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
//      die('Please switch to Firefox / Safari');

		wp_enqueue_script('prototype');
		wp_enqueue_script('wpoadmin', $this->tplpath . '/admin.js', array('prototype'), $this->version);

		if ($this->section == 'list')
			wp_enqueue_script('listman');

		//if ( WPOTools::isAjax() ) {
		if ( WPOTools::isAjax() &&  $this->section != 'home' ) { // Matt Thiessen 11/8/11
			$this->admin();
			exit;
		}
	}

SlidePress Plugin Redirect Bug

When clicking on settings links for the SlidePress plugin in a multi-user WordPress site the plugin would redirect to /wp-admin/?c=1 for each domain except the parent site.

[code lang=”php”]function get_current_user_role() {
global $current_user, $wp_roles;
$role_names = $wp_roles -> get_names();
/* UPDATED 11/2/2010 9:21 AM
* by matt.thiessen@sourcemedia.net
*/
// modified [start]
reset($current_user->roles);
$first_key = key($current_user->roles);
return preg_replace( “/\|.*/”, ”, $role_names[$current_user->roles[$first_key]]);
/*old*///return preg_replace( “/\|.*/”, ”, $role_names[$current_user->roles[0]]);
// modified [end]
}[\code]

Also, make sure if you are an admin user with super user privileges you are added at a admin user to the site you are using the SlidePress plugin.

This will add proper capabilities to the database in the wp_usermeta table.
meta_key: wp_25_capabilities
meta_value: a:1:{s:13:”administrator”;s:1:”1″;}