WordPress Pretty URL Sorting by Date

I don’t know how to title this post properly, so I am just going to try and explain it and see if then I can have a good title. I wanted to be able to sort custom post types by the url and have it look pretty. I wanted it to look like:

http://www.com/customposttype/date/asc/

I know how to do:

http://www.com/customposttype/?sortby=date&direction=asc

The key is that I wanted it to be clean looking and now that I found out that it is relatively simple. I am going to be using this more and maybe make a plugin for it. I am just wondering out loud if this is already built into WordPress and I am being dumb (which I hope is the case, because I will really use this more and more in the sites that I make).

This goes into functions.php:

in my example above I am using the page “art” which uses a custom template. So when the URL http://youawake.com/art/date/desc/ gets called.

Now within the custom page template ART, I just need to call the variable that gets displayed and then sort it within the query, the example.

If there is no date sort it just displays it by default order.

You can see my two examples at:
http://youawake.com/art/date/desc/

http://youawake.com/art/date/asc/

Posted in PHP, Wordpress | Tagged , , , , | Leave a comment

Single Serving WordPress Theme

I just bought a domain today doineedtoseeitin3d.com and I was sad to see that there are no single serving WordPress themes. So, I went ahead and made it obviously. This is my second attempt at doing a Single Serving Site. But now that I have a WordPress theme for it, I think I will make more.

Download
Demo with random posts setting

Posted in Theme, Wordpress | Leave a comment

Simple Comment Spam Stopper

This is from Another Approach at Comment Spam, I couldn’t wait for a plugin to be made, So I just made it myself.

All this does it add is a hidden field to the comment form, spam. And if anything gets put into there it gets marked as spam. Simple as that. I was getting some spam on my WordPress sites that I had to do something more about it. I did not want to upload it to the WordPress plugin directory because it wasn’t my idea.

Download

Posted in PHP, Wordpress | Tagged , , | Leave a comment

WordPress Instant Search

I have been getting a lot of requests lately to do an Instant Search type thing for a couple of my sites. I wasn’t really into it, and I am still not into it. I have had trouble lately with searching, on how to do it properly. But this sparked my interest in search and have now found a great solution. Apparently RLIKE is way better to use than LIKE in your mysql query. Also, you need to do an array to search for two words if two words are present and on and on. But anyways, this tutorial, How-To Create Your Own Instant Search sparked my interest for some reason into looking into it again. It is basically an Instant google/facebook type search. I had a lot of trouble with the code but, took me an hour or so to figure it out. You can see an example at Obey Giant Search. It is awful and doesn’t work very well, but it is just for fun.

Download: instant-search.zip

I am not going to get into how this works, or anything like that. This is a complete file that will work when everything gets changed. It is for wordPress specifically, but can be used in other ways.

Posted in PHP, Wordpress | Tagged , , , | 1 Comment

Make Network WordPress Private Site Wide

I am creating an Intranet wordPress site for the company that I work for. It has different sections for each part of the company. When you login to the site it will show you everything that you have access to, Graphs, Charts, Personal To Do’s. This is all using WordPress Multi Network, and it is slowly coming along and now I wanted to make it private. This is a two fold thing, We want you to be logged in to view whats going on, and we don’t want any outsiders seeing what we are doing. I could put this on a computer her in the office and host it internally, but thats no fun, We have a lot of satellite working and are often working off our devices. So thats why i made it possible to access anywhere.

Anyways, We wanted to make it so you had to login to be able to see anything. Essentially making it private. Luckily there is already a plugin out there and it is very small, and works magical to our needs, Private WP. But then I have to add it to every blog we have and activate it. But thankfully wordPress is smart and made a mu-plugins folder in wp-content. Whatever plugin you add in there gets activated and added to every blog in your install.
Make Network WordPress Private Site Wide

All you have to do is download the plugin and upload it to that folder and it is activated site wide.

This is the plugin, which is exactly how I would have done it.


function private_wp() {
if (!is_user_logged_in()) {
auth_redirect();
}
}

add_action('get_header', 'private_wp');

Posted in Wordpress | Leave a comment

Code Injection

So, I found out this weekend that I got all my sites injected with code. I tried deleting it and it just wouldn’t go away. It had injected itself into every plugin in the plugin folder. I tried removing the code, but it was still showing up in the footer of my theme. So, I just tried to do some more detective work on how to remove it. Thank god for google, I found the answer at stack overflow which is a great resource for doing this sort of thing. I found a code that scans files and looks for the code injection if it uses base64 injection. Anyways, since i have multiple domains in my host i changed one thing.

