Archive

Posts Tagged ‘article’

Design Patterns in WordPress: The Simple Factory Pattern

May 17th, 2013 Comments off

This entry is part 3 of 3 in the series Design Patterns in WordPress

In this series, we’re taking a look at design patterns and how we can leverage them to our advantage when building products on top of WordPress.

The nice thing about design patterns is that they aren’t explicitly limited to themes or plugins – they are handy in a variety of different scenarios. It’s simply a matter of being able to identify which patterns are applicable to certain scenarios.

In the last post, we reviewed the Singleton Pattern. In this article, we’re going to take a look at the Simple Factory Pattern which is especially useful when you have a number of different classes each of which has a unique purpose and solves a specific problem.

In this post, we’ll take a look at another pattern – the Simple Factory Pattern – which is useful when you have a number of classes each of which has a unique purpose and that can be selected based on certain criteria.

/>

The Factory Method Pattern

The Simple Factory Pattern is actually derived from a pattern known as the Factory Method Pattern which is a slightly more complicated version of the pattern that we’re going to be reviewing.

According to Wikipedia, the Factory Method pattern is defined as follows:

The factory method pattern is an object-oriented creational design pattern to implement the concept of factories and deals with the problem of creating objects (products) without specifying the exact class of object that will be created

Sounds a bit complicated, doesn’t it?

The truth is, it’s actually a really powerful design pattern but it would take a much longer article to discuss it, and it’s a bit out of scope for the purpose of this series.

So, as mentioned, we’re going to take a look at a version of the pattern that’s paired down a little bit and should be more generally applicable to less complicated projects.

Before we do that, let’s come up with a definition of the Simple Factory Pattern:

The Simple Factory pattern returns a specific set of data or a specific class based on its input.

Ah the risk of making a pun, simple, right?

A Note About the Simple Factory Pattern

The truth is, many software engineers refer to the Simple Factory more as an idiom than a full-blown pattern; others consider this a pattern.

For what it’s worth, I see it as a very simple pattern. It has a specific use case that can be easily identified when to use it during the course of development which we’ll review later in this article.

Regardless, I bring this up so that if you see this used as an idiom (or a pattern) used throughout various articles on the Internet, or even in conversation, you’ll know that the developers in question are referring to the same programming strategy – just in a different way.

So Why Does This Matter in WordPress?

Just as design patterns in non-WordPress specific projects, such as larger applications, the design patterns provide a tried and true way to solve a common problem.

It helps to abstract our code a bit, keep our project easily maintainable, easily readable, and can actually help us to keep our code lean. This may result in us actually having more files in our project, but each file should have fewer lines of code.

This means that each file should have a specific purpose that should be clear, not only to us, but future developers as well.

/>

What It Looks Like

Now, before we dive into the diagrams, talking about classes, and the strategies required to implement the actual pattern, I want to mention that we’re going to be taking a simple approach to this.

The thing is, the readership of this blog spans a wide array of experiences – we have some people who are learning to write code; others who are seasoned veterans.

In order to appeal to the majority of the readership, we need to strike a balance. So for those of you who have been involved with software engineering for years, this may seem overly simplistic; however, don’t skim it – perhaps you’ll pick up something new.

For those of you who are beginners or even intermediate programmers, pay close attention to what we’re discussing as it can provide dividends in future (or even existing) work.

The Purpose of the Simple Factory

So imagine this scenario: You’re working on a function that takes in a set of input – usually some type of unique string or integer – and you have this long if/else statement or perhaps you have this large switch/case statement that continues to grow as your project grows.

The problem is that the conditionals become a pain to manage. In fact case conditionals, or the case blocks, may actually end up doing as much work as a certain function should do.

This is where the Simple Factory comes into play. What we can do is abstract the details happening in each of the conditionals into their own class thus making it much easier to maintain and keeping the code much leaner.

And that is the Simple Factory Pattern.

A Look at the Pattern

The Simple Factory Pattern

So here are the key features of the Simple Factory Pattern:

  • Notice that the Plugin class has a private reference to the Factory class
  • The Factory class encapsulates all of the logic to return an object of the type User
  • The User class is a base class for three other classes: Admin, Volunteer, Reader, and the idea is that each of these types are subclasses of users with unique functionality of their own
  • The Plugin will receive a certain type of input that it will pass to the Factory
  • The Factory will examine the input and then, based on its value, will return one of the three user types

Nothing too complicated, right? Honestly, I think that the diagram is a bit more complicated than the principles at play. It really provides a lot of flexibility especially whenever you’re looking to introduce another User type like an Editor or something similar.

Note: This is not to be confused with WordPress’ built-in user types. This is simply an example to show what the pattern would look like.

A Working Example

Now that we’ve taken a look at the diagram for the pattern, let’s take a look at the source code in action. Below, we’ll look at the source code for each class and then I’ll provide a download to a fully documented demo after the discussion.

The Plugin

First, let’s look at the plugin class. Remember, this is nothing more than a prototype of what the pattern looks like. It’s not the same thing as a fully developed WordPress plugin.

factory = new Simple_Factory();
	

	public function get_user( $permission ) 
		return $this->factory->get_user( $permission );
	

}

?>

Notice that the plugin is relatively simple:

  • It includes the simple-factory.php script in the header of the file
  • It then defines a constructor in which it sets the $factory property to an instance of the Simple_Factory
  • The only method available in the plugin is get_user which returns a user based on a type

We’ll see how this comes into play after we’ve examined all of the other classes.

The User

The User is an abstract base class that provides a basic constructor and an abstract function that must be implemented by all other subclasses.

role = $role;
	

	abstract public function get_role();

}

?>

Note that this class is intended to be subclassed by a variety of other classes, each of which we’ll look at in detail momentarily.

The Administrator, The Reader, and The Volunteer

The following four classes are all separate files each of which subclass the User base class. I’ve opted to include them all here together because there’s so little deviation from their actual implementation that it should be easy enough to follow.

The Administrator
role = "Administrator";
	

	public function get_role() 
		return $this->role;
	

}

?>
The Reader
role = "Reader";
	

	public function get_role() 
		return $this->role;
	

}

?>
The Volunteer
role = "Volunteer";
	

	public function get_role() 
		return $this->role;
	

}

?>

As usual, leave me questions in the comments; otherwise, review the code then be sure to read up on The Simple Factory which is the next section – it ties all of this together.

Also, remember that all of this code will be shared at the end of the article along with code comments that describe exactly what’s happening.

The Simple Factory

The Simple_Factory class is really the crux of the entire pattern. Here is where all the decisions are made and the appropriate objects are returned.


Note that the Simple_Factory includes the base user class and its subclasses and then works to return the appropriate type of user based on the incoming set of permissions.

/>

The Advantages of the Simple Factory Pattern

Though it should be a bit obvious by this point in the article, the Simple Factory Pattern provides a number of advantages especially if you’re used to working with large conditionals.

  • It provides an elegant way to abstract your code so there’s less visual clutter
  • It allows you to introduce specialized, focused classes with a single purpose (which is great if you follow the SOLID principles)
  • It makes the code more maintainable as there’s a single place where classes are instantiated, and each class serves a single purpose

Overall, this is one of my favorite patterns simply for the matter of code organization and specialization that it can bring to the table.

/>

Conclusion

Finally, you can checkout the entire source code – complete with documentation and installation instructions – on GitHub using this link.

At this point, we’ve taken a look at three patterns:

  1. The Observer Pattern
  2. The Singleton Pattern
  3. The Simple Factory Pattern

This series could go one for a while; however, I think that we’ve covered enough ground at least to get many of us started with implementing patterns into our work.

So in the last article in the series, we’ll recap what we’ve learned and I’ll also recommend some other patterns, their purpose, and some further points of research that should continue to aid you in continuing to learn about design patterns and their advantages not only in WordPress development, but general software development, as well.

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

Quick Tip: After the Content – More From This Category

May 7th, 2013 Comments off

This entry is part 6 of 6 in the series After the Content

Do you have a solid construction of categories on your blog? If so, you might not need a “Related Posts” section at all – you can just display latest posts from the same category.

In this post, we’re going to go through the “More From This Category” section, an alternative to “Related Posts” (which we covered earlier).

/>

Show You Have More to Say

If you keep your posts organized well with categories, you might find it useful to have a list of posts from the post’s category.

“Related Posts” is not always the answer: If you have a website where the posts are separated with categories, a “Related Posts” section might “break” this separation.

For example, if you have a blog about different occupational groups, you can’t show news about the textile sector as “Related News” under a post about informatics. A number of latest posts from the same category would be more relevant, right?

Creating a “More From This Category” List

As you may have guessed, listing latest posts from a post’s category will be much easier than displaying related posts based on a post’s tags. We just need to get the category of the post and list a number of posts from that category, excluding the post that the visitors have just read. The arguments that we can pass in the get_posts() function has everything we need.

