Categorie ‘Code’ » Archiv


0

Never lose your source code, ever!

March
1

Twice. In 1 week.

I lost my code and my awesome plugin edits when my hard drive crashed, I started writing it again and I formatted the wrong partition. Seriously gutted! I tried to recover the data with undelete apps but it was gone forever.

No worry no more!

Now, I don’t need to worry because I use Dropbox and have configured my local server to use it as the document_root of my dev site. That way, all the developing work I’m doing gets saved automatically online and is accessible on any of my pc’s.

I don’t even need to worry about being able to access the SAMBA share if I want to edit a file, I just open it from my dropbox on the pc I’m using and save it back there, it’ll get automatically updated on my dev server.

Oops no more!

Another advantage is the revisions feature. You can go online and see the updates that you made to a file and revert it back to an earlier save. This has already saved me from crying, I always forget to rename a file before I start trying to add updates and before I know it, the whole thing is causing an error and I can’t remember how to put it back the way it was! just luvin the revision feature!!

Get 2GB for FREE! (and help me out)

You can apply for a Dropbox for FREE and get a full 2GB to use to store anything from simple documents to executable files to database backups or like me, use it as your code repository and never go through the pain of a lost bit of awesome code again!

You can even install it on Linux which is super helpful when it comes to transferring files between a windows->linux network.

If you click this link and install your dropbox for free, we both get extra bonus space which would help me out a lot :)

Blog Tools, Code, Uncategorized


0

Taming the Upgrades plugin from http://premium.wpmudev.org

February
2

If you’re lucky enough to have a subscription to Premium WPMU Dev account then you’ll have access to great monetization plugins like the Upgrades or Supporter which take all the pain out of providing a ‘pay for’ service that can handle payments through Paypal, Google or even Amazon gateways.

I downloaded and installed the upgrades plugin a while ago and I’ve used it to monetize certain parts of my ComLuv site. There’s the usual way of adding plugins to the Upgrades directory and configuring them to be used which I’ll go into in a future post but I wanted to use the system slightly differently, and that was to charge users for adding new URLs to an account or to add default links to their returned list of posts.

The advantage of premium

Some of the advantages to using wpmupremium plugins is the support you receive, knowledge that the plugin will be updated to keep it compatible with new changes and my favourite is, the quality of the code.

When you’re getting premium, you’re getting premium code which for me personally, has taught me a LOT about how wordpress works. Particularly custom hooks and actions and filters. That was always a mystery to me until I dissected the plugins I downloaded from their site so it was a breeze to modify the upgrades plugin to work for users who don’t have blogs and start using the internal functions in a daughter template to do what I wanted.

Modifying the upgrades plugin


I needed to allow the upgrades menu to show for regular users because not everyone who joins the Comluv site starts a blog. This was just a simple case of changing the user level so that everyone, not just blog owners can see the menu and buy credits.

There are two places to modify:

/mu-plugins/upgrades-framework.php
line ~ 197-200 (upgrades plug pages framework function)
change add menu and submenu calls to

add_menu_page($upgrades_branding_plural, $upgrades_branding_plural, 0, 'upgrades.php');
add_submenu_page('upgrades.php', __('Credits'), __('Credits'), 0, 'credits', 'upgrades_credits_output' );
add_submenu_page('upgrades.php', __('History'), __('History'), 0, 'history', 'upgrades_log_output' );

line ~ 1919 (upgrades_credits_output function)
change user check to

