Archive for March, 2011

Flexible height vertical centering with CSS, beyond IE7

One of the most common CSS questions is undoubtedly how to center an element vertically. There are several techniques for doing that, but many, including one that I posted more than seven years ago in Centering with CSS, rely on specifying a height for the centered content. That obviously makes the technique somewhat inflexible.

I recently needed to center something both horizontally and vertically and started thinking that there might be better ways of doing it if I could disregard IE7 and older. The technique I ended up with uses display:table to center the whole page and seems to work well, though there is one caveat.

Read full post

Posted in , .



Useful Photoshop Tips And Tricks For Photo Retouching

Advertisement in Useful Photoshop Tips And Tricks For Photo Retouching
 in Useful Photoshop Tips And Tricks For Photo Retouching  in Useful Photoshop Tips And Tricks For Photo Retouching  in Useful Photoshop Tips And Tricks For Photo Retouching

When it comes to designing in Photoshop, there is a myriad of ways one could use to achieve a certain result, especially when it comes to photo retouching. Designers use technique they are most confident as well as comfortable with, which is great because it’s always useful to peek into the workflow of our colleagues and learn new design approaches. We have had articles on cloning, compositing, masks and obscure Photoshop time-savers in the past. This article is different.

I’ll be covering some of the useful techniques and tricks which I’ve learned from my experience. You may know some of them, but hopefully not all of them. All images used in this article were purchased and are used according to their licenses. The second part of this post will be published in 2 weeks.

Here is a short overview of the techniques we’ll be covering:

Naturally Increased Light

The light of the sun creates texture. There are shadowy areas and spots where the sunlight can shine without interference. To control the intensity, you can draw more light onto a separate layer or increase already existing light. Create a new layer by going to Layer → New → Layer, or by pressing Shift + Control + N on Windows or Shift + Command + N on a Mac. Set the blending mode to “Color Dodgeâ€� and the opacity to about 15%.

30-tips-and-tricks1a in Useful Photoshop Tips And Tricks For Photo Retouching
Increase light on a separate layer.

Then use the brush tool with a soft brush, and hold the Alt/Option key to pick up colors from the area that you want to brighten. Continue to brush in some light, picking up appropriate colors if the background changes. This way, you increase not only the light, but the saturation, which makes for more realistic results.

30-tips-and-tricks1b in Useful Photoshop Tips And Tricks For Photo Retouching
The blending mode “Color Dodge� creates realistic results.

Simulate Infrared Images

Open a photo in Camera Raw; you can do this either in Bridge, using the right mouse key and clicking “Open in Camera Raw,â€� or directly in Photoshop, by selecting File → Open as Smart Object. Apply basic adjustments to optimize your image (for example, with the “Recoveryâ€� and “Fill Lightâ€� slides), then switch to the “HSL/Grayscaleâ€� tab. Check “Convert to Grayscale,â€� and set the Blues down to around -85. Set the Greens to +90 and the Yellows to +20.

Trees and bushes should now shine in the typical white, and the sky should appear almost black. If you want to go on and simulate some grain, switch to the “Effects� tab, and enter 15 for the amount, 20 for size and 80 for roughness. You could also apply a “Vignette.� Here I used -30 for the amount, 40 for the midpoint and -35 for roundness.

30-tips-and-tricks3 in Useful Photoshop Tips And Tricks For Photo Retouching
It’s almost like an infrared image.

Levels

When applying a “Levels adjustment,â€� you can set black and white points in order to decrease color tints, but where are the darkest and brightest spots in the image? Go to New Adjustment Layer → Threshold to find those areas. This function is available under the “Layerâ€� menu.

Move the slider so far to the right that only a few white spots remain in the document. Use the “Color Sampler tool� and set down a point there. Move the slider to the left until only a few black spots remain, and set a second point down there.

One could also find a neutral gray in the image by using a “Threshold adjustment layer.â€� Add a new blank layer between the original image and the threshold adjustment layer, and fill this layer with 50% gray. Go to Edit → Fill or press Shift + F5, then select “50% Grayâ€� under “Contentsâ€� and click “OK.â€�

30-tips-and-tricks5a in Useful Photoshop Tips And Tricks For Photo Retouching
Here is the threshold adjustment layer at work.

Change the blending mode of this layer to “Difference.� Select the “Threshold adjustment layer� again and move the slider all the way to the left. Slowly move the slider back to the right until black dots start to appear. These are the neutral gray areas in the image (if neutral grays are present). Add a “Color Sampler spot.�

Now delete both the threshold adjustment layer and the 50% gray layer. Create a new adjustment layer, “Levels.� Use the first Eyedropper tool to click on the darkest area, then use the third Eyedropper on the brightest area.

30-tips-and-tricks5b in Useful Photoshop Tips And Tricks For Photo Retouching
Here’s a before-and-after comparison.

Now you can use the gray Eyedropper tool on the third Color Sampler spot. The color tint will be decreased. Color Sampler spots can be deleted by dragging them off the canvas with the Color Sampler tool.

Color Look With An Adjustment Layer

Go to the Layer menu, and then New Adjustment Layer → Hue/Saturation, and set the blending mode to “Soft Lightâ€� and check “Colorize.â€� Use the Hue, Saturation and Lightness sliders to control the color: for a cool look, for example, set the hue at 210, the saturation at 50 and the lightness at 10; for a warm look, set the hue at 30, the saturation at 30 and the lightness at 5.

30-tips-and-tricks6a in Useful Photoshop Tips And Tricks For Photo Retouching
Here is Hue/Saturation and Color Fill.

Alternatively, you could use several color layers. Create them from the layer palette with the “New Fill/Adjustment Layer� button. Choose a color, then set the blending mode to “Vivid Light.� Reduce the opacity to about 12%, and invert the layer mask with Control/Command + I. Paint in the colored light with a big brush and white color. This works especially well for the lighting in portraits that have a textured background.

30-tips-and-tricks6b in Useful Photoshop Tips And Tricks For Photo Retouching
Here’s the Color Look with an Adjustment Layer.

Controlling Mid-Tone Contrasts

To increase detail in landscape shots, boost the mid-tone contrast. Copy the background layer with Control/Command + J, and then click on Filter → Convert for Smart Filters in the menu. Then go to Filter → Other → High Pass and enter a radius of 3 pixels. Change the blending mode to “Overlayâ€� and double-click the layer next to its name to open the “Layer Styleâ€� window.

30-tips-and-tricks7a in Useful Photoshop Tips And Tricks For Photo Retouching
Layer Style window: This Layer

For the first gradient, “This Layer,� split the sliders by holding the Alt/Option key and trim the layer effect to the “50/100� and “150/200� ranges. As soon as you move the sliders, you’ll see where those numbers are. This increases contrast only for the mid-tones. Double-click the “High Pass� filter in the layer palette to bring the dialog box up again in order to adjust the radius to your liking.