ID );
    $first_cat = $categories[0]->cat_ID;
    // Let's start the $output by displaying the title and opening the 
    $output = '

    ' . $title . '

    '; // The arguments of the post list! $args = array( // It should be in the first category of our post: 'category__in' => array( $first_cat ), // Our post should NOT be in the list: 'post__not_in' => array( $post->ID ), // ...And it should fetch 5 posts - you can change this number if you like: 'posts_per_page' => 5 ); // The get_posts() function $posts = get_posts( $args ); if( $posts ) $output .= '
      '; // Let's start the loop! foreach( $posts as $post ) setup_postdata( $post ); $post_title = get_the_title(); $permalink = get_permalink(); $output .= '
    • ' . $post_title . '
    • '; $output .= '
    '; } else // If there are no posts, we should return something, too! $output .= '

    Sorry, this category has just one post and you just read it!

    '; // Let's close the
    and return the $output: $output .= '
    '; return $output; } ?>

Done! You can include this function inside your functions.php file (or save it as a separate plugin) and echo it (as ) anywhere you want inside your single.php file.

/>

Conclusion

Yes, content may be “king” but a lonely king is a weak king, and people might not respect that “king”.

Do you think there are more page elements that can help “the king”? Post your comments below – it’s always important for you to share your thoughts with us!

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

Developing Plugins With a Distributed Team

April 16th, 2013 Comments off

Recently, I had the opportunity to build a plugin with two other developers – Pippin Williamson and Andrew Norcross. We came up with the idea via Twitter, scoped it via email, and built it using GitHub using its tools all prior to releasing it.

I know – the title of this post sounds all too familiar especially given the global economy in which we all live today. After all, many of us work from our home offices, coffee shops, or wherever else while the home base of our company is located elsewhere.

But this is a different type of distributed team.

First, let’s acknowledge that when it comes to building software in the WordPress space, we’re extremely fortunate to be able to do so by ourselves, with a couple of friends, or within the context of a team in a corporate environment.

Even though WordPress itself is built by a lot of people all over the world, you don’t often see the same experience being pulled through with themes or plugins. This isn’t to say that it’s never done (because it is), but it appears that it’s done less so.

Now, the purpose of this post is not to promote the aforementioned plugin, but it’s more of a call to action for us to find more creative ways to build publishing products with teams – namely, our “Internet friends” or tweeps – with whom we may not have previously worked.

But there are a few learnings that have come from this process that I think are worth sharing for the sake of helping others get into experimenting with developing projects with fellow tweeps.

/>

Scope Is Key

Simply put, locking in the scope is part of identifying the core features of your plugin. When you first start out, it’s important to be able to succinctly state what your product is going to do.

In our case, we said:

We want to make it easy for people to identify what comments need a reply from the post’s author.

What this does is allow you to define a grid – or a scope – through which all potential features can be filtered. If it doesn’t fit in with the core idea of the plugin, then it’s not fit for the first release.

That said, this feels almost like it’s a bit cliche because it should be expected for any software project: identify the scope, lock it in, and then aim for it.

But when you’re working with a group of friends on a free project, this can become increasingly easy to ignore.

Case in point: As a single developer, how often have you thought to yourself: “That’d be a cool feature to build!” And then, because you had no one to really hold you accountable to build it, you were able to achieve it.

This isn’t to say that’s wrong – it may be, it may not be – I don’t know the specifics of your project; however, if you’re working with a team on a project, taking time to work on something that is outside of the scope is time wasted that can ultimately detract from the core of the plugin. Furthermore, it can hold up your peers’ development time while they wait for your feature to be complete especially if there’s a dependency on your work.

Finally, if you get a group of developers together to build something for the fun of it, the project may never get done because you’ve taken the idea of “wouldn’t this be cool,” and multiplied it by however many are on your team.

The point is that even though you’re running the project with friends, you’ve got to scope the project lean, and scope the project early; otherwise, you’ll never be done.

/>

Delivery Date Matters

And this brings us to the second point: Despite the fact that you have no one “above you” holding you accountable to your delivery date, you still have an obligation to yourselves, your scope, and those who may be waiting for the product to complete development.

Granted, there’s always the argument that can be made that since people aren’t paying, then they have no real demand on when something should be finished; however, if you’ve set a date, there’s a level of integrity that should be matched when aiming to deliver your work.

What’s a plugin that @nocross and I could build during #wcmia and release for free? #WordPress

— Pippinsplugins (@pippinsplugins) February 13, 2013

To that end, it’s important that you set a delivery date – however arbitrary it may be – and then set milestones to make sure the pace of development matches that date.

For example, Pippin, Andrew, and I scoped the plugin in February and aimed to have the plugin completed in April by the end of one of the WordCamp events. Sure, the deadline was somewhat arbitrary, but it kept us honest not only in our own development efforts, but it allowed us to hold one another accountable for our own specific tasks.

This means that if I was dragging my feet, Pippin or Andrew could call me on it (of course, it works all around).

/>

Keep It Open

GitHub Repository

Finally, working with friends is great especially when you’re unified around the same vision. It allows you to get more done faster since the work can be spread across more than a single person.

But the nice thing about software is that it can be open sourced. This means that if others are not only interested in the project, or are bought into the vision, they can even contribute to it.

But here’s the thing, software is inevitably going to breed two things:

  1. Bugs
  2. Feature Requests

Using tools such as GitHub allows the plugin’s user base – be it users, developers, or designers – to voice their issues and/or feature requests in a centralized way.

Furthermore, it allows the core team to not only assign each set of issues to their own milestones, but it allows for other contributors who are also brought into the vision know exactly how they can contribute. There’s no guesswork. There’s no “hey, maybe we could do this!

Instead, there’s a list of issues and requests that are needed (permitting the list is kept up to date) so that contributors know they are ultimately improving the product – not just blindly adding something because they think it would look good.

Of course, this isn’t limited to GitHub: Whatever source control system and ticket system you opt to use, make sure it’s something that makes it easy for others to interact and others to view outstanding issues. The last thing contributors need is yet-another-hurdle for contributing to your project.

/>

Conclusion

So there you have it: Three points to working on products with a distributed team outside of the typical organized environment.

Simply put, make sure that you scope your project, stick to your delivery date, and allow others to contribute who are interested. By doing this, you’re making it easy not only for your current team, but your future contributors to improve the product.

Finally, I’ve avoided discussing the plugin that Pippin, Andrew, and I built specifically because I wanted this post to be about the process, not the product; however, now that we’ve covered the former, you can find the latter here on GitHub. If you’re interested, feel free to leave us issues, notes, or even pull requests!

Original from: http://feedproxy.google.com/~r/Wptuts/~3/L-j-NNeAuik/

Best of Tuts+ in March 2013

April 11th, 2013 Comments off

Each month, we bring together a selection of the best tutorials and articles from across the whole Tuts+ network. Whether you’d like to read the top posts from your favourite site, or would like to start learning something completely new, this is the best place to start!

/>

Psdtuts+ — Photoshop Tutorials

  • Create a Heroic Firefighter Painting in Photoshop

    Firefighters do so much to help keep us safe. In this tutorial, we will honor our firefighters by creating a digital painting that depicts a firefighter coming to the rescue. Let’s get started!

    Visit Article

  • Why You’re Not as Popular as You Should Be

    With so many artists competing for the same work, getting noticed can be a challenging task. As the editor of Psdtuts+, I have had the opportunity to interact with some exceptionally talented artists and designers from all over the world. This proximity to so many artists has given me a unique perspective, and over the years, I have been able to make a lot of observations about what it takes for artists to increase their visibility and to raise their online profiles. In this article, I wanted to share several reasons why you might not be getting as much attention as you should.

    Visit Article

  • Create an Adorable Children’s Illustration

    What child wouldn’t love a real-life teddy bear to have as a friend? In this tutorial, we will show you how to create an adorable children’s illustration using digital painting techniques in Photoshop. Let’s get started!

    Visit Article

/>

Nettuts+ — Web Development

  • Round Table #1: Should Exceptions Ever be Used for Flow Control?

    I’m pleased to release our first ever round table, where we place a group of developers in a locked room (not really), and ask them to debate one another on a single topic. In this first entry, we discuss exceptions and flow control.

    Visit Article

  • Pro Workflow in Laravel and Sublime Text

    Not too long ago, I built a handful of generators for Laravel, which ease the process of various tasks. Today, thanks to help from Gaurav Narula, we’re turning things up a notch with the release of a new Sublime Text plugin that leverages the power of Artisan and the generators from directly within your editor.

    Visit Article

  • The Command Line is Your Best Friend

    The command line can either be your best friend, or your worst enemy. It simply depends on how you use it, and what you use it for. If you’re one of the many people who cringe at the mere thought of using the command line, then you’ve come to the right place!

    Visit Article

/>

Vectortuts+ — Illustrator Tutorials

/>

Webdesigntuts+ — Web Design Tutorials

  • Your Logo, as a Web Font Ligature

    Let’s look at an alternative approach for displaying logos on a web page. Normally, you’ll approach the challenge by using an img tag. Perhaps you’ll use image replacement through CSS, perhaps you’ll even venture into SVG files, but have you considered what’s possible by designing your own web font ligature?

    Visit Article

  • How They Did It: The Accessibility Project

    Perhaps you, or someone you know, has experienced the difficulties of computer interaction for the impaired. In general, operating systems and software suites have made provisions for accessibility for hearing-impaired audience, vision-impaired audience, and internationalization; however, the open web hasn’t caught up as quickly. Many sites ignore accessibility completely.

    Visit Article

  • Fireworks in the Real World

    There’s a very good chance you know what Adobe Fireworks is, especially if you regularly use Photoshop or any of the other Adobe products. There’s an equally good chance you’ve never really taken the opportunity to see how it can help your web design workflow, even if you’ve always meant to. This session is here to put that right. Follow Leigh Howells as he demonstrates exactly what Fireworks can do for you in the real world.

    Visit Article

