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 , , | Leave a 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 , , , | 1 Comment

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

Using Custom Fields in Comments

For a private wordpress site I have been using a custom comments table. It just has an added row where people rate the business. Everything is included in the comments table where I don’t need to make a custom table for the ip address, the name, blah blah blah. So now with wordpress 2.9 they have added custom fields for comments so this eliminates the use of me having to do this, YAAAA!

Using custom fields for comments is just like using custom fields for wordpress.

So instead of using: update_post_meta('postid', 'customfield', 'customfieldvalue');

We now use: update_comment_meta('postid', 'customfield', 'customfieldvalue');

So in your plugin or functions.php file you can just do this:

add_action('comment_post','comment_rating');
function comment_rating($comment_id) {
global $wpdb, $user_identity, $user_ID;
$star = $_POST['rating'];
update_comment_meta('postid', 'rating', $star);
}

Again you need to add a rating drop down in your comments.php file (example): <input type=”radio” name=”rating” id=”vote1″ value=”1″ />

Posted in PHP, Wordpress | 3 Comments

Removing first image from the_content

I recently had a client want to put the_title below the first image. Without making it to complicated by adding custom fields or anything like that. I thought that I could grab the first image from the content with catch_that_image and then display the title and then display the_content. But if I did it that way, it would display the first image twice. So I had to come up with a way to remove the first image from the_content here comes filters!

// This is the filter that gets added to the content
add_filter( 'the_content', 'remove_first_image' );

// This is the function name
function remove_first_image($content) {
global $post, $posts;

// This is the pre replace that removes the first image
$content = preg_replace('//i',$matches,$post->post_content,1);
return $content;
}

You can see a working example at Barack Obama. The first image is called via catch_that_image and then the_title is displayed and then the_content after that.

This way Casey just keeps doing what he is doing without having to change any of the posts around that he already has done.

Posted in Wordpress | Tagged , , , | 4 Comments

Add Custom Field to Register Form

this is gonna be a quick one, cause I need to finish website. But I got this working today. This is for function.php file or in a plugin will work. This will add two forms to the register page in your wordpress, First Name and Last Name.

add_action(‘register_form’,'show_first_name_field’);
add_action(‘register_post’,'check_fields’,10,3);
add_action(‘user_register’, ‘register_extra_fields’);

function show_first_name_field(){
?>
<p>
<label>First Name<br/>
<input id=”user_email” type=”text” tabindex=”20″ size=”25″ value=”<?php echo $_POST['first']; ?>” name=”first”/>
</label>
</p>
<p>
<label>Last Name<br/>
<input id=”user_email” type=”text” tabindex=”20″ size=”25″ value=”<?php echo $_POST['last']; ?>” name=”last”/>
</label>
</p>
<?php
}

function check_fields($login, $email, $errors) {
global $firstname, $lastname;
if ($_POST['first'] == ”) {
$errors->add(‘empty_realname’, “<strong>ERROR</strong>: Please Enter in First Name”);
} else {
$firstname = $_POST['first'];
}
if ($_POST['last'] == ”) {
$errors->add(‘empty_realname’, “<strong>ERROR</strong>: Please Enter in Last Name”);
} else {
$firstname = $_POST['last'];
}
}
function register_extra_fields($user_id, $password=”", $meta=array())  {

$userdata = array();
$userdata['ID'] = $user_id;
$userdata['first_name'] = $_POST['first'];
$userdata['last_name'] = $_POST['last'];
wp_update_user($userdata);
}

Posted in Wordpress | 17 Comments

Why Include a Logout Button?

So I am making a site where users can create an account on this site. It is not an important site where multiple users are going to be using the site, where there is a need for a logout button. So I am not going to include a logout button anywhere on the site. I just don’t see a use for it at all, unless someone will tell me different.

Posted in Clients, Wordpress | 1 Comment