Archive

Posts Tagged ‘backup’

5 Things to Consider When Finishing a Site

April 9th, 2013 Comments off

So you have finished up your theme, all the design elements are in place and you’re happy with how it looks and works. But are you really done? There are so many little things that can easily be over looked.

Lets take a look at some of them and see what we can do about it.

/>

1. Take Control of Your Email

Nothing says unfinished quite like one of your users getting an email from your site and having it say it’s from “WordPress” and be some nondescript email address. Thankfully with just two filters we can tackle this issue.


The code above should be easy to follow. Both functions have only one argument, either the name or the email address. We take that variable and add our own name or email then return it. Depending on your needs these functions can be this simple, or get extremely complex setting different names and return emails based on forms, pages, user status or anything else.

/>

2. Master the Excerpt

There are many things that can be done with the excerpt from filtering it before it’s saved to controlling its length. We are going to talk about two excerpt filters: excerpt_length and excerpt_more

The default excerpt length is 55 words, don’t get this confused with characters. To change this value we can use a simple function such as:


But we can take this one step further and use a custom meta field to allow the post writer to set the excerpt length per post.

ID, 'custom_excerpt_length', true ) ) 
		$len = $custom;
	

	return $len;
}
?>

Now that we have the excerpt_length sorted out lets tackle excerpt_more. As we all know the default more text looks like this [...]. Changing that value is rather simple just like the first example for excerpt length.


Now that looks a little better. I never really liked the square brackets in there, but lets take it one step further. Why not make the more text actually link to the post.

ID );
	$more = "More >";

	return $more;

?>

There, that’s much better, now we have an element that we can style and conveys the message that there is more to this story and you can see it by clicking here.

/>

3. Don’t Forget the Analytics

Analytics are a large part of running a successful website. It doesn’t matter if it’s a small “mom and pop” site or a fortune 500 company site. There is always a way to benefit from tracking the usage patterns of your site.

There are a lot of options when it comes to Google Analytics plugins, some are better than others and everyone has an opinion on what is the best. I’m not going to tell you that the two plugins I’m going to talk about the absolute best, but they are the ones that I have found to offer the options that I want.

  • Google Analytics for WordPress by Yoast

    Yoast takes analytics to the next level by taking advantage of analytics custom variables to track traffic by post type, author, clicks and downloads and a handful of other options. With the amount of data that is collected though this plugin you can map out your traffic patterns till your head spins, and still have data to go through.

  • Google Analytics Dashboard

    Where Yoast takes all the information you could want and feeds Google with it. Google Analytics Dashboard takes that information and puts it right at your fingertips. The dashboard widget gives you at-a-glance statistics of the traffic, most popular pages and posts, top searches, and top referrers as well as bounce rate, visits and page views. While the analytics column added to the page / post list gives you the sparklines and data for each post or page.

The use of these two plugins together has allowed me to help my clients really understand how to use analytics and improve their site based on that information.

/>

4. A Little SEO Goes a Long Way

Yes, yes, I know this subject has been done to death, reanimated and put down again. So why am I bringing it up in this article…

That would be because people still fail to really pay attention to what SEO is and what it can do for your site. Of course this isn’t an article on how to properly handle SEO in your theme, I’m going to assume you have already done that.

What I am going to do is just share some of my personal choices for SEO plugins when finishing up a new site.

  • All in One SEO Pack

    For years I have been using this plugin for the daily SEO needs of client sites. It has always performed admirably and I will continue to use it for years to come.

  • WordPress SEO by Yoast

    This plugin has been around for a while now but it was only recently that I used it for the first time. And I fell in love with it. The features are outstanding and the flow of the plugin is perfect. It makes number two on my list because I fear some of my less tech savvy clients clients fill find some of the features overwhelming.

  • W3 Total Cache

    I know most of you reading this are probably asking if I have a screw loose. What does page caching have to do with SEO? When you consider that Google uses page speed as a factor in ranking sites it becomes clear that caching can not only be in the performance section of your needs but also a big factor in SEO too.

/>

5. Back It Up