if(!current_user_can('level_0')) {

Creating the daughter template

Adding another page you can use as a template is pretty easy, you just need to create a new php file in your theme directory and make sure it has the correct remarks at the top to identify it as a template page.


/*
Template Name: ComLuv purchase url
*/

Next just copy and paste the main calls from another template, you’ll be deleting most of it like the loop to display posts and replacing it with your own hard coded form and text. Be sure to keep the divs that surround the content intact.

I wrote a description of the item being sold and added a form.
(DON’T copy and paste from this page, I had to remove the beginning < characters from the code so it displays properly)

form action='/member/additional-urls/' method="POST">
input name="addurl" type="text" size="30"/>
input type="submit" name="submit1" value="Submit"/>

/form>

I also added a finish_page() function which just closes the /div tags so I could easily break out of what I was displaying without rendering the rest of the custom code below it.

You set the action to the page slug you’re publishing the page as and put a nonce field in there so you can check it with the next bit of code to prevent a naughty user from trying to call the purchase directly.

Handling the purchase

Next, you need to handle the data that gets submitted by your form and do the magic with the users credits.

if(isset($_POST['submit1'])){
$nonce=$_REQUEST['_wpnonce'];
if(!wp_verify_nonce($nonce,'addurl1')){
echo 'Page request deformed, please go back and try again. (b1s1)';
finish_page();
}
if(!$_POST['addurl']){
echo 'Please go back and enter a value';
finish_page();
}
// check if user has enough credits
global $user_ID;
$credits = upgrades_user_credits_available($user_ID);
if($credits < 3){
echo 'h2>Error - Insufficient Credits/h2>';
echo 'p>You will need to purchase some credits to register another URL, you currently have strong>'.$credits.'/strong>';
echo 'p>a href="/wp-admin/upgrades.php?page=credits">Click here to visit the purchase page/a>';
finish_page();
}
// if we're here then everything is ok to provide service and deduct credits
$credits = upgrades_user_credits_available($user_ID);
$credits -= 3;
upgrades_user_credits_update($credits);
upgrades_log_add_msg($user_ID,'You paid 3 credits for an additional URl - '.$url);
do_add_url($url,$user_ID);
echo 'h2>Site added, 3 credits used on your account/h2>';
echo 'p>You have '.$credits.' credits remaining';
echo 'p>a href="/member/additional-urls/">Click here to refresh the page/a>';

The first bit gets the nonce you created and checks it and displays an error message if it doesn’t match
Next, check the field you’re expecting and spit out an error if it is empty.
Next, check the user has enough credits and spit out an error if they don’t.
If everything is fine, continue.

use $credits = upgrades_user_credits_available($user_ID); to get the users current credits total
use upgrades_user_credits_update($credits); to set the users credits total to $credits (after you deduct what your item/upgrade costs)
use upgrades_log_add_msg($user_ID,’You paid 3 credits for an additional URl – ‘.$url); to add a message to the users Credits history page so they know they used some.

That’s it, easy peasy! Here’s an idea, use credits to sell digital downloads on another page, just check and deduct the users credits before allowing a dowload.

I’ll post a follow up to this soon on how to use the upgrades plugin to add a new package that enables the RSS widget for a blog (I’ll show you how to disable the rss widget too)

You can get over 100 plugins and themes of premium quality at http://premium.wpmudev.org and they all help to make your wpmu site better than the jones’s :)

Blog Tools, Making / Made Money, PHP, Wordpress


11

They go in 3’s too

November
24

You know how the expression says that problems come in 3’s ? I get 3 lots of 3’s most of time but this week I think I have managed to get rid of 3 problems.

I was posting about my woes at Comluv and just a few days later I finally managed to track down the random freezes on my AsRock M3A790GXH – 128M motherboard and OCZ DDR3 Gold Series RAM

Random crashes on Vista/7 – AsRock M3A790GXH/128M with OCZ DDR3 Gold RAM – Solved

Shiny, SHINY! RAM!

Shiny, SHINY! RAM!


The crashes were driving me crazy, I could never repeat the action that caused the crash and there was never any entry in the event log except for after the reboot. I tried removing one stick and running it with that one to see if it was a faulty stick, it crashed on the first try so I thought that was it but after swapping it with the other stick, the pc crashed within a day. :(

It turns out that OCZ DDR3 RAM needs 1.9v instead of the regular 1.5v that it would get from the motherboard. A quick visit to the bios and I switched the DRAM voltage to 2.0v and the pc has been up and running for days without a problem. yey!

Dedicated server non responsive after high traffic – solved

They put the fast in, um, ukfast :)

They put the fast in, um, ukfast :)


Another problem was my server, it is fast and a nice bit of kit but it was getting overloaded at times with so many requests to the CommentLuv API. I had a word with UKFast explaining to them that I expected my server to be able to stay up if a lot of traffic came in. They did their utmost to help and sent me a very nicely priced invoice to beef up my server with an extra 1 GB of RAM.

It’s been up for 7 days and the CTM graphs are showing me that my CPU usage and system load are down a lot from what they’ve been.

Monthly view upgrade shows better performance

Monthly view upgrade shows better performance

Looks more dramatic on the 1 year chart

Looks more dramatic on the 1 year chart

My last issue was my laptop charger, it went poof! I did a search online for a universal charger and the best price I could see was over 60 quid! luckily, I was able to buy a Toshiba charger from ebay for 9.99 for next day delivery.

sorted! (for now)

Blog News, Code


4

How to do a mass text search and replace with MySQL

October
24

I noticed that all my images on the posts here weren’t showing and it was because the url to their location was still pointing at the sub blog on The Comluv Network so I needed a way to edit the database to update the url to point to the files held here.

Easy with a REPLACE function on the wp_posts table.

You just need 3 things for the replace command :

  1. The row you’re altering
  2. The string you’re searching for
  3. The string you’re replacing with

UPDATE `wp_posts` SET `post_content` = REPLACE( `post_content` , "fiddyp.comluv.com/files/", "fiddyp.co.uk/wp-content/uploads/" )

It did the whole table of posts in less than a second. Sweet, now all my images are back to normal on this site.

Code, PHP


165

WP-Twitip-ID Plugin – Add a twitter field to your comment form (easily)

October
8

Version 1.0 (updated 11 Feb 09)
Requires: Wordpress 2.6 (could work with lesser)
Tested up to : Wordpress 2.7b3

This plugin is no longer supported, please download TwitterLink-Comments which will do a much better job and will still be able to use the existing database table and labels.

Download TwitterLink Comments

Blog News, Blog Tools, Code, PHP, Wordpress


6

Crashing like a mofo and OMG big list of to-do

August
12

It’s been almost a week where I haven’t been coding anything for longer than an hour without the computer crashing with weird little squares all over the screen. :-(

pc_crash11

I think it has to do with my integrated graphics card (Radeon HD 3300) . I have gone through all the usual steps of updating drivers, bios, firmware and wotnot and I am waiting for the next crash.

It’s been hard because I need to code some major things for the ComLuv site and every time I get deep into it, the bloody pc crashes! It’s doubly hard because I have so many great things to watch and listen to on these awesome monitors and 5.1 speakers and I can’t because a little bit of media is liable to make the screen freeze with little squares corrupting it.

Big mofo list

I’ve got a fair bit of stuff to do for the ComLuv network, it’s kind of like the washing up. The longer you leave it, the less likely you are to do it… imagine a big pile of washing up and then imagine that the kitchen crashes every time you run the water. That’s me that is. boo hoo

If my latest open heart procedures on my hardware can keep the system up without pissing it’s pants when an mp3 gets played, I can move on to what I was doing before all this crashing malarky. Which is..

1st priority: Get the url registration page working with a new look and form validation. (seriously, I don’t know how people keep putting http://http:// in their url field!)

2nd priority: Update the WP commentluv plugin with these new things:

  • update the settings page to look real nice
    I’m doing this with a plugin framework that takes care of all the settings page bumph so I can easily make it a lot more intuitive to use.
  • Allow CSS to be edited for all objects
    This seems to be an important thing to do. Rather than edit a style sheet or hunt through the code for inline styles, I will add a text input box for the different objects so (advanced) users can completely control the look of the links, badge and info box.
  • Add the Russian and Chinese language files
    Awesome work from users to add even more languages to the plugin

3rd Priority: Allow more URL’s per account on ComLuv.
This was supposed to be done already but I have spent an awful lot of time on making sure the basics work properly, plus, my personal/business life has it’s own mofo lists to deal with!

4th Priority: Add a “what I’m doing” theme to ComLuv so extra features that are only available to ComLuv blog owners can be opened to all. This will be a friend feed type of affair where you can add widgets to show your stumbleupons, diggs, comments, luvlinks, link clicks etc etc.

I want this in right now but time to do it is a rarity for me these days! Having this theme will allow people who don’t necessarily want a new blog to have the extra features. It might help with links and traffic to have a site where your latest links and other social activities are chronicled and it’ll reduce the amount of empty blogs created on the network.

5th Priority: Tutorials and videos!
Lots of them.

6th Priority: Email courses.
Everything from starting blogging to running your own network to making money with a ComLuv blog (I’m itching to start this one!)

There’s loads more but it’s depressing the hell out of me listing them!

As soon as the crashing like a mofo finishes, I’ll try to get on the coding like a mofo. Stay tuned!

Blog News, Code


6

New url registration page or new plugin settings?

August
5

I took a day off this week and it extended itself to another half which then puts me in contemplation mode.

I’m used to this happening after finishing a particularly complex series of things, I kind of get a sugar crash which puts me into day off mode, that then leads to search for new source of sugar.

It happened last week, I managed to work out how to upgrade the WPMU version ComLuv site to 2.8.2 and then expand the single db into 256 smaller ones. This was a big thing for me, it was either get the site working with 256 databases or fork out another bundle of cash every month for an extra gig or two of RAM on the server!

Luckily, after seeing it work fine for about a week with the new db configuration and no scary cpu usage alerts coming, I think I can concentrate on the next stage of development. I’m really itching to get a decent url registration page up and I’m considering opening up the ability to have up to 5 urls or sources registered with your account without needing anything other than a standard commentluv account.

I’ve already started sketching out what I want the page to look like (which I really should have done the first time around!)..
Sketching out new url registration page on Twitpic

Another thing I really want to do is convert commentluv to use a plugin framework so I can really do wonders with the settings page and not worry about htmlspecialchars this and mysqlescape that.
Doing this would allow me to put in some needed features to the commentluv plugin like full editing of the css used.

I’m tempted to update the plugin first, I have just received a Russian translation to go in with it and I want to update the readme so it is formatted to display fully in the plugin browser of a wp blog.

Oh the quandary! I can’t decide which one to do, they both need doing and both need to be done on their own or else distractifications occur!

What’s more important to you?
1. comluv update to make the whole url registration process nicer and add 5 sources to your acocunt
2. fix plugin so you can edit your own styles and have a prettier and easier to understand settings page?

Blog News, Code, Wordpress


4

Big fat database moves to 256 thinner ones

August
2

I spent the morning putting Comluv through some tasks to convert the huge monstrosity that was my wpmu database into 256 smaller ones. it was touch and go for a bit, I did a practice go on a local install but misread some docs and put wrong values in, the whole thing looked like it worked anyway but a live install is a different matter!

I think everything is working as it should now, no errors are appearing in the error log and posts and blogs are being created.

I thank thulawd that I had a WPMU premium account so I can go and ask lots of questions at the WPMU premium site! I got a free membership when the 2.7 version of CommentLuv won the wpmu plugins contest. It’s one of the best prizes I have ever received! it is partly why comluv is open to multiple users now.

I am not going to touch much today and see if any major happenings happen and maybe, just maybe, my day off tomorrow can actually be a day off… fingers crossed

Blog News, Code


1

A day of other peoples code

June
24

Support Tickets

I did some pretty fancy tweaking of code today to see if I can replace the support tickets system on ComLuv, the system at the moment isn’t bad but the last support ticket management software I used was far superior and allowed me to reply to closed tickets and create canned responses.

It will need some more work to integrate it into the dashboard of the site but I’m pretty confident I can do it.

Theme

I feel the need to tweak themes too, I found an old mockup image on my hard drive that I had for a client that never took up the job and I contacted someone about converting it to a WP theme. I love how it looks and I’d really like to have the format for ComLuv so I can start on tutorials and other features.

That’s not to say the current one isn’t great, it’s just that I’m all for “get it done” then “make it work” and then “make it pretty” and then “do it all again until I have what I want.

Newsletter

I had a bit of a nightmare with my newsletter software taking up too much resources while being on the same server as ComLuv so I took steps to transfer it to another server and use the ComLuv SMTP connection to do all the sending. Hopefully this will fix any issues I was seeing..

Tutorials & Videos

I have the new pc set up with a screen recorder and I have a list of videos that I’d like to produce for tutorials on the ComLuv site. I tested it out and my quad core monster can handle the capture on a widescreen so I can do HD videos and host them on Vimeo

Remote Images & Scripts

I have done some serious optimization on the blogger version of CommentLuv so that now there are very few calls to the ComLuv server for images and scripts. This one thing should dramatically decrease the server load during busy times.

Work

And now I have to tweak the system in the shop.  The tweaking never ends!

Blog News, PHP, Social Networking, Wordpress


2

Coding is nearly done for new CommentLuv for Blogger/Js-kit

June
11

enough with the twitter updates please mr. twittertools! sorry about that, who really needs to see twitter updates? (although i did notice google indexing more tweets and sending me alerts about them)

anyhoo, I am fiddling with some code right now for the Blogger / JS-kit version of new CommentLuv and will hopefully have that up ready for the weekend quiet time. I’ll put up some easy install instructions too so it should be case of click a button and the code gets installed to your blogger dashboard.

I’m hosting the script files myself on my ukfast server, the last server (when it stayed up) managed to serve those files ok so I think it should be fine for the switch on with this new super dedicated and supported server. If it gets too much, then I can look at using Amazons’ S3 service to serve everything. I researched on their service before and it seems to be fairly inexpensive to do. Although now, I’m paying for the server so I might as well use its resources. If things get so big that it needs a massive upgrade then that can be dealt with at the time. (Dragons Den? lol)

Please let me know about any errors you’re experiencing or glitches with the CommentLuv API, site or plugin by submitting a support ticket at The ComLuv Network

I still can’t believe how many hits and links come through to my sites from this plugin, last night there were over 1300 downloads of the plugin from the wordpress repository! and more than 1500 comments processed by the API.

Talking of the API, it is being updated before the weekend so I hope you can be patient, I am but one man and have only 2 coder peeps to pester/hassle/question/demand/poke/tweet about the server and API. And to top it off, I work full time in a takeaway (Fired Wok Chinese Takeaway and Delivery in Lancaster, Lancashire – tasty food chop chop!) which I luv. (seriously, I luv that job)

Blog News, Blog Tools, PHP