/>

Phototuts+ — Photography Tutorials

  • How to Shoot Video on Your Canon Rebel

    The explosion of filmmaking since its democratization in 2008 has meant increasingly cheap ways of exploring the possibilities of motion pictures. One of the most popular cameras in recent times for beginners to start shooting on is the Canon Rebel series. Today, I’m going to take a look at the basics of getting your Rebel rolling, and provide some ideas on how to improve and develop those first attempts.

    Visit Article

  • How to Turn a Photograph into a Dynamic Panograph

    Panography was created to depict the way we naturally see. The way our eyes pick up on the details of a place or subject, then arrange them into a single image. The scale of detail you choose to create depends on the final image you see. Today, we’re going to take the style and techniques of panography and apply it to images we’ve already taken.

    Visit Article

  • Understanding & Using Ansel Adam’s Zone System

    The Zone System is an approach to a standardized way of working that guarantees a correct exposure in every situation, even in the trickiest lighting conditions such as back lighting, extreme difference between light and shadow areas of a scene, and many similar conditions that are most likely going to throw off your camera’s metering giving you a completely incorrect exposure.

    Visit Article

/>

Cgtuts+ — Computer Graphics Tutorials

/>

Aetuts+ — After Effects Tutorials

  • Make a Magnificent Magnifying Glass That Really Works

    In this tutorial we are going to create a beautiful Magnifying Glass in After Effects. Using just one null object as a Controller we will be able to change all the parameters: Size, Distance, Rotation, Blur, Shadow, and Background. Everything is going to be automatic, and this will save you a bunch of time when animating!

    Visit Article

  • Download A Free Tool for Making Animated Alphabet Blocks

    Do you want to create a fun video for kids in just a few minutes? Check out this free After Effects® project file that will help you create words in any language and animate them in a colorful way. The project template is set up with a visual interface that makes it easy for beginner After Effects® users to customize. Take a look at the video tutorial for an overview of the template options, and get ready to spark your viewer’s imagination!

    Visit Article

  • How to Animate Retro Pixel Art in After Effects

    Pixel drawings are really small compared to an HD video canvas. This tutorial explores the common failure points when bringing your pixel artwork into a 1080p comp in After Effects. Scaling and looping are covered as well as a workflow for preparing your frames for animation in the free sprite editor ASEprite and Adobe Photoshop.

    Visit Article

/>

Audiotuts+ — Audio & Production Tutorials

  • Mixing With Headphones

    For some people it is not practical to use loudspeakers to mix their music tracks. It might be that their neighbours are easily disturbed, or their acoustic environment is not up to scratch. Despite the fact it is not usually recommended, many people make decent mixdowns using only headphones.

    Visit Article

  • Extracting MIDI from Audio in Ableton Live 9

    Ableton Live 9 has arrived, and among its new features is the ability to convert melody and drums into MIDI. In this tutorial we show you how to use these features, as well as some of their limitations.

    Visit Article

  • Setting Up Your MIDI Controller Inside Studio One

    Studio One 2.5 is quickly becoming my go to DAW in my studio. If you are new to Studio One or are using the free version PreSonus has made available, I want to show you how you can quickly set up you MIDI controller inside of Studio One, if it is not in the list of preset devices.

    Visit Article

/>

Wptuts+ — WordPress Tutorials

  • Check Out the New Recommended Resources on Wptuts+

    We’ve added a new page to the site, which will help WordPress pros grab top quality software, tools and services. It’s filled with our favorite WordPress resources. You can jump straight over to our Recommended Resources page here on Wptuts+ or read on for further information.

    Visit Article

  • A Beginner’s Guide to Enqueuing jQuery

    In this post, we’re going to review a few concepts around jQuery and WordPress to make sure that we, as developers, are not only working to build our products correctly, but that we also know how to properly diagnose problems as they arise in our customer’s sites.

    Visit Article

  • Cross-Site Scripting in WordPress: What Is XSS?

    In this two part series, we’re going to take a look at what cross-site scripting really is, its dangers, how it impacts WordPress development, and then practical steps that we can take for testing our themes and plugins.

    Visit Article

/>

Mobiletuts+ — Mobile Development Tutorials

  • Geofencing with Core Location

    With the release of iOS 4, the Core Location framework received a significant update by providing support for geofencing. Not only can an application be notified when the device enters or exits a geofence, the operating system also notifies when the application is in the background. This addition to the Core Location framework fits neatly in Apple’s endeavor to support multitasking on iOS. This opens up a number of possibilities, such as performing tasks in the background through geofencing and that is exactly what this tutorial is about.

    Visit Article

  • Create an Unblock Puzzle Game – Interface Creation

    In this tutorial series, you’ll learn how to create an unblock puzzle game. The objective of the game is to clear the path for the square to get out. Read on!

    Visit Article

  • Decoding the iOS 6 SDK Available Now!

    Rockable Press is proud to present our latest release: Decoding the iOS 6 SDK. Written by five seasoned iOS experts and packed with almost 500 pages of essential iOS 6 development fundamentals, this great new eBook will quickly get you up to speed with the iOS 6 SDK and all the fundamental changes that occurred to Xcode and the iOS device landscape in 2012. Get your copy now!

    Visit Article

/>

Gamedevtuts+ — Game Development

  • 3D Primer for Game Developers: An Overview of 3D Modeling in Games

    Almost every major game released these days is made in 3D or uses a heavy amount of 3D assets. While there are still many games made in 2D, even platforms like Flash are now integrating 3D. In this bumper-length article I am going to explore what separates games from other mediums that use 3D art, and cover some of the important topics to consider when making 3D art for games.

    Visit Article

  • How to Learn Flixel

    Flixel is a free and open source 2D game development framework written by Adam “Atomic” Saltsman (Canabalt, Hundreds) in AS3 for making Flash games. It is a very mature, flexible and robust library. In this article, we’ll introduce you to the platform and its capabilities, and share tutorials, plugins, and suggestions to get you started developing games with it.

    Visit Article

  • From Zero to Pitch: A Walkthrough for Game Designers

    Would you believe me if I told you that after you finish reading and participating in the activities established in this article, you will have a game designed and ready to be developed? Yes, I know it sounds inconceivable, but trust me – this series of unconventional exercises will explain the workflow of designing a brand new game from zero to pitch.

    Visit Article

/>

Mactuts+ — Mac & OS X

  • Quick Tip: Combine PDF Files in Preview

    Have you wondered if it was possible to merge similar PDF files together into one file without downloading third-party software? Well, turns out you can–and it’s really simple, too! In this screencast we show you how to easily merge your PDFs into one document using Preview.

    Visit Article

  • Go Paperless With Doxie

    If you’re wanting to reduce your paper clutter and digitise your old bank statements and receipts, a Doxie scanner is definitely the way to go. In this guide we’ll show you how to get the most from your Mac and Doxie.

    Visit Article

  • 9 Hazel Rules to Increase Your Productivity

    Hazel, a folder monitoring application, has long been a favorite among many a Mac enthusiast. Hazel will automatically take action on your files, using the rules you create, keeping your folders in order. If you’ve wished that all of your downloaded music or any other sort of files would just do what you wanted them to, using only the power of your mind, well, this is the next best thing. We’ll look step-by-step at how to create a rule from scratch and then set up nine rules you can customize for your needs.

    Visit Article

/>

Crafttuts+ — Craft & Handmade

  • Make Your Own Mini Macrame Succulent Egg Decorations for Easter

    I’ve been thinking about a simple and contemporary way to add a little Easter decoration to my home as I don’t really want bunnies and eggs everywhere! These mini succulent egg decorations fit the bill nicely for me with a bit of macrame, some dip-dying, cute succulents, and of course eggs.

    Visit Article

  • Transform an Old Sweater Into an Adorable Bunny Softie for Easter

    Do you have a favourite sweater that you can’t wear anymore because it (a) shrunk in the dryer; (b) got a stain or (c) developed a hole? If you can answer ‘yes’ to one (or more) of the above, don’t despair. With this tutorial you will learn how to transform and re-purpose an old sweater (or a charity shop find) into a very sweet Easter bunny plush. Let’s get started.

    Visit Article

  • The Prettiest Egg Decorations to Make This Easter

    Easter is just around the corner and this pretty project will inject some colour into your decor. In this tutorial you’ll learn how to dye brightly-coloured eggs and embellish them with sweet silhouettes. You can download our free silhouette pattern to make the project super-easy. Read on for the full instructions after the jump.

    Visit Article

/>