30-tips-and-tricks7b in Useful Photoshop Tips And Tricks For Photo Retouching
Check out these mid-tone contrasts.

Sunset

A sunset, especially at sea, can be an amazing color spectacle. The hues will depend heavily on the weather, though — but you can push them a bit with a gradient map. Click on the “New Fill/Adjustment Layerâ€� button in the Layer palette and select “Gradient Mapâ€� from the list. Click on the gradient to open the “Gradient Editor.â€�

30-tips-and-tricks8a in Useful Photoshop Tips And Tricks For Photo Retouching
Gradient Map

Click on the first color patch below the gradient, and change the color to red. Set the color patch on the opposite side to yellow, and click “OK.� Set the blending mode to “Soft Light� and reduce the opacity to about 50%. This will create a warm, almost golden sunset.

30-tips-and-tricks8b in Useful Photoshop Tips And Tricks For Photo Retouching
Observe the movement from a blue to a golden sunset.

Creating Smiles

Roughly select the area around the mouth with the Polygon Lasso tool. Go to Select → Modify → Feather, and enter a radius of 10 pixels. Confirm, then click on Layer → New → Layer via Copy (or press Control/Command + J), then Edit → Puppet Warp. Photoshop will put a mesh over the entire layer in the shape of your previous selection.

30-tips-and-tricks10a in Useful Photoshop Tips And Tricks For Photo Retouching
Here’s the mesh over the layer.

You can control the size of the mesh with the “Expansion� value in the Options bar. Increase the density to “More Points� for increased precision. Press Control/Command + H to hide the mesh, then set the first pins to the corners of the mouth. Add more pins to distinctive spots of the mouth. By clicking and dragging the mesh, you can shape a nice smile.

Colorful Water Drops

Macro shots of water drops are appealing, and shapes can be further accentuated with discreet coloring. You could treat the bland surface with a linear gradient from #772222 (RGB 119, 34, 34) to #3333bb (RGB 51, 51, 187). If the photo is on a layer of its own, click on Layer → Layer Style → Gradient Overlay or double-click the layer next to its name.

30-tips-and-tricks12a in Useful Photoshop Tips And Tricks For Photo Retouching
Layer Style: Gradient Overlay

Set the blend mode to Color, the opacity to 50%, the gradient to “Foreground to background color� and the angle to 90%. The gradient will be saved as a layer style, so you can come back at any time to adjust the values. Double-clicking the style name opens up the dialog window once more.

30-tips-and-tricks12b in Useful Photoshop Tips And Tricks For Photo Retouching
See the colorful drops with optimized colors.

Skin Color

If the skin is not quite perfect after retouching, it might be because of the general hue. You can control it by going to New Adjustment Layer → Hue/Saturation. Click on the miniature mask, and press Control/Command + I to invert the mask.

30-tips-and-tricks14a in Useful Photoshop Tips And Tricks For Photo Retouching
Adjustment Layer: Hue/Saturation

Using white color and a soft brush, paint over the skin areas so that only they get treated. For the adjustment, switch from Standard to “Reds� (found in the Hue drop-down menu of the Adjustment layer), and use the Hue, Saturation and Lightness sliders to adjust the skin color. Switch to “Yellows� and optimize the skin tone. Getting the colors exactly right depends very much on the image material. Rely on your common sense.

30-tips-and-tricks14b in Useful Photoshop Tips And Tricks For Photo Retouching
Optimized skin tones

Matching Skin Tones

A sunburn or a blush can disrupt a portrait, especially if there is a contrasting pale person nearby. Photoshop has a tool to correct that: “Match Color� offers control over skin tones. Open your image and use the Quick Selection tool to roughly select the red skin areas.

You can hold down the Alt/Option key and subtract areas from the selection. Click on Select → Modify → Feather and enter a value of about 15 pixels. Use the Control/Command + J shortcut to copy the selection to a new layer.

30-tips-and-tricks18a in Useful Photoshop Tips And Tricks For Photo Retouching
Adjustments: Match Color

Using the same technique, copy the non-reddened skin to a new layer. In the next step, you’ll have to differentiate between the source layer and the layer to edit, so rename these two layers meaningfully; all it takes is a double-click on the layer name. You could use the naming scheme shown here and call them “Beautiful skin� and “Reddened skin.�

Activate the layer with the red skin, and select Image → Adjustments → Match Color from the menu. For “Source,â€� select the current document, and for “Layer,â€� select the one with the beautiful skin. Control the effect using the “Luminanceâ€� and “Color Intensityâ€� sliders in the Image Options area. Once you confirm, you can control the effect’s strength with the Opacity slider.

30-tips-and-tricks18b in Useful Photoshop Tips And Tricks For Photo Retouching
Paler skin after Match Color

Reducing Noise

Noisy images are annoying. One way to reduce noise is through the channels. Copy the background layer by pressing Control/Command + J, switch to the Channels palette, and select the channel that shows the least noise. Drag that channel down to the “New Channelâ€� icon (next to the trash can) and go to Stylize → Find Edges. Then apply a Gaussian Blur with a radius of about 3 pixels.

30-tips-and-tricks19a in Useful Photoshop Tips And Tricks For Photo Retouching
Look at this copy of the red channel.

Click on the new channel’s miniature icon while holding the Control/Command key to select the content. Activate the “RGB channel� (top-most), and switch back to the Layers palette. When the duplicated background is selected, click on the “Add Layer Mask� icon.

Click on the Layer Miniature icon, and select Filter → Blur → Surface Blur from the menu. Play around with the Radius and Threshold sliders until the noise has been reduced as much as possible. Thanks to the mask you created, the contours are safe.

30-tips-and-tricks19b in Useful Photoshop Tips And Tricks For Photo Retouching
With and without noise

Retro Look With Curves

Go to Layer → New Adjustment Layer → Curves and switch from RGB to Reds. Then drag the line downwards a little for the shadows and upwards for the highlights, creating a slight “Sâ€� curve. Do the same for the Greens. For the Blues, drag the highlights down a little and the shadows up (for an inverted S shape). The shadows should now be slightly blue-ish, the highlights slightly yellow-ish.

30-tips-and-tricks20a in Useful Photoshop Tips And Tricks For Photo Retouching
Adjustment Layer: Curves

Create a new layer with Shift + Control/Command + N, and fill it with #000066 (RGB 0, 0, 102). Set the blending mode to “Exclusion.� Now copy the background layer by clicking it and pressing Control/Command + J. Set the blending mode for this copy to “Soft Light.�

To decrease the effect overall, activate the top-most layer and then click on the background copy while holding the Shift key, thereby selecting both layers. Alternatively, you can add them to a group with Control/Command + G. Reduce the layer’s (or group’s) opacity. Note that in Photoshop versions prior to CS5, you’ll have to reduce the opacity for each layer individually.

