Justin Gable

Archive for the ‘How-To’ Category

Modifying Wordpress’ default method for inserting media

Working on a client site this week I wanted to change the way that Wordpress inserts media into posts. Right now if you were to upload a flash movie (FLV) and click the “Insert into post” button, Wordpress injects the title of the file linking to the file you just uploaded (ex - <a href="http://yoursite.com/wp-content/uploads/movie.flv">The Title</a>).

I wanted Wordpress to output the data in a custom shortcode (ex -[flash http://yoursite.com/wp-content/uploads/movie.flv]). I have a plugin that will take that shortcode and turn it into an embedded flash video automatically. This makes it incredibly easy for a client to add flash movies and mp3’s to their posts.

So what did I do to change the output?

Filters FTW

Searching around the source code of Wordpress I came across the filter media_send_to_editor in /wp-admin/includes/media.php on line 291 (there is also image_send_to_editor on line 63 for those who are interested). Now that I found the filter I just needed to write a basic plugin to modify the output.

<?php
/*
Plugin Name: EWM Modified Media Insert
Description: Modifies the default method for injecting media into posts
Author: Element Web Media
Version: 1.0
Author URI: http://www.elementwebmedia.com/
*/

class ewmInsertMedia {
  //class constructor
  function ewmInsertMedia () {
    add_filter('media_send_to_editor', array($this, modifyMediaInsert) , 10, 3);
  }
  //function that does the modifying
  function modifyMediaInsert($html, $send_id, $attachment) {
    $output = '[flash '.$attachment['url'].']';
    return $output;
  }
}
//instantiate the class
$ewmIM = new ewmInsertMedia();
?>

There are a total of 5 values that are available in the $attachment array:

  • url
  • menu_order
  • post_title*
  • post_excerpt*
  • post_content*

* It says “post_” but the values are not that of the actual post but the info of the file. I’m not sure why they chose those particular terms to describe the values, it just makes it confusing imho. I remember now that Wordpress stores media entry data in the wp_posts table. That’s why it’s post_title, post_excerpt, etc.

Going beyond

The shortcode API is awesome, if you haven’t messed around with it yet I urge you to take a look at the documentaion. This discovery has inspired me to start working on my own flash plugin, one that’s seamlessly implemented and without all the extra bloat (unnecessary header requests, etc). Maybe I’ll post it here when I’m done, we’ll see :).

Blog Yourself: Buying a domain name

On the path to claiming your own piece of hyperspace real estate, purchasing a domain name is a good place to start. If you want to learn what a domain name is and get some tips for buying one, keep reading, but if your itching to blow some money click here to skip to the spendin’ part.

Examples

  • www.ebay.com
  • www.google.com
  • www.justingable.com

Purpose

In the simplest explanation possible; a domain name represents a specific place (directory) somewhere in the vast network of computer servers, what we web professionals like to call the “internet”, with an easily memorable name. If we didn’t have them we’d have to remember web addresses such as http://74.125.19.147/ if we ever wanted to visit Google.

Dot Whatever

Those little letters that appear at the end of a domain after the “.” (com, net, org) are called Top-Level Domains (TLD). Each one has it’s own reason for existance; the 3 most common are:

  • com: (Commercial) officially intended to designate commercial entities
  • org: (Organization) mostly associated with churches, charities and other non-profits
  • net: (Network) intended to be used only for the computers of network providers

Of course anyone can buy a domain name with either of these extensions, and these “rules” I listed are generally not followed. When buying your own domain, however, get a .com if at all possible, it’s the one that most people will assume is your TLD when entering in your address.

What’s in a name?

  • it must contain 3 to 63 characters
  • it can contain the letters a-z as well as numbers 0-9
  • it can contain a hyphen (-) but it cannot start or end with one
  • it cannot contain spaces or any other special characters

Where to buy

There are many places that will sell you domain names, some will try and entice you with $1 domains or even free… DO NOT FALL FOR THIS! Usually they want you to sign up for their hosting service before they “give you” the domain name of your choice. But wait there’s more! That domain you were just “given”, you don’t own it, the people you bought it through do. So, when you go to change hosts for whatever reason, they will most likely not give you the domain name back.

It is best to buy through a 3rd party and there are two that I recommend, GoDaddy (you know, the ones that run all the ads during the Super Bowl with the skanky women) and NetworkSolutions. Both offer nice controls to manage all your domain names and have excellent customer service. GoDaddy is who I use and they’re the ones I’m going to walk you through buying your own domain name.

The Walk-thru

 
Buying a domain name on Godaddy.com from Justin Gable

Wrapping up and looking ahead

Hopefully I’ve helped clear the air around getting your own domain name. However, if there is something you feel I left out or something I went over needs some more elaboration, leave me a comment.

In the next tutorial I’m going to show you how to purchase your own hosting and setup your domain name to point to your shiny new server space.

Blog Yourself: Introduction

Hey, everyone! I’m very excited to introduce a blog series that I’m going to be posting starting this week titled Blog Yourself (if someone has a better name please let me know :) ). I will show you how to create your own blog from start to finish. I wanted to breakdown the seemingly complicated process of setting your own blog up and make it easy for anyone interested in blogging.

I have noticed some of my wife’s blogging buddies and many others using services such as Blogger and TypePad to run their blog. These services may be an appropriate option for some, but are actually quite limiting to those seeking more control and a more professional image. For bloggers falling into this category, I want to offer insight on migrating their blog to their own web host as well.

Let me give you an overview of what I will be covering and who may be interested in this series:

What I will cover

  • Purchasing a domain name
  • Finding and purchasing web hosting
  • Installing and configuring blogging software (WordPress)
  • Free applications used to setup and customize your blog
  • Free web services that show you detailed statistics for your blog
  • How to customize your blog with themes and plugins
  • Tips on best practices and better usability
  • Basic SEO (Search Engine Optimization) to give your blog a higher ranking in various search engines such as Google and Yahoo!

Who may be interested in this series

  • non-bloggers who would like to start their own blog
  • bloggers who use a hosted blogging service such as Blogger or TypePad and who would like more control by hosting it themselves (I will show you how to migrate your posts and comments from your current blog)
  • bloggers who want to learn useful tips on customizing and promoting their blogs

Who/what this series is not intended for:

  • those looking for WHAT to write about on their blogs (I’m just giving you the tools, not the content)
  • people intending to use blogs to spam
  • carnies

I am planning to go into as much detail as possible on each subject, even splitting individual topics into multiple posts if they require more attention. I will try to include as many screenshots as well as videos (if requested) of the tutorials. Feel free to post comments asking questions or send me a message on my contact page.