FreelanceSwitch — Freelance Jobs & Information

  • 40 Attention-Getting Post Topic Ideas for Your Freelancer’s Blog

    Blogging is not a hard-sell environment. Readers expect to get useful information in posts, not pitches to hire you. So what can you write about? Quick tip: Provide useful or interesting information your prospects can use, and your readers will keep coming back — and some may end up becoming your clients. Here are 40 specific ideas for quick-and-easy blog topics that will attract quality prospects and then keep them interested.

    Visit Article

  • Google+ Networking: Circles and Communities

    Social networking is all about staying in touch with friends and making new contacts. On Google Plus, you add friends by putting them into your circles. You meet new people by hanging out in Google Plus communities. /> In this article, I give you a freelancer’s guide to who you should add to your circles, how to meet new people in communities, and how to use communities and circles as a marketing tool.

    Visit Article

  • The Incentives that Will Convince Subscribers to Sign Up for Your Email Newsletter

    There are a lot of options on what incentives you can offer to potential readers. Before leaping in to creating any type of incentive piece, make sure you know exactly what will attract your audience. If necessary, survey a few of the people you’d most like to sign up for your list about what they really need.

    Visit Article

/>

Tuts+ Premium — Creative & Technical Skills

  • WordPress Widgets: Front To Back

    In this course, we’ll review the process of building custom WordPress widgets using the WordPress API and advanced development techniques. This course begins at ground zero, and assumes that you have no experience with WordPress widget development. Stick with me for a few hours, and you’ll learn a lot! Let’s get to it.

    Visit Article

  • Django Unchained

    In this course, join me, Christopher Roach, as I walk you through the creation of a simple Hacker News clone. Along the way, you’ll learn all the basics, including working with views, templates, the ORM, and even some of the more powerful features of the framework, like setting up the admin app and handling AJAX calls.

    Visit Article

  • Digital Drawing Fundamentals

    Whether you’re an ambitious illustrator or an experienced designer, almost everyone wants to improve their traditional drawing skills. Kirk Nelson is here to do just that! As an experienced digital painter and designer, Kirk walks you through the building blocks of digital drawing, shapes and shading, composing and perspective, and much more. Grab your tablet or stylus and let’s get started.

    Visit Article

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

A Beginner’s Guide to Enqueuing jQuery

March 21st, 2013 Comments off

One of the best things about WordPress is its vibrant economy. For many users, it’s trivially easy to find themes to fit the design for which they’re aiming, or to find plugins that provide functionality that they want to introduce into their site.

But how many of you – as developers or designers – have a received that phone call or that email in which the customer claims that something is wrong with their site only to discover that the browser console displays something about an error having to do with JavaScript or jQuery?

Exactly. Most likely anyone who has built and/or maintained a site for someone has come across this problem especially if the end user is given permission to add their own plugins, allow their own updates, etc.

In this post, we’re going to review a few concepts around jQuery and WordPress to make sure that we, as developers, are not only working to build our products correctly, but that we also know how to properly diagnose problems as they arise in our customer’s sites.

/>

A Word About Including JavaScript Files

This particular topic is not new to Wptuts+. In fact, we’ve written an extensive article about it before complete with a number of code examples all of which should provide you with everything that you need to understand how to work with JavaScript within WordPress.

But as we continue to observe certain practices going on in the community that we’d love to help resolve, we don’t mind covering multiple facets of the same topic.

So, before reading this article, make sure that you’re familiar with how to include JavaScript and CSS in your WordPress themes and plugins.

/>

WordPress as a Foundation

When it comes to building products in WordPress, one of the things that we, as developers, need to try to do is to treat the WordPress application as a foundation.

Right now, the API allows us a massive amount of flexibility when it comes to building themes, plugins, and applications, and this is a good thing.

But when we begin to remove libraries that ship with WordPress in favor of our own, it’s almost as if we’re creating a “mini-fork” of the project.

This isn’t a good practice to adopt.

As far as I’m concerned, WordPress ships with its core set of functions and libraries that allow it work the way that it does. Changing out crucial parts of the application – such as jQuery – doesn’t only affect WordPress itself, but the entire ecosystem of products that are built on top of it.

Good themes and plugins depend on the presence of those libraries. When we change that functionality, we potentially break every piece of work that’s depending on them.

We need to stop viewing WordPress as something that we can take apart and reassemble as we need it, and view it as a foundation off of which to build our own unique work.

/>

Why the Problem of JavasScript Conflicts Exist

Generally speaking, the problem of JavaScript conflicts exist for one of three reasons. A developer has either:

  1. Improperly managed jQuery in their code
  2. Swapped the version of jQuery in favor of another version
  3. Changed the order in which jQuery is loaded

First, any of the above three cases could all be done at once, but more often than not its one of the above. Secondly, I don’t think that developers typically do this with ill-intent.

I think it’s more of a lack of education and/or understanding of the consequences.

1. Improperly Managing jQuery

By this, I mean that the developer has improperly gained access to the jQuery library either by executing noConflict, not properly returning the variable to its original state, or simply renaming the short cut function.

Later in this article, we’ll take a look at the best practice for how to write WordPress-specific jQuery so that it allows us to take full advantage of the library without conflicting with other plugins, themes, or projects.

2. Swapped Versions of jQuery

This is something that is often done with good intent: The idea is that the developer is providing an update to the version of jQuery that’s included with WordPress so that new features or more modern jQuery can be written.

The problem with doing this is that previously developed projects aren’t written with some of the newer features of the latest version of jQuery. Also, if jQuery has deprecated or completely removed a function in the new version that was present in the old version, then it will prevent that code from working.

3. Change the Order in Which jQuery Is Loaded

Though this is a less common problem, it’s something that happens occasionally: In an attempt to help make a site load faster, developers will move the order in which jQuery is loaded further down the page, usually to the footer.

While loading JavaScript in the footer of a page is encouraged by a number of high profile sites, this goes back to thinking of WordPress, holistically, as a foundation for application development.

If WordPress, by default, loads jQuery in a certain location, then we need to remember to leave it there as all works that are built on top of the application are depending on it being in that location and nowhere else.

/>

How to Properly Include jQuery

Though there are a number of different ways that you can prepare your JavaScript source files to use jQuery, there’s one way that I tend to follow because it completely protects and encapsulates the $ function.

(function( $ ) 
	"use strict";

	$(function() 

		// Your code here

	);

}(jQuery));

You can also view the GitHub gist here.

In short:

This provides a properly loaded version of jQuery that uses the standard $ function reference to allow us to continue going about our work.

Note that the “use strict” statement provides the following:

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. This strict context prevents certain actions from being taken and throws more exceptions

For those who are interested, you can read more about that at this site.

Finally, the actual document.ready function is optional. Here, it’s used just to show how you can begin using the standard jQuery functions within the context of the code.

/>

Conclusion

Note that the next version of WordPress is planning to ship with a patch that will make this particular discussion obsolete, at least as far as the Dashboard goes.

Specifically, there is currently a ticket in Trac in which WordPress will not allow us to remove jQuery from the Dashboard. That’s a good thing.

In short, the main takeaways for this article are as follows:

  • Use the version that ships with WordPress
  • Gain access to the $ function using proper JavaScript facilities

I’d say that doing anything else is setting yourself up for potentially bad results.

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

Creating a Simple Instagram Plugin

March 4th, 2013 Comments off

In the following tutorial we will create a plugin to get the popular pictures from Instagram’s main feed.

/>

1. The Plan

Our plugin will work with the [instagradam] shortcode. You can insert it anywhere where HTML content can go eg. template code, editor code, etc.

As a result about 10-15 thumbnail pictures will be shown with clickable links. The core of the plugin is based around a remote feed, which we will retrieve using the Function API of WordPress.

The raw data list functionally will look like this:

/*
  theluxurystyle --- http://distilleryimage8.s3.amazonaws.com/c4c876f4780a11e2a15422000a9f19a4_5.jpg
  loveobe --- http://distilleryimage3.s3.amazonaws.com/0c2d3b20781911e2b92122000a9e0727_5.jpg
  jaredleto --- http://distilleryimage8.s3.amazonaws.com/21d07bce781c11e2adc122000a1f9ace_5.jpg
  balloop --- http://distilleryimage11.s3.amazonaws.com/4fe04e66781411e2890222000a1fb0b2_5.jpg
  pinkshosho --- http://distilleryimage10.s3.amazonaws.com/abaef1b4781b11e2a2ce22000a1fa411_5.jpg
*/
This is our plan />We will pull in some pictures
/>

2. Getting Client ID and Secret

This step is needed for every new plugin. Register it at Instagram to get a client_id and client_secret. The plugin name should be simple alphabetical characters in my experience (eg. johnsplugin).

/>

3. Plugin Information

This is the place to describe your plugin’s base data like plugin name, url, version number, and author.

/*
Plugin Name: Instagradam
Plugin URI: http://wp.tutsplus.com/
Description: A simple and fast Instagram shortcode plugin. Please use [instagradam] to pull main feed!
Version: 1.0
Author: Adam Burucs
Author URI: http://burucs.com/
*/
/>

4. Registering the Shortcode

This will define the [instagradam] shortcode, which will work based on the instagradam_embed_shortcode function.

	// register shortcode
	add_shortcode( 'instagradam', 'instagradam_embed_shortcode' );
/>

5. Defining Main Function for the Shortcode