30-tips-and-tricks20b in Useful Photoshop Tips And Tricks For Photo Retouching
Achieve a simple retro look in a few steps.

Identifying Layers

If you’re ambitious with your collages, then you’ll be familiar with this problem: meaningful layer names are often neglected during the creative process. This can result in layer names like “Layer 4� and “Layer 5 Copy 2,� which are not very helpful when you need to quickly identify the contents of a layer.

Photoshop offers a number of solutions for our laziness. For example, you can click on the element you want to select by using the “Move tool� and holding the right mouse key; you’ll see which layer contents are below the tool. Photoshop will display a list in a drop-down menu, from which you can easily select the desired element.

30-tips-and-tricks21 in Useful Photoshop Tips And Tricks For Photo Retouching
Right click with the Move tool

Control/Command + left-click with the Move tool selected and, in most cases, you’ll select the corresponding layer of the element that your mouse is over (unless Photoshop can’t distinguish between the multiple layers).

You could also Control/Command + left-click on a layer’s miniature icon to get a selection of the content of that layer. The marching ants will show you what is on that layer and where it is.

Another option is to click on the Layer palette’s Options icon, in the top-right corner, and select “Layers Palette Options.� From here you can adjust the size of the layer’s miniature preview and concentrate the miniature’s content to the layer’s bounds, which should cut down on future guesswork when it comes to layer contents.

30-tips-and-tricks21b in Useful Photoshop Tips And Tricks For Photo Retouching
Layers Palette options

Conserving Resources

Plug-ins save time, but they’re a bit resource-hungry; at least, they lengthen Photoshop’s start-up time. Your plug-ins might have functionality that you rarely use, so deactivate them until you need them. To do so, create a new folder by going to Adobe → Adobe Photoshop CS5 (or whatever your version) and name it something like Plugins_deactivated.

30-tips-and-tricks24 in Useful Photoshop Tips And Tricks For Photo Retouching
After disabling some plug-ins.

Now move all of the extensions that you don’t need for the moment. When you restart Photoshop now, those plug-ins won’t load, so the program will start up quickly. Your RAM will be relieved. Because you neither deleted nor uninstalled the plug-ins, they’re available to use anytime. If you need them, just move them back to the plug-in folder.

Classy Sepia Look

The sepia look is an absolute classic. To enhance a black and white image with a classy sepia tone, follow these steps. Click on Layer → New Adjustment Layer → Photo Filter, and select the Sepia filter, with a density of 100%. Double-click the layer (not the layer name) to open up the Layer Style window. This will show the Blending options.

30-tips-and-tricks26a in Useful Photoshop Tips And Tricks For Photo Retouching
A view of the Layer Style window.

At the bottom of the dialog box for the first gradient, move the white slider to the left while holding the Alt/Option key. This creates a smooth transition between adjusted and unadjusted areas. The sepia will now look elegant.

30-tips-and-tricks26b in Useful Photoshop Tips And Tricks For Photo Retouching
Subtle sepia

Precise Positioning

I’m sure you’ve often been irritated by Photoshop’s tendency to position elements on its own, but the program is just trying to help you align an element that is on its own layer with the outer edge of the document or with the edge of another object. To your frustration, the layer’s content will jump to the edge, even though you wanted to leave a few pixels of space in between. You can temporarily deactivate the automatic snapping by holding the Control/Command key as you position.

30-tips-and-tricks27 in Useful Photoshop Tips And Tricks For Photo Retouching
A banner, close to the edge.

Applying Layer Styles Multiple Times

Usually, layer styles can be applied only once. For example, if you click on Layer → Layer Style → Drop Shadow, you cannot create a double drop shadow, one of which has an angle of 120°, a distance of 2 pixels and a size of 2 pixels, and the other of which has an angle of 180°, a distance of 12 pixels and a size of 12 pixels.

Actually, it is possible! It just requires a little detour. Create the first drop shadow as you normally would. Then right-click on the layer and select “Convert to Smart Object� from the menu. This smart object can be assigned another drop shadow, and you can convert the smart object into yet another smart object. This way, you can easily add a third and fourth drop shadow. Alternatively, you could apply multiple strokes.

30-tips-and-tricks31 in Useful Photoshop Tips And Tricks For Photo Retouching
Three shadows in combination.

By the way, to put one or even several styles onto their own layers at once, right-click on the FX symbol and select “Create Layer� from the list. Now you can apply filters to these styles, but they won’t be editable anymore.

Stay tuned

The second part of this post will be published in 2 weeks. Please stay tuned and subscribe to our RSS-feed and join us on Facebook.

Huge thanks to Carlos Lanenga for his valuable suggestions for this article.


(al) (ik) (vf)


© Dirk Metzmacher for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us
Post tags: , , , , ,


Fresh Icon Sets To Improve Your Designs

Advertisement in Fresh Icon Sets To Improve Your Designs
 in Fresh Icon Sets To Improve Your Designs  in Fresh Icon Sets To Improve Your Designs  in Fresh Icon Sets To Improve Your Designs

A predefined icon set collection is like a resource reservoir for graphic designers which can be used to improve the appearance of the designs they’re working on. Nevertheless, these icons should be seen as an inspiration and we encourage you all to try creating your own icons for designing portfolios, blogs, corporate designs, magazines and Web applications.

Tutorials on how to create your own icons (almost everything is possible!) are available after the jump. Here, all icon sets are free. Nevertheless, please be sure to read the license agreements carefully before using all icons since this can change from time to time. Enjoy!

IC Minimal Icon Set – by Design Deck – Available in 28 Icons in total all PNG & JPG format and a size of 64x 64.

Freshiconset22 in Fresh Icon Sets To Improve Your Designs

Android Icons – Shape Package – Vector shapes collection in one package.

Freshiconset181 in Fresh Icon Sets To Improve Your Designs

Mail Icons / Elements – A set of vector mail icons.

Freshiconset30 in Fresh Icon Sets To Improve Your Designs

Web Icons Tile-Style – A clean set of stylish web icons in 256 x 256 pixels.

Freshiconset34 in Fresh Icon Sets To Improve Your Designs

Weather Icons – A set of beautiful ‘weather’ icons.

Freshiconset16 in Fresh Icon Sets To Improve Your Designs

Shopping Icons – Set of 12 shopping icons in 256 x 256 pixels.

Freshiconset32 in Fresh Icon Sets To Improve Your Designs

Glossy: Free Icon Set – This free icon set has 20 high quality semi-transparent and glossy icons.

Freshiconset38 in Fresh Icon Sets To Improve Your Designs

Free Vector Net Icon Set – Here you’ll find the EPS and AI file in the zipped folder:

Freshiconset46 in Fresh Icon Sets To Improve Your Designs

Cutie – 20 High Quality Web Icons – “Cutieâ€� consists of 20 icons, available in 48×48, 64×64, 128×128, 256×256 and 512×512.