This script will clean the malware from this attack:

$dir = "./";

$rmcode = `find $dir -name "*.php" -type f |xargs sed -i 's###g' 2>&1`;
echo "Malware removed.
\n";
$emptyline = `find $dir -name "*.php" -type f | xargs sed -i '/./,$!d' 2>&1`;
echo "Empty lines removed.
\n";
?>

Completed.

If you upload this to the root of your website and open it up in the browser it will do as it says. I changed the $dir = “./”; to $dir = “./../”; so it went through all my websites at the same time. Took about 30 seconds or so. And it removed the injection from all my sites. Great

Posted in PHP | Tagged , , | 1 Comment

Disable New User Email Notifications

This plugin will disable emails about new users who register on your blog. It is a very simple plugin that just changes what happens when new users registers.

You can download this plugin here.

I am going to be submitting this plugin to the repository, I don’t suspect any updates to this anytime soon. But if there are, it will be there.


/*
Plugin Name: Disable new user email notifications
Plugin URI: http://www.tipsforwordpress.com
Description: Disables email notifications of new users registered on your blog
Author URI: http://westondeboer.com
Version: 1.0
*/

if ( !function_exists('wp_new_user_notification') ) :
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = new WP_User($user_id);

$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);

// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

if ( empty($plaintext_pass) )
return;

$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
$message .= wp_login_url() . "\r\n";

wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);

}
endif;
?>

With this plugin, I have learned so much about pluggable.php and am so excited about it! Things I didn’t know before.

Posted in Wordpress | Tagged , , , , | 1 Comment

Custom Post Types in WordPress 3.0


This has been something that I have been looking forward to for a very long time. With these options, wordpress mu and buddypress, WordPress is really a cms/blogging software to be reckoned with.

Clients get confused when you install wordpress as a cms for them and they see add a new post, they always get confused with that. With this new feature where it says add a new client, or add new business. Clients will be able to understand easily what they need to do. This will also add the ability to organize much easier within categories and categories within categories.

To add a custom post type in wordpress 3.0 this would go into either a plugin or the functions.php file in your theme directory:


// This function is where the magic happens
function post_type_gallery() {

// this is where we say the post type
register_post_type( 'gallery',

// This section tells wordpress what to show when they go to add Gallery. This will only show the subject box, the body box and the publish box.
array( 'label' => __('Gallery'), 'public' => true, 'show_ui' => true) ) );
}

// This action shows the above function in the WordPress Dashboard
add_action('init', 'post_type_gallery');

With that you will have a custom post screen, Way easier than it was before! Everything posted in this gallery section will also only appear in the gallery edit posts section. It should look this this below:

Next will be how to add a custom field to this custom post. It is the same way as before, just a little bit of added code into the register_post_type.

WP Engineer goes a little more in detail about custom post types. More in detail about how to display certain boxes and what not. Definitely worth a read.

Posted in Wordpress | Tagged , , , , | 5 Comments

Add Link to Favorites Drop Down

I saw a post today about making a quick action button always there that required you to edit the core wordpress files. This made me cringe a little bit, I have only had to do this once for a wordpress install. And I always forget when I upgrade and the site gets borked. So I decided to steal a function from wp cache that does this exact same thing.

I have no uses for this as I can navigate to any area that I want to, pretty easily. Just putting it out there for other plugin/theme developers.


function my_favorite_action( $actions ) {

$actions[ wp_nonce_url( 'edit-comments.php', 'wp-cache' ) ] = array( __( 'Manage Comments' ), 'manage_options' );

return $actions;
}
add_filter( 'favorite_actions', 'my_favorite_action' );

The only section that you need to edit is the edit-comments.php, and just point that to where you want the link to go. And the Manage Comments will be the text that is displayed.

Posted in Wordpress | Tagged , , , | 2 Comments

WordCamp San Francisco May 1st, 2010

Just bought two WordCamp San Francisco tickets. I have never been to anything like this before and don’t know what to expect. There aren’t any speakers yet, but it will be interesting to meet some WordPress folk. There are already some 194 attendees which is impressive. I don’t really know anyone on the list except for ma.tt, But I would be interested in talking with some theme developers. I really like studiopress and would be interested in chatting them up.

Anyways May 1st is a long way away.

Posted in Wordpress | Tagged , | Leave a comment