This will describe our plugin’s core operation. The $atts and $content should be defined as we see here, but we won’t use them in this lesson.

	// define shortcode
	function instagradam_embed_shortcode( $atts, $content = null ) 

		// ...

	
/>

6. Making Variables

We need a helper variable for making an output for our function and a data retrieval which uses the WordPress Function API. That is $str and $result, respectively.

		// define main output
		$str    = "";
		// get remote data
		$result = wp_remote_get( "https://api.instagram.com/v1/media/popular?client_id=3f72f6859f3240c68b362b80c70e3121" );
/>

7. Handling Feed Errors

The main selection handles the feed error (in some cases we can get SSL errors, but there is a fix for that described later in this article).

If there is any error we echo it to the page: Something went wrong: ... .

	if ( is_wp_error( $result ) ) 
		// error handling
		$error_message = $result->get_error_message();
		$str           = "Something went wrong: $error_message";
	 else 
		// processing further
		// ...
	
/>

8. More Variables

Variable $result will contain the main data, for processing we make another helper called $main_data. We also need a counter for the iteration.

// processing further
$result    = json_decode( $result['body'] );
$main_data = array();
$n         = 0;
/>

9. Looping, Part One

This loop will collect all usernames and thumbnails we need. Previously I analyzed the main feed (the structure of the feed), to discover how to get the data I want. So this is an important step and also let’s not forget that Instagram can change this later /> and we might need to modify $d->user->username and $d->images->thumbnail->url.

	// get username and actual thumbnail
	foreach ( $result->data as $d ) 
		$main_data[ $n ]['user']      = $d->user->username;
		$main_data[ $n ]['thumbnail'] = $d->images->thumbnail->url;
		$n++;
	
/>

10. Looping, Part Two

In the following lines, we create the HTML code which will contain the pictures and links from the Instagram main feed. The links will open in a new window, made with target="_blank". Note the space at the end of the main string, this is for basic separation.

	// create main string, pictures embedded in links
	foreach ( $main_data as $data ) 
		$str .= ''.$data['user'].' pictures ';
	
/>

11. The Easy Part

This (shortcode) standard code will return our main content.

	return $str;
/>

12. SSL Problems

In some cases the wp_remote_get function can work badly, to solve this we need to use this code before the main code sections.

	// fix SSL request error
	add_action( 'http_request_args', 'no_ssl_http_request_args', 10, 2 );
	function no_ssl_http_request_args( $args, $url ) 
		$args['sslverify'] = false;
		return $args;
	
/>

13. Complete Code

The finished code looks like this.

/*
Plugin Name: Instagradam
Plugin URI: http://wp.tutsplus.com/
Description: A simple and fast Instagram shortcode plugin. Please use [instagradam] to pull main feed!
Version: 1.0
Author: Adam Burucs
Author URI: http://burucs.com/
*/

	// fix SSL request error
	add_action( 'http_request_args', 'no_ssl_http_request_args', 10, 2 );
	function no_ssl_http_request_args( $args, $url ) 
		$args['sslverify'] = false;
		return $args;
	

	// register shortcode
	add_shortcode( 'instagradam', 'instagradam_embed_shortcode' );
	
	// define shortcode
	function instagradam_embed_shortcode( $atts, $content = null ) 
		// define main output
		$str    = "";
		// get remote data
		$result = wp_remote_get( "https://api.instagram.com/v1/media/popular?client_id=3f72f6859f3240c68b362b80c70e3121" );

		if ( is_wp_error( $result ) ) 
			// error handling
			$error_message = $result->get_error_message();
			$str           = "Something went wrong: $error_message";
		 else 
			// processing further
			$result    = json_decode( $result['body'] );
			$main_data = array();
			$n         = 0;

			// get username and actual thumbnail
			foreach ( $result->data as $d ) 
				$main_data[ $n ]['user']      = $d->user->username;
				$main_data[ $n ]['thumbnail'] = $d->images->thumbnail->url;
				$n++;
			

			// create main string, pictures embedded in links
			foreach ( $main_data as $data ) 
				$str .= ''.$data['user'].' pictures ';
			
		}

		return $str;
	}
/>

Finished Look

This is a picture showing the plugin in action. For this, the shortcode was inserted in an article.

Finished plugin, how it looks in browser />How it looks in a browser

Original from: http://wp.tutsplus.com/tutorials/plugins/creating-instagram-plugin/

Incorporating the jQuery Date Picker Into the Post Editor: Preparing the Plugin

February 26th, 2013 Comments off

This entry is part 1 of 1 in the series Incorporating the jQuery Date Picker Into the Post Editor

We cover a lot of topics on this blog – anything ranging from something as simple as how to include and require template files in WordPress projects to something such as an entire series on the Settings API, but I think there’s always room to cover a straightforward How-To that covers a single, specific task within the context of WordPress.

So, in this two-part series, we’re going to take a look at how to introduce a jQuery date picker into our post editor so that we can associate a date with a given post.

/>

About the Plugin

We’ll be doing all of this within the context of a plugin so that the source code will be easily downloadable via GitHub and will provide a working example of the tutorial.

The first thing to note is that incorporating the jQuery date picker is not meant to replace the publish date of the post. Instead, it’s meant to provide an easy way to select a date, save it in the post meta data, and then display it for another purpose such as, say, when an event is going to occur.

/>

Planning the Plugin

For anyone that’s read any of my previous posts, you know that I’m a fan of planning the project from the outset, then implementing each step at a time to make sure we’re clear on everything that’s happening.

So let’s do that now:

  • We’ll provide the skeleton class for the plugin
  • We’ll write the code responsible for generating the post meta box that allows the user to select the date
  • We’ll implement the jQuery date picker so users can actually select a date
  • We’ll save the data when the post is published and/or updated
  • We’ll display the date on the front end of the post

Straightforward, right? With that said, let’s get started.

/>

Building the Plugin

At the end of this article, the entire plugin will be available in this GitHub repository, but I highly recommend following along and writing the code yourself to make sure you follow everything that we’re doing.

The code will be commented so it should be easy to follow. If not, always feel free to leave comments after the post.

1. Stub Out the Plugin Class

Assuming that you’ve already created the WordPress-jQuery-Date-Picker directory in your wp-content/plugins directory, go ahead and create two files:

  • plugin.php
  • README.txt

We’ll revisit the README file in a bit, but let’s go ahead and stub out the class that serves as our plugin.

Here’s the code with more explanations after the snippet:


Obviously, there’s not much to it, yet. We’ve simply defined the class, set an empty constructor, and instantiated the plugin outside the class.

Before we move any further, let’s go ahead and prepare the plugin for localization. To do this, we need to do several things:

  • Introduce a lang directory
  • Add lang/plugin.po
  • Set the text domain for the plugin within the constructor

Remember that localization is used to be sure that translators can make our plugin compatible with other languages, and that Poedit is the tool of choice.

The plugin.po file should contain something like the following (yours will obviously be different based on the date, the time, and the configuration of Poedit):

msgid ""
msgstr ""
"Project-Id-Version: WordPress jQuery Date Picker 1.0n"
"Report-Msgid-Bugs-To: n"
"POT-Creation-Date: 2013-02-07 13:36-0500n"
"PO-Revision-Date: 2013-02-07 13:36-0500n"
"Last-Translator: Tom McFarlin n"
"Language-Team: Tom McFarlin n"
"Language: en_USn"
"MIME-Version: 1.0n"
"Content-Type: text/plain; charset=UTF-8n"
"Content-Transfer-Encoding: 8bitn"
"X-Poedit-KeywordsList: __;_en"
"X-Poedit-Basepath: .n"
"X-Generator: Poedit 1.5.5n"
"X-Poedit-SearchPath-0: ..n"

Next, we need to set the text domain in the constructor. First, include the following line in your constructor:

// Load plugin text domain
add_action( 'init', array( $this, 'plugin_textdomain' ) );

Next, add the following function to your file:

/**
 * Loads the plugin text domain for translation
 *
 * @version		1.0
 * @since 		1.0
 */