There are some things in the development world that are unavoidable. One of those things is the dreaded “It’s all gone!” call/text/email/other form of contact. If you haven’t had the luxury of dealing with it yet, just wait, you will.

It will start out with a frantic message from your client saying that something has happened to the site, of course they will have no idea how or what happened. At this point there are two things you can tell your client; either you have a backup you can restore, or you don’t.

You really don’t want to be the guy that has to tell the client that he is out of luck. Do you?

The great thing about the open source community is when you need a solution for something there are bound to be a good number of options to choose from. If you search the WordPress plugin directory for “backup” you will get close to 500 results. Not all things are created equal and rummaging through 500 plugins can take a really long time. So I’m going to narrow the field a bit and talk about a couple solutions that I’ve used that work, and work well.

  • BackWPup

    This has been my goto plugin for backups for a while. Not only can it backup the database but also the entire file structure. The resulting backup can be stored on the server, sent to your email or more importantly it can be stored using a number of external storage sites like S3, Dropbox or even through the FTP of another server.

  • Online Backup For WordPress

    Similar to BackWPup Online Backup for WordPress will create a backup on your local server that you can download, or it can email it to you. There is also a third option to backup to your own Backup Technology account and store your backups in their secure data center (100 MB free).

  • VaultPress

    Unlike the first two solutions VaultPress comes with a monthly fee ranging from $5 to $40 at the time of this article. It is also a complete third-party backup. When your site is backed up the files are stored on the VaultPress servers and can then be restored from there too. This means that if anything ever happens to your server or personal computer the files will still be safe and sound on their servers.

Some other plugins that I’ve used over the years and deserve an honorable mention in this category are WP-DB-Backup, Complete Central Backup, and Backup.

/>

Conclusion

The five topics covered in this article only scratch the surface of all the nit picking that can be done on a site before you finally launch it. But they do make for a good start to get you to think about what else there might be to do.

It is also important to keep in mind that every client is different and what worked for one will not always work for another. Some people are tech savvy and want lots of features, some are not and want it as automated as possible. So it’s best to keep an eye out for new plugins that do the same job in different ways so you always have options.

Original from: http://feedproxy.google.com/~r/Wptuts/~3/Q1ZCoyuk0j4/

Creating a Simple Backup/Restore Settings Feature

June 22nd, 2012 Comments off

Options are the most important data in WordPress, they store various configuration settings (see more). They’re also contained in the database like other important data such as posts, pages, etc. Day by day, these options can be changed by WordPress itself or users. So how to configure them back to a previous state without memorizing each exact value?

In this tutorial, I’m going to show you how to create a simple backup/restore feature for your WordPress blog. With this feature, you can backup all options to another place, that you can restore them from at any time without configuring them again.


Before We Start

In general, our feature will have two sections, one is an Export section for backing up data and an Import section for restoring data. So I will demonstrate these by creating a simple plugin.


Step 1 Plugin Header

First of all, I must write a few lines to tell WordPress about our plugin.

/*
Plugin Name: I/E Option
Plugin URI: http://wp.tutsplus.com/
Description: This is a sample plugin with backup and restore options feature.
Author: Lee Pham
Version: 1.0
Author URI: http://twitter.com/leephamj
*/

And here is our result:


Step 2 Create a Page Admin

Now we need a place to put our plugin interface, it shows two key features that were mentioned above (including Import and Export features). So I generate a page in the admin section:

function register_ie_option() 
	add_menu_page('IE Option Page', 'IE Option', 'activate_plugins', 'ie-option', 'ie_option_page', '', 76);
	add_submenu_page('ie-option', 'Import', 'Import', 'activate_plugins', 'ie-import-option', 'ie_import_option_page');
	add_submenu_page('ie-option', 'Export', 'Export', 'activate_plugins', 'ie-export-option', 'ie_export_option_page');


function ie_option_page() 
	// Our stuff here


function ie_import_option_page() 
	// Content Import Feature


function ie_export_option_page() 
	// Content Export Feature

add_action('admin_menu', 'register_ie_option');