Freshiconset24 in Fresh Icon Sets To Improve Your Designs

Kaching – Exclusive Free eCommerce Icons – The icons are available as PNGs (48×48 and 400×400) and more:

Freshiconset43 in Fresh Icon Sets To Improve Your Designs

Facebook, Twitter & RSS Feed Icons – The set consist of the Facebook, Twitter and RSS Feed Icons and are available in two different sizes – 64 x 64px and 128 x 128px.

Freshiconset1 in Fresh Icon Sets To Improve Your Designs

Winter Writers: A Unique and Free High Quality Icon Set – This high-quality icon set features 10 icons, all in PNG format, ranging from 32×32 px to 512x512px.

Freshiconset9 in Fresh Icon Sets To Improve Your Designs

Vector Weather Icons – Vector weather icons are provided in .AI (Adobe Illustrator CS3) format.

Freshiconset39 in Fresh Icon Sets To Improve Your Designs

Medical Icon Set – Available in PNG: 24×24, 32×32, 48×48, 64×64, 128×128, 256×256, ICO, ICNS: 128x128px.

Freshiconset201 in Fresh Icon Sets To Improve Your Designs

MySecret 10 icons – A set of 10 beautiful icons.

Freshiconset4 in Fresh Icon Sets To Improve Your Designs

Colorful Heart Icons – 10 color variations of a stylish heart icons in a fully layered PSD.

Freshiconset11 in Fresh Icon Sets To Improve Your Designs

Settings – ICO, ICNS and PNG files available inside the zip.

Freshiconset12 in Fresh Icon Sets To Improve Your Designs

The Lost Props – Movie based OSX icons.

Freshiconset37 in Fresh Icon Sets To Improve Your Designs

Free Computer & Mobile Icons – A set of 9 game and mobile icons in 256 x 256 pixels.

Freshiconset28 in Fresh Icon Sets To Improve Your Designs

Free Aircraft Icons – A set of 18 free aircraft icons. PNG’s and Vector files can be downloaded for free.

Freshiconset45 in Fresh Icon Sets To Improve Your Designs

Small Icons – can be used in any application.

Freshiconset13 in Fresh Icon Sets To Improve Your Designs

Minecraft Icon Replacement – A set of awesome Mac / Windows Icons.

Freshiconset15 in Fresh Icon Sets To Improve Your Designs

Free simple icons – Zip file including PSD and PNG files.

Freshiconset19 in Fresh Icon Sets To Improve Your Designs

Free Food Icons – Looks good enough to eat: A set of 12 food icons in 256 x 256 pixels.

Freshiconset33 in Fresh Icon Sets To Improve Your Designs

Vector Funny Emoticons – Funny emoticons are provided in vector .AI (Adobe Illustrator CS3) format.

Freshiconset40 in Fresh Icon Sets To Improve Your Designs

MySecret – A set of 10 beautiful icons.

Freshiconset21 in Fresh Icon Sets To Improve Your Designs

Fashionable Handbag Icons – Brighten up a fashion site or blog with these fashionable handbag icons. Set of 12:

Freshiconset36 in Fresh Icon Sets To Improve Your Designs

Free Social Icon Set – 3 folders with PNG icons in different sizes . Available sizes : 64×64,
128×128, 256×256.

< Freshiconset23 in Fresh Icon Sets To Improve Your Designs

Twitter Icon for Mac – Beautiful twitter icon for Mac.

Freshiconset17 in Fresh Icon Sets To Improve Your Designs

Blue Print Icon Set – Detailed blue print icon in 4 sizes available as transparent PNG files: 64 x 64px, 128 x 128 px, 256 x 256 px, 512 x 512 px.

Freshiconset26 in Fresh Icon Sets To Improve Your Designs

Music Instruments – A set of 9 music instruments in 256 x 256 pixels.

Freshiconset29 in Fresh Icon Sets To Improve Your Designs

Cute as a Button. Cats 2 – This collection contains 6 icons with large resources for Windows & Mac OS X.

Freshiconset47 in Fresh Icon Sets To Improve Your Designs

Comic iPad Icons – Including Mac, Windows and PNG files.

Freshiconset48 in Fresh Icon Sets To Improve Your Designs

Free Icons: Multimedia – A nice set of 9 multimedia icons in 256 x 256 pixels.

Freshiconset31 in Fresh Icon Sets To Improve Your Designs

Vector Social Paper Icons – Awesome collection of free vector social icons from the web 2.0 family:

Freshiconset41 in Fresh Icon Sets To Improve Your Designs

Developpers Icons – 105 icons contained in a wonderful set.

Freshiconset44 in Fresh Icon Sets To Improve Your Designs

i Icons – Icons contained in a set (62 total) / Free for personal desktop use only.

Freshiconset42 in Fresh Icon Sets To Improve Your Designs

Free Web Icons – A set of 3D Web icons in 256 x 256 pixels.

Freshiconset35 in Fresh Icon Sets To Improve Your Designs

More Icons:


Fresh Icon Sets To Improve Your Designs

Advertisement in Fresh Icon Sets To Improve Your Designs
 in Fresh Icon Sets To Improve Your Designs  in Fresh Icon Sets To Improve Your Designs  in Fresh Icon Sets To Improve Your Designs

A predefined icon set collection is like a resource reservoir for graphic designers which can be used to improve the appearance of the designs they’re working on. Nevertheless, these icons should be seen as an inspiration and we encourage you all to try creating your own icons for designing portfolios, blogs, corporate designs, magazines and Web applications.

Tutorials on how to create your own icons (almost everything is possible!) are available after the jump. Here, all icon sets are free. Nevertheless, please be sure to read the license agreements carefully before using all icons since this can change from time to time. Enjoy!

IC Minimal Icon Set – by Design Deck – Available in 28 Icons in total all PNG & JPG format and a size of 64x 64.

Freshiconset22 in Fresh Icon Sets To Improve Your Designs

Android Icons – Shape Package – Vector shapes collection in one package.

Freshiconset18 in Fresh Icon Sets To Improve Your Designs

Mail Icons / Elements – A set of vector mail icons.

Freshiconset30 in Fresh Icon Sets To Improve Your Designs

Web Icons Tile-Style – A clean set of stylish web icons in 256 x 256 pixels.

Freshiconset34 in Fresh Icon Sets To Improve Your Designs

Weather Icons – A set of beautiful ‘weather’ icons.

Freshiconset16 in Fresh Icon Sets To Improve Your Designs

Shopping Icons – Set of 12 shopping icons in 256 x 256 pixels.

Freshiconset32 in Fresh Icon Sets To Improve Your Designs

Glossy: Free Icon Set – This free icon set has 20 high quality semi-transparent and glossy icons.

Freshiconset38 in Fresh Icon Sets To Improve Your Designs

Free Vector Net Icon Set – Here you’ll find the EPS and AI file in the zipped folder:

Freshiconset46 in Fresh Icon Sets To Improve Your Designs

Cutie – 20 High Quality Web Icons - “Cutie� consists of 20 icons, available in 48×48, 64×64, 128×128, 256×256 and 512×512.

Freshiconset24 in Fresh Icon Sets To Improve Your Designs

Kaching – Exclusive Free eCommerce Icons - The icons are available as PNGs (48×48 and 400×400) and more:

Freshiconset43 in Fresh Icon Sets To Improve Your Designs

Facebook, Twitter & RSS Feed Icons - The set consist of the Facebook, Twitter and RSS Feed Icons and are available in two different sizes – 64 x 64px and 128 x 128px.

Freshiconset1 in Fresh Icon Sets To Improve Your Designs

Winter Writers: A Unique and Free High Quality Icon Set - This high-quality icon set features 10 icons, all in PNG format, ranging from 32×32 px to 512x512px.

Freshiconset9 in Fresh Icon Sets To Improve Your Designs

Vector Weather Icons - Vector weather icons are provided in .AI (Adobe Illustrator CS3) format.

Freshiconset39 in Fresh Icon Sets To Improve Your Designs

Medical Icon Set – Available in PNG: 24×24, 32×32, 48×48, 64×64, 128×128, 256×256, ICO, ICNS: 128x128px

Freshiconset20 in Fresh Icon Sets To Improve Your Designs

MySecret 10 icons - A set of 10 beautiful icons.

Freshiconset4 in Fresh Icon Sets To Improve Your Designs

Colorful Heart Icons - 10 color variations of a stylish heart icons in a fully layered PSD.

Freshiconset11 in Fresh Icon Sets To Improve Your Designs

Settings - ICO, ICNS and PNG files available inside the zip.

Freshiconset12 in Fresh Icon Sets To Improve Your Designs

The Lost Props - Movie based OSX icons.

Freshiconset37 in Fresh Icon Sets To Improve Your Designs

Free Computer & Mobile Icons - A set of 9 game and mobile icons in 256 x 256 pixels.

Freshiconset28 in Fresh Icon Sets To Improve Your Designs

Free Aircraft Icons - A set of 18 free aircraft icons. PNG’s and Vector files can be downloaded for free.

Freshiconset45 in Fresh Icon Sets To Improve Your Designs

Small Icons - Small icons – can be used in any application.

Freshiconset13 in Fresh Icon Sets To Improve Your Designs

Minecraft Icon Replacement - A set of awesome Mac / Windows Icons.

Freshiconset15 in Fresh Icon Sets To Improve Your Designs

Free simple icon - Zip file including PSD and PNG files.

Freshiconset19 in Fresh Icon Sets To Improve Your Designs

Free Food Icons - Looks good enough to eat: A set of 12 food icons in 256 x 256 pixels.

Freshiconset33 in Fresh Icon Sets To Improve Your Designs

Vector Funny Emoticons - Funny emoticons are provided in vector .AI (Adobe Illustrator CS3) format.

Freshiconset40 in Fresh Icon Sets To Improve Your Designs

MySecret - A set of 10 beautiful icons.

Freshiconset21 in Fresh Icon Sets To Improve Your Designs

Fashionable Handbag Icons - Brighten up a fashion site or blog with these fashionable handbag icons. Set of 12.

Freshiconset36 in Fresh Icon Sets To Improve Your Designs

Free Social Icon Set - 3 folders with PNG icons in different sizes . Available sizes : 64×64, 128×128, 256×256.

Freshiconset23 in Fresh Icon Sets To Improve Your Designs

Twitter Icon for Mac - Beautiful twitter icon for Mac.

Freshiconset17 in Fresh Icon Sets To Improve Your Designs

Blue Print Icon Set - Detailed blue print icon in 4 sizes available as transparent PNG files: 64 x 64 px, 128 x 128 px, 256 x 256 px, 512 x 512 px.

Freshiconset26 in Fresh Icon Sets To Improve Your Designs

Music Instruments - A set of 9 music instruments in 256 x 256 pixels.

Freshiconset29 in Fresh Icon Sets To Improve Your Designs

Cute as a Button. Cats 2 - This collection contains 6 icons with large resources for Windows & Mac OS X.

Freshiconset47 in Fresh Icon Sets To Improve Your Designs

Comic iPad Icons - Including Mac, Windows and PNG files.

Freshiconset48 in Fresh Icon Sets To Improve Your Designs

Free Icons: Multimedia - A nice set of 9 multimedia icons in 256 x 256 pixels.

Freshiconset31 in Fresh Icon Sets To Improve Your Designs

Vector Social Paper Icons - Awesome collection of free vector social icons from the web 2.0 family:

Freshiconset41 in Fresh Icon Sets To Improve Your Designs

Developpers Icons - 105 Icons contained in a wonderful set.

Freshiconset44 in Fresh Icon Sets To Improve Your Designs

i Icons - Icons contained in a set (62 total) / Free for personal desktop use only.

Freshiconset42 in Fresh Icon Sets To Improve Your Designs

Free Web Icons - A set of 3D Web icons in 256 x 256 pixels.

Freshiconset35 in Fresh Icon Sets To Improve Your Designs

More Icons:

(ik)


Ten Things Every WordPress Plugin Developer Should Know

Advertisement in Ten Things Every WordPress Plugin Developer Should Know
 in Ten Things Every WordPress Plugin Developer Should Know  in Ten Things Every WordPress Plugin Developer Should Know  in Ten Things Every WordPress Plugin Developer Should Know

Plugins are a major part of why WordPress powers millions of blogs and websites around the world. The ability to extend WordPress to meet just about any need is a powerful motivator for choosing WordPress over other alternatives. Having written several plugins myself, I’ve come to learn many (but certainly not all) of the ins-and-outs of WordPress plugin development, and this article is a culmination of the things I think every WordPress plugin developer should know. Oh, and keep in mind everything you see here is compatible with WordPress 3.0+.

Don’t Develop Without Debugging

The first thing you should do when developing a WordPress plugin is to enable debugging, and I suggest leaving it on the entire time you’re writing plugin code. When things go wrong, WordPress raises warnings and error messages, but if you can’t see them then they might as well have not been raised at all.

Wordpress Plugins Screenshot in Ten Things Every WordPress Plugin Developer Should Know

Enabling debugging also turns on WordPress notices, which is important because that’s how you’ll know if you’re using any deprecated functions. Deprecated functions may be removed from future versions of WordPress, and just about every WordPress release contains functions slated to die at a later date. If you see that you are using a deprecated function, it’s best to find its replacement and use that instead.

How to Enable Debugging

By default, WordPress debugging is turned off, so to enable it, open wp-config.php (tip: make a backup copy of this file that you can revert to later if needed) in the root of your WordPress installation and look for this line:

define('WP_DEBUG', false);

Replace that line with the following:

// Turns WordPress debugging on
define('WP_DEBUG', true);