public function plugin_textdomain() 
	load_plugin_textdomain( 'wp-jquery-date-picker', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
 // end plugin_textdomain

The most significant thing to note here is the use of the wp-jquery-date-picker key as this is what we’ll be using to localize the strings throughout the remainder of the plugin.

Finally, we’ll revisit this along with the README file later in the tutorial.

2. Create the Meta Box

At this point, we’re ready to define the code that will render the meta box. This consists of several steps:

  • Defining the hook in the constructor
  • Register the meta box with WordPress
  • Defining a function used to render the actual meta box

In the constructor, add the following line of code. This is what we’ll be using to register our post meta box:

add_action( 'add_meta_boxes', array( $this, 'add_date_meta_box' ) );

In the function above, we’re telling WordPress to look for our date meta box in a function called add_date_meta_box, so we need to define that now.

Within your class, add the following code:

 /**
  * Registers the meta box for displaying the 'Date' option in the post editor.
  *
  * @version	1.0
  * @since 		1.0
  */
 public function add_date_meta_box() 

	 add_meta_box(
	 	'the_date',
	 	__( 'The Date', 'wp-jquery-date-picker' ),
	 	array( $this, 'the_date_display' ),
	 	'post',
	 	'side',
	 	'low'
	 );

  // end add_date_meta_box

We’ve covered meta boxes in depth in various tutorials and the WordPress Codex has a terrific article explaining what each parameter does, so I don’t want to belabor the point here.

That said, there’s one specific thing that we need to notice in the call above. Note that the meta box is looking to register its display using a function called the_date_display.

As such, we need to define this function. Luckily, the meta box can be very simple: In order to trigger the date picker, we only need a single element. Since we’re going to be rendering the date, let’s opt to use a simple input box.

Next, add the following function to your class:

/**
 * Renders the user interface for completing the project in its associated meta box.
 *
 * @version 1.0
 * @since   1.0
 */
public function the_date_display( $post ) 

	wp_nonce_field( plugin_basename( __FILE__ ), 'wp-jquery-date-picker-nonce' );

	echo '';

 // end the_date_display

Easy to understand, right?

We define a nonce value for security purposes giving us the security features we need to make sure that the user has permissions to save values for this field, and then we render an input element to the screen.

Note that the input element includes an ID of “datepicker” and a name of “the date.” This will be imported later, but for now save your work.

If you activate the plugin right now, you should see something like the following:

Initial Date Picker

Obviously, this needs some light styling to make it look just a little bit better. So, let’s do the following:

  • Create a css directory
  • Add a css/admin.css file

In the file, include the following code:

#datepicker 
	width: 100%;

Then, in the constructor, add this line:

add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );

After that, add this function to your plugin:

/**
 * Registers and enqueues admin-specific styles.
 *
 * @version		1.0
 * @since 		1.0
 */
public function register_admin_styles() 
	wp_enqueue_style( 'wp-jquery-date-picker', plugins_url( 'WordPress-jQuery-Date-Picker/css/admin.css' ) );
 // end register_admin_styles

At this point, the width of the input box for the date picker should span the width of the meta box’s container. Makes it look just a little bit nicer, in my opinion.

3. Save the Date

Before we actually begin implementing the date picker, let’s go ahead and make sure that our new post meta box can properly save information. Right now, it’s not possible because we haven’t written the code for it.

This particular step will entail the following:

  • Defining a function for saving the data
  • Making sure that the user has the ability to save the data
  • Actually saving the data

First, we need to define the hook for saving the data. To this, add the following line to your constructor directly under the line where we defined the hook for creating the meta box:

add_action( 'save_post', array( $this, 'save_project_date' ) );
1

Next, we need to actually define the save_project_date function. This function is going to be responsible for making sure that the user has permission to save the data and then will actually save the contents of the input field in the post meta for the associated post.

So, add the following function to your plugin:

1
 /**
  * Saves the project completion data for the incoming post ID.
  *
  * @param		int		The current Post ID.
  * @version	1.0
  * @since 		1.0
  */
 public function save_the_date( $post_id ) 

	 // If the user has permission to save the meta data...
	 if( $this->user_can_save( $post_id, 'wp-jquery-date-picker-nonce' ) ) 

	 	// Delete any existing meta data for the owner
		if( get_post_meta( $post_id, 'the_date' ) ) 
			delete_post_meta( $post_id, 'the_date' );
		 // end if
		update_post_meta( $post_id, 'the_date', strip_tags( $_POST[ 'the_date' ] ) );

	 } // end if

 } // end save_the_date
 

This function works by basically checking to see if this user can save. If so, then it will delete any existing post meta so as not to clutter the database, then add the date specified to this post.

But there’s a catch: We’re making a call to a function called user_can_save. This particular function is a helper function that we need to define as it simplifies a lot of the boilerplate code necessary for making sure the user has permission to save the file.