Here are some points:

  • We use add_menu_page as a built-in WordPress function to add a new top level menu section in the admin menu sidebar and where the ie_option_page parameter is the callback function for outputting the page content.
  • In order to separate two main features into different sections, we use add_submenu_page to add them to the top level menu we just created above. As you see, each function also has a callback function to display output content like the add_menu_page function does. It does not matters if you merge these into one place, I just try to keep it clear.
  • Then we hook register_ie_option on to the admin_menu action in order to trigger our goal everytime this action is called.

Step 3 Create Export Feature

I plan to create an Export page like this:

Create Export Page Skeleton

function ie_export_option_page() 
	if (!isset($_POST['export'])) 
		?>
		

Export

When you click Backup all options button, system will generate a JSON file for you to save on your computer.

This backup file contains all configution and setting options on our website. Note that it do NOT contain posts, pages, or any relevant data, just your all options.

After exporting, you can either use the backup file to restore your settings on this site again or another WordPress site.

We just create a form with a button and check if the button is being clicked or not. Additionally, we add some instruction text using some available WordPress CSS class. For doing a security check, I use a wp_nonce_field() and the check_admin_referer() function, read more about WordPress Nonces.

Naming the Filename to Be Generated

$blogname = str_replace(" ", "", get_option('blogname'));
$date = date("m-d-Y");
$json_name = $blogname."-".$date;

Just name the file so you can easily see where and when it was exported.

Get Backup Options and Encode Into JSON Data

$options = get_alloptions();

foreach ($options as $key => $value) 
	$value = maybe_unserialize($value);
	$need_options[$key] = $value;


$json_file = json_encode($need_options);

Here is the important step, let’s pay attention:

  • get_alloptions() is a function that gets all options on your site and returns them as an array, $options in this case.
  • By retrieving all the options, the value of options may be serialized data, so we have to unserialize it first.
  • Our intention is to generate JSON to store the backup data. JSON is a light-weight and powerful way to store text information. So what we need to do is convert our data to JSON syntax, json_encode helps us to achieve this goal.
ob_clean();
echo $json_file;
header("Content-Type: text/json; charset=" . get_option( 'blog_charset'));
header("Content-Disposition: attachment; filename=$json_name.json");
exit();

Then we wrap content of our JSON data within two important functions, ob_clean() and exit() to ensure our generated JSON file only contains JSON data that json_file holds without any other data. By the way, we send a header request to the client that displays a download dialog. To make this work properly we should put the ob_start() function at the top of our plugin code, this prevents header errors from occurring, maybe there are some extra whitespace or lines somewhere in WordPress code that could cause that.

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.”

So here is the entire Export function code:

function ie_export_option_page() 
	if (!isset($_POST['export'])) 
		?>
		

Export

When you click Backup all options button, system will generate a JSON file for you to save on your computer.

This backup file contains all configution and setting options on our website. Note that it do NOT contain posts, pages, or any relevant data, just your all options.

After exporting, you can either use the backup file to restore your settings on this site again or another WordPress site.

$value) $value = maybe_unserialize($value); $need_options[$key] = $value; $json_file = json_encode($need_options); // Encode data into json data ob_clean(); echo $json_file; header("Content-Type: text/json; charset=" . get_option( 'blog_charset')); header("Content-Disposition: attachment; filename=$json_name.json"); exit(); } }

Step 4 Create Import Feature

This page’s task is quite simple, it displays an upload form and parses data from the JSON file to backup our options.

Create Import Page Skeleton

function ie_import_option_page() 
	?>
	

Import

Click Browse button and choose a json file that you backup before.

Press Restore button, WordPress do the rest for you.

Like the Export page we create a form, but this time, we add a Browse button so the user can choose the file they want and submit it.

Validation and Updating JSON File

if (isset($_FILES['import'])) 
	if ($_FILES['import']['error'] > 0) 
		wp_die("Error happens");
	
	else 
		$file_name = $_FILES['import']['name'];
		$file_ext = strtolower(end(explode(".", $file_name)));
		$file_size = $_FILES['import']['size'];
		if (($file_ext == "json") && ($file_size < 500000)) 
			$encode_options = file_get_contents($_FILES['import']['tmp_name']);
			$options = json_decode($encode_options, true);
			foreach ($options as $key => $value) 
				update_option($key, $value);
			
			echo "