// Tells WordPress to log everything to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);

// Doesn't force the PHP 'display_errors' variable to be on
define('WP_DEBUG_DISPLAY', false);

// Hides errors from being displayed on-screen
@ini_set('display_errors', 0);

With those lines added to your wp-config.php file, debugging is fully enabled. Here’s an example of a notice that got logged to /wp-content/debug.log for using a deprecated function:

[15-Feb-2011 20:09:14] PHP Notice: get_usermeta is deprecated since version 3.0! Use get_user_meta() instead. in C:\Code\Plugins\wordpress\wp-includes\functions.php on line 3237

With debugging enabled, keep a close eye on /wp-content/debug.log as you develop your plugin. Doing so will save you, your users, and other plugin developers a lot of headaches.

How to Log Your Own Debug Statements

So what about logging your own debug statements? Well, the simplest way is to use echo and see the message on the page. It’s the quick-and-dirty-hack way to debug, but everyone has done it one time or another. A better way would be to create a function that does this for you, and then you can see all of your own debug statements in the debug.log file with everything else.

Here’s a function you can use; notice that it only logs the message if WP_DEBUG is enabled:

function log_me($message) {
    if (WP_DEBUG === true) {
        if (is_array($message) || is_object($message)) {
            error_log(print_r($message, true));
        } else {
            error_log($message);
        }
    }
}

And then you can call the log_me function like this:

log_me(array('This is a message' => 'for debugging purposes'));
log_me('This is a message for debugging purposes');

Use the BlackBox Debug Bar Plugin

I only recently discovered this plugin, but it’s already been a huge help as I work on my own plugins. The BlackBox plugin adds a thin black bar to the top of any WordPress post or page, and provides quick access to errors, global variables, profile data, and SQL queries.

Debug-bar-black1 in Ten Things Every WordPress Plugin Developer Should Know

Clicking on the Globals tab in the bar shows all of the global variables and their values that were part of the request, essentially everything in the $_GET, $_POST, $_COOKIE, $_SESSION, and $_SERVER variables:

Debug-bar-globals1 in Ten Things Every WordPress Plugin Developer Should Know

The next tab is the Profiler, which displays the time that passed since the profiler was started and the total memory WordPress was using when the checkpoint was reached:

Debug-bar-profiler1 in Ten Things Every WordPress Plugin Developer Should Know

You can add your own checkpoints to the Profiler by putting this line of code anywhere in your plugin where you want to capture a measurement:

apply_filters('debug', 'This is a checkpoint');

Perhaps the most valuable tab in the BlackBox plugin is the SQL tab, which shows you all of the database queries that executed as part of the request. Very useful for determining long-running database calls:

Debug-bar-sql1 in Ten Things Every WordPress Plugin Developer Should Know

And finally we have the Errors tab, which lists all of the notices, warnings, and errors that occurred during the request:

Debug-bar-errors1 in Ten Things Every WordPress Plugin Developer Should Know

By providing quick access to essential debug information, the BlackBox plugin is a big-timer when it comes to debugging your WordPress plugin.

Prefix Your Functions

One of the first things that bit me when I started developing WordPress plugins was finding out that other plugin developers sometimes use the same names for functions that I use. For example, function names like copy_file(), save_data(), and database_table_exists() have a decent chance of being used by other plugins in addition to yours.

The reason for this is because when WordPress activates a plugin, PHP loads the functions from the plugin into the WordPress execution space, where all functions from all plugins live together. There is no separation or isolation of functions for each plugin, which means that each function must be uniquely named.

Fortunately, there is an easy way around this, and it’s to name all of your plugin functions with a prefix. For example, the common functions I mentioned previously might now look like this:

function myplugin_copy_file() {
}

function myplugin_save_data() {
}

function myplugin_database_table_exists() {
}

Another common naming convention is to use a prefix that is an abbreviation of your plugin’s name, such as “My Awesome WordPress Plugin”, in which case the function names would be:

function mawp_copy_file() {
}

function mawp_save_data() {
}

function mawp_database_table_exists() {
}

There is one caveat to this, however. If you use PHP classes that contain your functions (which in many cases is a good idea), you don’t really have to worry about clashing with functions defined elsewhere. For example, let’s say you have a class in your plugin named “CommonFunctions” with a copy_file() function, and another plugin has the same copy_file() function defined, but not in a class. Invoking the two functions would look similar to this:

// Calls the copy_file() function from your class
$common = new CommonFunctions();
$common->copy_file();

// Calls the copy_file() function from the other plugin
copy_file();

By using classes, the need to explicitly prefix your functions goes away. Just keep in mind that WordPress will raise an error if you use a function name that’s already taken, so keep an eye on the debug.log file to know if you’re in the clear or not.

Global Paths Are Handy

Writing the PHP code to make your plugin work is one thing, but if you want to make it look and feel good at the same time, you’ll need to include some images, CSS, and perhaps a little JavaScript as well (maybe in the form of a jQuery plugin). And in typical fashion, you’ll most likely organize these files into their own folders, such as “images”, “css”, and “js”.

That’s all well and good, but how should you code your plugin so that it can always find those files, no matter what domain the plugin is running under? The best way that I’ve found is to create your own global paths that can be used anywhere in your plugin code.

For example, I always create four global variables for my plugins, one each for the following:

  • The path to the theme directory
  • The name of the plugin
  • The path to the plugin directory
  • The url of the plugin

For which the code looks like this:

if (!defined('MYPLUGIN_THEME_DIR'))
    define('MYPLUGIN_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());

if (!defined('MYPLUGIN_PLUGIN_NAME'))
    define('MYPLUGIN_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));

if (!defined('MYPLUGIN_PLUGIN_DIR'))
    define('MYPLUGIN_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . MYPLUGIN_PLUGIN_NAME);

if (!defined('MYPLUGIN_PLUGIN_URL'))
    define('MYPLUGIN_PLUGIN_URL', WP_PLUGIN_URL . '/' . MYPLUGIN_PLUGIN_NAME);

Having these global paths defined lets me write the code below in my plugin anywhere I need to, and I know it will resolve correctly for any website that uses the plugin:

$image = MYPLUGIN_PLUGIN_URL . '/images/my-image.jpg';
$style = MYPLUGIN_PLUGIN_URL . '/css/my-style.css';
$script = MYPLUGIN_PLUGIN_URL . '/js/my-script.js';

Store the Plugin Version for Upgrades

When it comes to WordPress plugins, one of the things you’ll have to deal with sooner or later is upgrades. For instance, let’s say the first version of your plugin required one database table, but the next version requires another table. How do you know if you should run the code that creates the second database table?

I suggest storing the plugin version in the WordPress database so that you can read it later to decide certain upgrade actions your plugin should take. To do this, you’ll need to create a couple more global variables and invoke the add_option() function:

if (!defined('MYPLUGIN_VERSION_KEY'))
    define('MYPLUGIN_VERSION_KEY', 'myplugin_version');

if (!defined('MYPLUGIN_VERSION_NUM'))
    define('MYPLUGIN_VERSION_NUM', '1.0.0');

add_option(MYPLUGIN_VERSION_KEY, MYPLUGIN_VERSION_NUM);

I certainly could have simply called add_option('myplugin_version', '1.0.0'); without the need for the global variables, but like the global path variables, I’ve found these just as handy for using in other parts of a plugin, such as a Dashboard or About page.

Also note that update_option() could have been used instead of add_option(). The difference is that add_option() does nothing if the option already exists, whereas update_option() checks to see if the option already exists, and if it doesn’t, it will add the option to the database using add_option(); otherwise, it updates the option with the value provided.

Then, when it comes time to check whether or not to perform upgrade actions, your plugin will end up with code that looks similar to this:

$new_version = '2.0.0';

if (get_option(MYPLUGIN_VERSION_KEY) != $new_version) {
    // Execute your upgrade logic here

    // Then update the version value
    update_option(MYPLUGIN_VERSION_KEY, $new_version);
}

Use dbDelta() to Create/Update Database Tables

If your plugin requires its own database tables, you will inevitably need to modify those tables in future versions of your plugin. This can get a bit tricky to manage if you’re not careful, but WordPress helps alleviate this problem by providing the dbDelta() function.

A useful feature of the dbDelta() function is that it can be used for both creating and updating tables, but according to the WordPress codex page “Creating Tables with Plugins”, it’s a little picky:

  • You have to put each field on its own line in your SQL statement.
  • You have to have two spaces between the words PRIMARY KEY and the definition of your primary key.
  • You must use the keyword KEY rather than its synonym INDEX and you must include at least one KEY.

Knowing these rules, we can use the function below to create a table that contains an ID, a name, and an email:

function myplugin_create_database_table() {
    global $wpdb;
    $table = $wpdb->prefix . 'myplugin_table_name';

    $sql = "CREATE TABLE " . $table . " (
              id INT NOT NULL AUTO_INCREMENT,
              name VARCHAR(100) NOT NULL DEFAULT '',
              email VARCHAR(100) NOT NULL DEFAULT '',
              UNIQUE KEY id (id)
              );";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}

Important: The dbDelta() function is found in wp-admin/includes/upgrade.php, but it has to be included manually because it’s not loaded by default.

So now we have a table, but in the next version we need to expand the size of the name column from 100 to 250. Fortunately dbDelta() makes this straightforward, and using our upgrade logic previously, the next version of the plugin will have code similar to this:

$new_version = '2.0.0';

if (get_option(MYPLUGIN_VERSION_KEY) != $new_version) {
    myplugin_update_database_table();
    update_option(MYPLUGIN_VERSION_KEY, $new_version);
}

function myplugin_update_database_table() {
    global $wpdb;
    $table = $wpdb->prefix . 'myplugin_table_name';

    $sql = "CREATE TABLE " . $table . " (
              id INT NOT NULL AUTO_INCREMENT,
              name VARCHAR(250) NOT NULL DEFAULT '', // Bigger name column
              email VARCHAR(100) NOT NULL DEFAULT '',
              UNIQUE KEY id (id)
              );";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}

While there are other ways to create and update database tables for your WordPress plugin, it’s hard to ignore the flexibility of the dbDelta() function.

Know the Difference Between include, include_once, require, and require_once

There will come a time during the development of your plugin where you will want to put code into other files so that maintaining your plugin is a bit easier. For instance, a common practice is to create a functions.php file that contains all of the shared functions that all of the files in your plugin can use.

Let’s say your main plugin file is named myplugin.php and you want to include the functions.php file. You can use any of these lines of code to do it:

include 'functions.php';
include_once 'functions.php';

require 'functions.php';
require_once 'functions.php';

But which should you use? It mostly depends on your expected outcome of the file not being there.

  • include: Includes and evaluates the specified file, throwing a warning if the file can’t be found.
  • include_once: Same as include, but if the file has already been included it will not be included again.
  • require: Includes and evaluates the specified file (same as include), but instead of a warning, throws a fatal error if the file can’t be found.
  • require_once: Same as require, but if the file has already been included it will not be included again.

My experience has been to always use include_once because a) how I structure and use my files usually requires them to be included once and only once, and b) if a required file can’t be found I don’t expect parts of the plugin to work, but it doesn’t need to break anything else either.

Your expectations may vary from mine, but it’s important to know the subtle differences between the four ways of including files.

Use bloginfo(‘wpurl’) Instead of bloginfo(‘url’)

By and large, WordPress is installed in the root folder of a website; it’s standard operating procedure. However, every now and then you’ll come across websites that install WordPress into a separate subdirectory under the root. Seems innocent enough, but the location of WordPress is critically important.

To demonstrate, in the “General Settings” section of the WordPress admin panel, you’ll find the “WordPress address (URL)” and “Site address (URL)” settings, and for sites where WordPress is installed into the root directory, they will have the exact same values:

General-settings-same-url in Ten Things Every WordPress Plugin Developer Should Know

But for sites where WordPress is installed into a subdirectory under the root (in this case a “wordpress” subdirectory), their values will be different:

General-settings-different-url in Ten Things Every WordPress Plugin Developer Should Know

At this stage it’s important to know the following:

  • bloginfo(‘wpurl’) equals the “WordPress address (URL)” setting
  • bloginfo(‘url’) equals the “Site address (URL)” setting

Where this matters is when you need to build URLs to certain resources or pages. For example, if you want to provide a link to the WordPress login screen, you could do this:

// URL will be http://mydomain.com/wp-login.php
<a href="<?php bloginfo('url') ?>/wp-login.php">Login</a>

But that won’t resolve to the correct URL in the scenario such as the one above where WordPress is installed to the “wordpress” subdirectory. To do this correctly, you must use bloginfo('wpurl') instead:

// URL will be http://mydomain.com/wordpress/wp-login.php
<a href="<?php bloginfo('wpurl') ?>/wp-login.php">Login</a>

Using bloginfo('wpurl') instead of bloginfo('url') is the safest way to go when building links and URLs inside your plugin because it works in both scenarios: when WordPress is installed in the root of a website and also when it’s installed in a subdirectory. Using bloginfo('url') only gets you the first one.

How and When to Use Actions and Filters

WordPress allows developers to add their own code during the execution of a request by providing various hooks. These hooks come in the form of actions and filters:

  • Actions: WordPress invokes actions at certain points during the execution request and when certain events occur.
  • Filters: WordPress uses filters to modify text before adding it to the database and before displaying it on-screen.

The number of actions and filters is quite large, so we can’t get into them all here, but let’s at least take a look at how they are used.

Here’s an example of how to use the admin_print_styles action, which allows you to add your own stylesheets to the WordPress admin pages:

add_action('admin_print_styles', 'myplugin_admin_print_styles');

function myplugin_admin_print_styles() {
    $handle = 'myplugin-css';
    $src = MYPLUGIN_PLUGIN_URL . '/styles.css';

    wp_register_style($handle, $src);
    wp_enqueue_style($handle);
}

And here’s how you would use the the_content filter to add a “Follow me on Twitter!” link to the bottom of every post:

add_filter('the_content', 'myplugin_the_content');

function myplugin_the_content($content) {
    $output = $content;
    $output .= '<p>';
    $output .= '<a href="http://twitter.com/username">Follow me on Twitter!</a>';
    $output .= '</p>';
    return $output;
}

It’s impossible to write a WordPress plugin without actions and filters, and knowing what’s available to use and when to use them can make a big difference. See the WordPress codex page “Plugin API/Action Reference” for the complete list of actions and the page “Plugin API/Filter Reference” for the complete list of filters.

Tip: Pay close attention to the order in which the actions are listed on its codex page. While not an exact specification, my experimentation and trial-and-error has shown it to be pretty close to the order in which actions are invoked during the WordPress request pipeline.

Add Your Own Settings Page or Admin Menu

Many WordPress plugins require users to enter settings or options for the plugin to operate properly, and the way plugin authors accomplish this is by either adding their own settings page to an existing menu or by adding their own new top-level admin menu to WordPress.

How to Add a Settings Page

A common practice for adding your own admin settings page is to use the add_menu() hook to call the add_options_page() function:

add_action('admin_menu', 'myplugin_admin_menu');

function myplugin_admin_menu() {
    $page_title = 'My Plugin Settings';
    $menu_title = 'My Plugin';
    $capability = 'manage_options';
    $menu_slug = 'myplugin-settings';
    $function = 'myplugin_settings';
    add_options_page($page_title, $menu_title, $capability, $menu_slug, $function);
}

function myplugin_settings() {
    if (!current_user_can('manage_options')) {
        wp_die('You do not have sufficient permissions to access this page.');
    }

    // Here is where you could start displaying the HTML needed for the settings
    // page, or you could include a file that handles the HTML output for you.
}

By invoking the add_options_page() function, we see that the “My Plugin” option has been added to the built-in Settings menu in the WordPress admin panel:

Admin-menu-options-page in Ten Things Every WordPress Plugin Developer Should Know

The add_options_page() function is really just a wrapper function on top of the add_submenu_page() function, and there are other wrapper functions that do similar work for the other sections of the WordPress admin panel:

  • add_dashboard_page()
  • add_posts_page()
  • add_media_page()
  • add_links_page()
  • add_pages_page()
  • add_comments_page()
  • add_theme_page()
  • add_plugins_page()
  • add_users_page()
  • add_management_page()

How to Add a Custom Admin Menu

Those wrapper functions work great, but what if you wanted to create your own admin menu section for your plugin? For example, what if you wanted to create a “My Plugin” admin section with more than just the Settings page, such as a Help page? This is how you would do that:

add_action('admin_menu', 'myplugin_menu_pages');

function myplugin_menu_pages() {
    // Add the top-level admin menu
    $page_title = 'My Plugin Settings';
    $menu_title = 'My Plugin';
    $capability = 'manage_options';
    $menu_slug = 'myplugin-settings';
    $function = 'myplugin_settings';
    add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function);

    // Add submenu page with same slug as parent to ensure no duplicates
    $sub_menu_title = 'Settings';
    add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);

    // Now add the submenu page for Help
    $submenu_page_title = 'My Plugin Help';
    $submenu_title = 'Help';
    $submenu_slug = 'myplugin-help';
    $submenu_function = 'myplugin_help';
    add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
}