So in the “Helper Functions” area of your class, add the following function:

 /**
  * Determines whether or not the current user has the ability to save meta data associated with this post.
  *
  * @param		int		$post_id	The ID of the post being save
  * @param		bool				Whether or not the user has the ability to save this post.
  * @version	1.0
  * @since		1.0
  */
 private function user_can_save( $post_id, $nonce ) 

    $is_autosave = wp_is_post_autosave( $post_id );
    $is_revision = wp_is_post_revision( $post_id );
    $is_valid_nonce = ( isset( $_POST[ $nonce ] ) && wp_verify_nonce( $_POST[ $nonce ], plugin_basename( __FILE__ ) ) ) ? true : false;

    // Return true if the user is able to save; otherwise, false.
    return ! ( $is_autosave  // end user_can_save

Notice that this function takes in the current Post ID and the nonce value (which we set earlier in this post). Finally, this function returns true if this is not an autosave, a post revision, and that the nonce is valid.

If it’s true, then the user has permission to save.

/>

Conclusion

At this point, let’s try out what we have. Activate the plugin, and you should see the meta box on the Post Editor dashboard. Right now, you should be able to save any value that you’d like in that particular field.

You can grab a copy of the plugin in its current version for this post using this link.

In the next article, we’re going to take a look at actually implementing the date picker. This will include importing the necessary JavaScript dependencies, writing a little bit of our own JavaScript, and then rendering the date on the front end of the post.

Finally, we’ll prepare the plugin for release by generating the localization files and then preparing the README.

Original from: http://wp.tutsplus.com/tutorials/plugins/incorporating-the-jquery-date-picker-into-the-post-editor-preparing-the-plugin/

Show Yourself Off With a Custom Author Box

February 25th, 2013 Comments off

Multi-Author blogs are becoming increasingly popular and with good reason. Creating regular, engaging content can often be a challenge for an individual blogger. With multiple authors it can be a lot easier and also allows you to cover a greater range of topics pulling from the knowledge of several people. On sites like Wptuts+ you get to read articles from a massive team of writers and bloggers, we all have our own writing style and personalities. Like Wptuts+, on most multi-author sites, you will find a nice little author information box somewhere on the page. Today I’m going to show you how you can create one for your very own site.

WordPress is a ready made multi-author blogging and content platform. All the tools we need are built in we just need to know how to use them.

/>

It All Starts With a Profile

Hidden away on the WordPress admin bar (when logged in) all users have access to the “Edit My Profile” link. It takes you to the page where you set how your name is displayed on the site, it’s where you change your password and email address. It’s also the place where you can enter really useful, modern and current contact information such as AIM, Yahoo IM and Google Talk details (/sarcasm). I know, because I do the same, you’ve always ignored most of it. If you don’t use these fields then why fill them in? Our author box is going to use these fields and we are going to make them a little bit more useful!

WordPress Profile Page
/>

Extra Fields

It is very easy for us to remove the contact methods we don’t want to use and replace them with something a little more current. So first things first you need to open up your theme’s functions.php (or stick this in a plugin if your prefer) and let’s get to work.

	function wptuts_contact_methods( $contactmethods ) 

		// Remove we what we don't want
		unset( $contactmethods[ 'aim' ] );
		unset( $contactmethods[ 'yim' ] );
		unset( $contactmethods[ 'jabber' ] );

		// Add some useful ones
		$contactmethods[ 'twitter' ] = 'Twitter Username';
		$contactmethods[ 'facebook' ] = 'Facebook Profile URL';
		$contactmethods[ 'linkedin' ] = 'LinkedIn Public Profile URL';
		$contactmethods[ 'googleplus' ] = 'Google+ Profile URL';

		return $contactmethods;
	

	add_filter( 'user_contactmethods', 'wptuts_contact_methods' );

So first thing we are doing is removing some fairly useless fields, next we simply add the additional fields we want. The first part needs to be unique for the text you can enter whatever you like as this is what will be displayed next to the field on the profile page.

If you revisit your edit profile page you should now see your additional fields have appeared and the useless ones have disappeared.

Profile with Custom Fields

Now we have somewhere we can store our additional information we can move on to working with the data and how we can show it in the front end of our site.

/>

Show Yourself Off

So we want to show a picture of our author, a little description / bio and some links to social media sites.

WordPress handles user profile pics using Gravatar. We want to use the WordPress Function get_avatar() this retrieves the Gravatar for the specified user ID or email address.

	

You can specify the size of the image and also what to do if the user doesn’t have a Gravatar. The final parameter allows you to set the Alternate text for the avatar. For now we are going to use the following code:

	

This pulls in the Gravatar at 70px x 70px and uses the user ID of the author for the current post.

We also want to pull some of the basic user profile information through like the user’s display name and description. Let’s have a look at a basic example.

/>

The Basics

	

The above code gives a nice starting point. Open up your single.php (I am using Twenty Twelve for the purposes of this article) and paste in the above code inside the loop but above your comments template. (Line 25 if you are using Twenty Twelve as well.) Now let’s go through what we’re doing.

We’ve already talked about the get_avatar() function but further down you will see the get_the_author() function. This simply retrieves the post author. In our example we print the author’s name at the top of our author box. It will display whatever the user has selected as their “Display name publicly as”. You could simply use:

	

However I prefer to escape all my output and allow the option for translators.

Next we see get_the_author_meta(). We’re going to be using this quite a bit. This function returns the desired meta data for the given user. If we use it within a loop we don’t need to specify the user ID however it can be used outside of the loop by passing the user ID. Using this function you can get a range of information, in the above example we are using it to pull the description which is the biography box you can complete on the user profile page. As with the author name I’m escaping the output to make sure our authors haven’t hidden any nasties!

Finally we have a link at the bottom which links through to our author page. We use the get_author_posts_url() function to simply give us the URL. WordPress automatically creates author pages for all users of the site who have published posts.

Let’s add some CSS and see how it looks:

	.media, .bd  overflow: hidden; _overflow: visible; zoom: 1; 
	.media img, .media .img  float: left; margin-right: 10px; 
	.media img  display: block; 
	.media .imgExt  float: right; margin-left: 10px; 
	.profile  margin-top: 10px; padding: 20px 10px; border: solid thin #c6c6c6; -webkit-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75); -moz-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75); box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75); 
	.profile-links  padding: 5px 0; 
Basic Author Box
/>

Social Shizzle Wizzle

So we’ve got a basic box, but what about all those extra fields we added? We can use the get_the_author_meta() function to retrieve those custom fields just as we did with the description. Let’s go through the following example together, a replacement for our previous “profile-links” div:

	

We’ve created an unordered list and each list item will be our extra fields we added at the start of the article. Firstly we do a crude check to make sure that there is a value entered for each of them as we don’t want links appearing that don’t do anything. Next we create a link based on the information entered in the user profile. As you can see from the example we form the link by using the same get_the_author_meta() function, however depending on what we are outputting we use a different validation function. For the Twitter link as we are only entering a username and appending that to our link we strip any HTML from it using wp_kses() for the others as we are entering full profile URLs into our profile page we are using esc_url() to ensure they are properly formed URLs. I’ve shown you two different ways of doing it so you can see how flexible it can be.

By adding a little more CSS we can style it and we’re almost done!

	.social-links li  padding: 5px; display: inline; list-style: none; text-indent: -9999px; float: left; 
	.social-links li a  background-position: 0 0; background-repeat: no-repeat; width: 16px; height: 16px; display: block; 
	.twitter-link  background: url( images/twitter.png ) no-repeat; 
	.facebook-link  background: url( images/facebook.png ) no-repeat; 
	.linkedin-link  background: url( images/linkedin.png ) no-repeat; 
	.google-link  background: url( images/google-plus.png ) no-repeat; 

The CSS I am using for demonstration purposes only you can of course do what you like with your own styling!

Author Box with Links
/>

Getting Fancy

Now we have our basic box we can add all kinds of extra features. We’re going to create a dynamic LinkedIn Profile Card when you hover over the LinkedIn icon.

First up we need to create some functions. We need to enqueue the LinkedIn JavaScript library on our blog posts and our author pages (more on this later!).

	function wptuts_linkedin_js() 
		if ( is_single() 

	add_action( 'wp_enqueue_scripts', 'wptuts_linkedin_js' );

Add the above code to your theme functions.php or wherever your added the code to change your contact methods. This will ensure we now have the required JavaScript loaded but only on pages where it is needed.

Next up we are going to create a little function to perform the hover functionality based on the author we are looking at:

	function wptuts_linkedin( $author ) 
		$authorinfo = get_user_meta( $author );
		$linkedin = $authorinfo['linkedin'][0];

		if ( isset( $linkedin ) ) : ?>
			
		

First thing you should notice is that we actually need to pass a parameter to this function when we call it. We want to pass the user ID of the author we want to create the hover card for. Essentially what we are doing is getting the user meta data using get_user_meta() we then pull out our LinkedIn URL that we created in the first half of the article. Then simply add that variable into our LinkedIn JavaScript so that it returns the correct user hover card. Here’s the updated single.php extract:

	

As you can see we call our LinkedIn function by using wptuts_linkedin( get_the_author_meta( 'ID' ) ) this passes through the user ID of the correct author to be used in our function. A couple of simple CSS tweaks to make it show properly:

	.linkedin-link  text-indent: 0 !important; 

As you can see now we have our author box with a nice hover card for our LinkedIn profile!

LinkedIn Hover Card
/>

Author Page

It’s often nice to show this author box at the top of an author’s archive page. Twenty Twelve already does some of the work for us in author.php. So we can add what we’ve learnt above to add our extra information.

	

WordPress Author Page
/>

Conclusion

So there we have it. You now know how to alter your contact methods, how to pull different information from a user profile and display it on their blog posts. There is so much more you can do depending on what you want to achieve. Try adding a link to the user’s website, display their latest Tweets, pull a commit history from GitHub; the options are endless. All the final code can be found below.

Vector Social Media Icons by IconDock.com & Double-J Design

URL: http://icondock.com/free/vector-social-media-icons

Original from: http://wp.tutsplus.com/tutorials/creative-coding/show-yourself-off-with-a-custom-author-box/

Strategies for Supporting WordPress Plugins

February 15th, 2013 Comments off

As a WordPress developer – specifically for plugins, in this case – determining the best way to provide support for your work can be a challenge. In fact, I’m currently in the process of evaluating what may be the best route for my current set of plugins, so this topic hits close to home.

As such, I thought it would be a relevant topic to share and discuss with the Wptuts+ community.

So in this article, I want to take a look at the problems that exist with supporting WordPress plugins, some of the current models for supporting WordPress plugins, and then initiate a discussion in the comments about the various options outlined here (as well as those that aren’t covered).

/>

The Fragmentation of Support

Before we discuss the various options for support, it’s important to note that as it stands right now there is a fragmentation of support that exists, even if you’re simply maintaining a free plugin in the WordPress Plugin Repository. For example, here’s how a lot of developers work:

  • Publish a plugin to the WordPress Plugin Repository. The repository offers a free support forum.
  • The developers then blog or publish an article about their plugin. This post now offers a comment thread that supports questions and comments about said plugin.
  • The developer is likely on Twitter or another social network on which users can connect and ask questions regarding the plugin.
  • The developer also has an email which acts as yet another channel through which others can talk with the developer about issues that they are experiencing.

Now, to be clear, I don’t fault anyone for reaching out to the developer through any of the available channels.

The problem is not with the users. Though I hesitate to say it, I don’t even think the problem is with the developers. The problem is with the variety of ways we share our work.

We need a way to funnel all questions through a single channel so that the problems, solutions, questions, and answers are easily visible or accessible by others so that developers aren’t left repeating themselves.

But that’s a tricky problem to solve. Some have done it well, some are still looking for solutions, and we’d love to hear from both in the comments. In the meantime, let’s review some of the more popular support models that exist.

/>

The Support Models

We’re going to look at four different models for offering support. I want to be clear that this is not the definitive list of support options, but a few of the most common support models that developers use today.

Premium Support

ZenDesk

One way that developers offer support is through some type of closed system. This doesn’t necessarily mean that all questions must be answered with payment – only those that are more involved or that require a significant time for troubleshooting.

The advantage to using this model is that there is obviously financial compensation for the time spent in helping the user. Often times, users are happy to pay assuming that the price is reasonable, and that the problem is significant enough; however, this can spur some bit of push back as users who believe that a free plugin should come with free support may also reject this.

It’s a fine line to balance, for sure, and I agree that plugins should all work under a certain set of conditions; however, I don’t believe that every problem that crops up is insignificant enough to warrant free support.

There are so many different permutations of hosting environments, WordPress versions, conflicting plugins, and other factors that isolating the problem can be challenging enough.

WordPress Plugin Repository

WordPress Plugin Repository Support

The WordPress Plugin Repository is often under-rated, in my opinion. It offers a variety of really nice tools for plugin developers that are simply under utilized either by the developers or by the users.

Aside from offering a consistent experience across the board for all developers and users, it gives us:

  • A way to brand our work using the header image
  • An easy way to provide a clear description of our work
  • Instructions on how to install the plugin
  • A section for Frequently Asked Questions
  • A Support Forum
  • …and much more

The problem is that you often have to consistently check back to the plugin pages to see if any new topics have been opened. On top of that, many of the people who leave topics are used to the plug-and-play model of themes and other plugins which can cause erradict results thanks to poor coding practices, conflicts, or some other anomaly.

Even still, the Support Forum isn’t bad – it’s free, it’s available for each plugin that we release, and it provides a consistent experience for the users. It’s worth considering, but it does require a bit of extra effort on the developer’s behalf.

Email

Support Emails

Email is a slippery slope when it comes to offering support, because it has a slightly more personal feel to it than one of the available forum options. As soon as you begin offering support through email, you’ve essentially given a user permission to contact you regarding a number of other issues either with their plugins or with WordPress problems they may have.

I’m not sharing this out of ignorance, either. This has happened more than a few times with me (and I do take full responsibility for it). Secondly, the problem with using email for support is that it has absolutely no visibility.

It provides no value to anyone except the person(s) in the email thread. This means the potential for duplicate support is really high.

No Support

Finally, one extreme option is simply to offer no support. I’m not particularly advocating this strategy, but I have seen it done, though I can’t speak to its results.

But if you’re offering a free plugin and you’re actively maintaining it, one option is to simply put it out in the wild and let the users fend for themselves.

It’s a dangerous route to go as I think that, as developers, we have some responsibility to our users since we’re attempting to create something to solve a problem for them, but that’s just one subjective stance on the topic. I’d love to hear others’ thoughts on it.

/>

Does Free Plugin Equal Free Support?

Before concluding, I think it’s worth asking the above question: Do free plugins imply free support? Personally, I don’t think so. At least, not as a whole.

On some level, I think that there’s a level of support we are obliged to give – especially those that normally take just a few minutes of time to resolve; however, there are other more convoluted issues that simply require more time.

At this point, I think it’s perfectly acceptable to ask for some level of compensation. I consider this to be analogous to a warranty with a physical product – replacements parts or fixes are available for a certain time; however, more complex problems usually require some type of technician.

/>

Conclusion

I’ve had recent conversations with respectable WordPress Plugin Developers all of whom have a stance on where to draw the line at free and paid support; however, each developer has his or her own opinion on what works for them.

Above all else, the conversation was rich with a variety of options, advantages, disadvantages, and more. To that end, I’d love for the Envato community to chime in and see if there isn’t more to be discussed – and possibly even solved – through the comments on this post.

Original from: http://wp.tutsplus.com/tutorials/plugins/strategies-for-supporting-wordpress-plugins/

Improving Blog Discussions With Disqus Comments

February 8th, 2013 Comments off

In the first part we discussed how we can use the default WordPress comments system to engage users into effective discussions. Today we are going to talk about how Disqus can help you to create effective discussions and how you can choose between default WordPress comment system vs Disqus systems.

Disqus is one of the most popular comment systems used for WordPress sites with a powerful set of built in features. As an author or blog owner, you should be trying to compare each of the discussed areas with your existing system and choose the best comment system for your readers.

Are you ready to Disqus your comments system?

/>

Do You Think Readers Prefer Disqus?

If you are a regular visitor to popular web design and development related blogs, you will definitely notice the change in their comments section.

Our favorite comment form is missing and it’s replaced by a dynamically generated component called Disqus. Most blogs are transferring their comments section to Disqus, including Wptuts+ and other Tuts+ sites.

Why Do They Change?

Unless there are considerable benefits to both readers and owners, these top sites won’t make a change which makes a huge impact to your user interaction section of the blog.

Readers are the most important people of a blog. So this means obviously readers are interested in commenting with the Disqus system.

/>

Improving Comments Section With Disqus

Every system has its own pluses and minuses. Nothing is going to be perfect. So let’s discuss the things we need to take into consideration before choosing Disqus as our blog commenting system.

Our discussion from here on will focus on comparing Disqus features against the default WordPress comments based on the sections we created in first part of this series.

Focusing on Simplicity

“Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.” /> ― E.F. Schumacher

As the above quote suggests, achieving simplicity is the hardest thing in any task. So lets see how Disqus helps us to simplify the comments system.

  • User Registration

    If you want to comment on a Disqus enabled blog, you need to register an account first. (At least with default settings). This looks like a certain disadvantage to start our discussion. But don’t rush into making decisions too quickly as Disqus provides the alternative option to comment with your social profiles like Twitter and Facebook.

    Disqus Login Alternatives

    These days almost all Internet users are on social networking sites like Twitter, Facebook and Google Plus. Hence there is a high percentage of possibility that they will be logged into one of these accounts at any given time.

    So it’s one click away from commenting, which seems fairly easy for a reader.

    Also we get the added advantage as authors or blog owners of social sharing links being provided automatically in line with every comment, increasing the possibility of readers sharing on their social profiles.

  • Comment Fields and Captcha

    Disqus doesn’t have a comment form with a lot of fields. A mandatory section is given to enter your comment. Other form fields depend on the chosen login section by the readers.

    If the readers are already logged into Disqus or social accounts, they can choose to enter the comment only. Readers who are not already logged in need to enter their username and password to login.

    In the worst case, readers need to fill only two fields, which is a simple enough task.

    Disqus Comment Fields

    No captcha image is used since not many people will waste time on getting authenticated and making spam comments. Disqus admin panel can also be used to filter and remove spam comments if necessary.

    So I would see this as a plus for making it easier for the reader to comment quickly.

  • Title of Comments Section

    Disqus default system provides a standard comment area for all users. So we won’t be able to create catchy titles to attract readers to comment, without digging into the Disqus plugin code. So I will consider this as the first minus point on Disqus.

Unique Identity for Readers

Sometimes people use anonymous or false names to comment. As a commenter, you won’t get any benefit by doing that. Also, other readers who read the comments section will feel these are just dummy comments since there is no real person.

We love to hear and learn from real people. For example, I could have written this article without creating my author biography. Since I have it under this article, you know I exist and my qualification to write such articles.

I am sure that you might be much more interested in this article if I had created this as a video explaining these things right in front of you.

Similarly we need to show our unique identity through our comments.

  • Commenter Profile Details and Image

    The profile image is one of the major parts in showing a unique identity for users. The default WordPress comments system uses a gravatar image for the given email address. Therefore if the email doesn’t have a gravatar image, a default image for the site will be shown instead.

    With Disqus you should be using either Disqus or Social accounts to comment. Therefore you will get the main profile image of your account in front of your comment which makes it easy to identify you.

    Comment Author Image

    Additionally, profile details of your social or Disqus account are displayed when you click on the name of the comment author. This is a really cool way of marketing your social media profiles with your comments.

    Author Profile Details

    So this can be considered as a really huge plus compared to the default WordPress comments section.

  • Highlight Author Comments

    You can use both a Disqus account and social media profiles to respond to comments, instead of WordPress login. So email cannot be used to identify the author, making it difficult to highlight author comments.

    I see this as a major minus point since it’s difficult to identify the author inside a Disqus comments thread. I hope we can find a method to get it to work with the default system without modifying code.

/>

Staying Updated With Discussions

  • Notifications on Comment Replies

    In the default system we had to implement the comment reply functionality through a manual process. Disqus comes up with built in functionality for notifying commenters when required. In order to make this work, as a reader you need to log into your Disqus account and change the configurations according to your preferences.

    Disqus Notifications

    You can find a section called Notifications in Edit Profile area of your Disqus account. In the Personal Settings area there are 3 options regarding notification.

    First you will be sent a notification whenever someone replies to your comments. This feature is similar to the default WordPress system feature.

    Second option can be used to subscribe to complete comment thread that you comment on. This will be set globally for every post you comment on. Also you can subscribe to specific comment threads only using the ‘Subscribe by Email’ link under the comment section as shown in the following screen.

    Subscribe to comments

    The final set of options sends notifications if someone mentions about you in comments. So considering all the above features, we can come to a conclusion that Disqus notifications are way more powerful than default WordPress comments system.

    Another plus point for Disqus.

/>

Enhanced Comments Navigation

In the article on the defaults comments section, we discussed the importance of navigating through comments and various techniques to improve the process. Now we are going to look at those techniques in the perspective of the Disqus comments system.

  • Comment Pagination

    We used either numbered pages or previous and next links as the pagination technique. However Disqus pagination differentiates from those techniques. Disqus uses infinite data displaying technique which is used by most popular sites such as Twitter and Facebook. In this technique a certain number of comments are displayed initially. Once we get into the last comment, a button appears with the heading “Load more comments”. Once you click it, it will provide the next set of comments and load a more button again at the end.

    comment Pagination

    So you want have a number of separate pages for comments or a very long comment thread with this technique. The comment thread will extend dynamically upon your request making it easier for the readers to navigate. So this is a definite plus point with Disqus comments.

  • Comment Numbers

    Disqus displays the comments thread similar to the default system’s style with small indentations for each level of sub comments. The latest version of Disqus 2012 uses an IFRAME to display the comments. Therefore it’s very difficult to add custom functionality. So implementing comment numbers with the new version will be very difficult if not impossible. Earlier we could have created this numbering using CSS tricks. With the new IFRAME, styles we use in the theme stylesheet will not take effect on Disqus comments.

    So it will be a minus point compared to the default system where we can customize almost anything.

  • Comment Filters

    In the default comment system we were able to create either the latest comments first or oldest comments first. So the readers had to use the pagination to view older or newer comments depending on what was displayed initially. Disqus allows us to filter the comments section using newest, oldest or best comments. In just one click you can change the direction to sort comments differently.

    Sort Comments

    This is very useful for the readers as well as authors. So another plus point to Disqus on our comparative analysis.

/>

Conclusion

Our discussion on Disqus contains more pluses than minuses which suggests Disqus will be very handy as a blog comments system.

But the thing is no matter how many additional benefits Disqus provides, WordPress default comments system, still seems to be the favorite. It does not mean that Disqus is bad. It might be that people take time to convert their system into a different one and don’t like to change.

“People don’t like change. But make the change fast enough and you go from one type of normal to another.” /> ― Terry Pratchett, Making Money

Disqus will become more popular among owners and readers in the near future.

This is what I have experienced. Now it’s time to know what you think. I hope you have five minutes to share your thoughts on Disqus vs Default systems for comments.

I have 2 questions for you:

  1. Do you like to comment on Disqus enabled blogs more than Default comments enabled blogs? And why?
  2. Do you like to use Disqus as a blog owner or author? And why?

Looking forward to hearing what you think.

Original from: http://wp.tutsplus.com/tutorials/business/improving-blog-discussions-with-disqus-comments/