All options are restored successfully.

"; } else echo "

Invalid file or file size too big.

"; } }

If the upload process gets errors, just return a die message “An error has occurred”. If not, get the extension and size of the file, store them into variables and check them. We only accept files that have the “.json” extension and size of less than 500000 bytes. If the file is not an appropriate one, just display an error message “Invalid file or file size too big.”. Note: You can modify this size as you need.

Then, the $encode_options variable will get all content of this file. As the file contains JSON data, before using it we must decode first. To do this, we use json_decode with a second parameter that has a true value so this function returns an array value. With an array value, we start to loop over it. On each iteration, we will update data with the same key and its value. In the end, all our options will be restored exactly as they were, and a successful message will be displayed.

And here is the entire Import function code:

function ie_import_option_page() 
	?>
	

Import

0) wp_die("Error happens"); else $file_name = $_FILES['import']['name']; // Get the name of file $file_ext = strtolower(end(explode(".", $file_name))); // Get extension of file $file_size = $_FILES['import']['size']; // Get size of file /* Ensure uploaded file is JSON file type and the size not over 500000 bytes * You can modify the size you want */ if (($file_ext == "json") && ($file_size < 500000)) $encode_options = file_get_contents($_FILES['import']['tmp_name']); $options = json_decode($encode_options, true); foreach ($options as $key => $value) update_option($key, $value); echo "

All options are restored successfully.

"; } else echo "

Invalid file or file size too big.

"; } } ?>

Click Browse button and choose a json file that you backup before.

Press Restore button, WordPress do the rest for you.


Create Your Own Backup Feature for Your Templates or Plugins

In the sample plugin, I backed up all of the site options by using the get_alloptions WordPress function. If you want to apply this to your own specific options, just do it like this:

$options = array('your_option1_name' => get_option('your_option1_name'), 'your_option2_name' => get_option('your_option2_name');
$json_file = json_encode($options);

And go on to the next step as above. You freely choose what options you want to backup!


Conclusion

In this tutorial, we take a look at an overview of creating a simple backup/restore feature. You should notice that my plugin is just a simple sample not an official one. My goal is not write a perfect plugin, but to show you the basic principle of this feature. By understanding it, you can create your own feature on your templates or plugins, you also can make it as flexible as you want. Therefore you can make this feature isolated for your templates/plugins.

I hope this tutorial is useful for you, let me know what you think. Your ideas make it better, or even show me my mistakes, your feedback will really help a lot. Thanks for reading!


Preference:

Original from: http://wp.tutsplus.com/tutorials/creative-coding/creating-a-simple-backuprestore-settings-feature/

WordPress 3.4 Has Arrived… Now What?

June 15th, 2012 Comments off

We posted last week about the upcoming features to look out for in WordPress 3.4, and yesterday it was released. That’s right, WordPress 3.4 “Green” is out right now! So what happens next?


Getting Up to Date

No doubt you all know how to update a WordPress installation. You just click the “Update” link and away you go, right? Well, you could do that but let’s think for a second about our theme and plugins, do we know for sure that everything will go smoothly?

I recommend you take the following steps as a minimum:

  1. Backup your current site’s files and database – you can do this manually or with a plugin, as long as it’s something you can restore from without too much trouble.
  2. Create a new installation using your backup – do this either on a sub-domain or on your local development environment.
  3. Once you’re up and running, perform the update – if you come across any errors, get them fixed up.
  4. Assuming everything went well and you’ve fixed any issues, update your site, and apply any fixes there too.
  5. You’re done! Enjoy WordPress 3.4

The Future

Now that WordPress 3.4 is out, hopefully you’ve all read the WordPress 3.4 Field Guide for Developers. If you haven’t, you should. If you’re a theme or plugin developer especially, hopefully you’re busy making updates to your themes and plugins too.

Now we can turn our attentions to WordPress 3.5, which will start being discussed at the WordPress Developer chat next week (for times, see the sidebar from the field guide link).

What are you hoping to see in WordPress 3.5? Let us know in the comments below.

Original from: http://wp.tutsplus.com/articles/news/wordpress-3-4-has-arrived-now-what/