function myplugin_settings() {
    if (!current_user_can('manage_options')) {
        wp_die('You do not have sufficient permissions to access this page.');
    }

    // Render the HTML for the Settings page or include a file that does
}

function myplugin_help() {
    if (!current_user_can('manage_options')) {
        wp_die('You do not have sufficient permissions to access this page.');
    }

    // Render the HTML for the Help page or include a file that does
}

Notice that this code doesn’t use any of the wrapper functions. Instead, it calls add_menu_page() (for the parent menu page) and add_submenu_page() (for the child pages) to create a separate “My Plugin” admin menu that contains the Settings and Help pages:

Admin-menu-custom in Ten Things Every WordPress Plugin Developer Should Know

One advantage of adding your own custom menu is that it’s easier for users to find the settings for your plugin because they aren’t buried within one of the built-in WordPress admin menus. Keeping that in mind, if your plugin is simple enough to only require a single admin page, then using one of the wrapper functions might make the most sense. But if you need more than that, creating a custom admin menu is the way to go.

Provide a Shortcut to Your Settings Page with Plugin Action Links

In much the same way that adding your own custom admin menu helps give the sense of a well-rounded plugin, plugin action links work in the same fashion. So what are plugin action links? It’s best to start with a picture:

Plugin-action-links-none in Ten Things Every WordPress Plugin Developer Should Know

See the “Deactivate” and “Edit” links underneath the name of the plugin? Those are plugin action links, and WordPress provides a filter named plugin_action_links for you to add more. Basically, plugin action links are a great way to add a quick shortcut to your most commonly used admin menu page.

Keeping with our Settings admin page, here’s how we would add a plugin action link for it:

add_filter('plugin_action_links', 'myplugin_plugin_action_links', 10, 2);

function myplugin_plugin_action_links($links, $file) {
    static $this_plugin;

    if (!$this_plugin) {
        $this_plugin = plugin_basename(__FILE__);
    }

    if ($file == $this_plugin) {
        // The "page" query string value must be equal to the slug
        // of the Settings admin page we defined earlier, which in
        // this case equals "myplugin-settings".
        $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=myplugin-settings">Settings</a>';
        array_unshift($links, $settings_link);
    }

    return $links;
}

With this code in place, now when you view your plugins list you’ll see this:

Plugin-action-links-settings in Ten Things Every WordPress Plugin Developer Should Know

Here we provided a plugin action link to the Settings admin page, which is the same thing as clicking on Settings from our custom admin menu. The benefit of the plugin action link is that users see it immediately after they activate the plugin, thus adding to the overall experience.

Additional Resources

I’ve covered a lot in this article, but there’s plenty more out there to keep you busy awhile. The most comprehensive documentation for WordPress plugin development can be found on the WordPress Codex, a huge collection of pages documenting everything that is WordPress. Below are some of the more pertinent links from the codex you’ll need:

I also suggest reading Joost de Valk’s article “Lessons Learned From Maintaining a WordPress Plug-In“, which provides more good tips on WordPress plugin development.

(vf) (ik)


© Dave Donaldson for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us
Post tags: , , ,


  •   
  • Copyright © 1996-2010 BlogmyQuery - BMQ. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress