BloggingPro Plugins: Add Subheadings to Your Blog Posts with the SubHeading WordPress Plugin

September 2nd, 2010

Is the title box always too small for your blog posts?  Do you find yourself wishing you could add more details or catchy copy to your blog post titles?  Are you tired of adding header tags to the subheadings you create for your blog posts?  Or perhaps you just want subheadings that appear directly beneath the title of your live blog posts rather than at the top of the body copy?

If you answered ‘yes’ to any of the above questions, then the SubHeading WordPress plugin is for you!



Mark on WordPress: Upcoming WordPress Events

September 1st, 2010

On September 8th, I’ll be at the Tampa Bay WordPress meetup to talk about WordPress custom post types. If you’re a WordPress developer or themer in the area, you should stop by! The meetup is at 7pm at CDB’s Southside in South Tampa.

WordCamp Portland is on September 18th and 19th at Webtrends. My talk is called “Swan Dive! …into the Best WordPress of your Life,” and it’s all about using WordPress to its fullest. Everything from hosting to scaling and everything from upgrades to insider ninja moves will be covered.



Justin Tadlock: Realizing a dream: Writing a WordPress book

September 1st, 2010

This is a story (the short version) of my personal journey to becoming an author. Thank you to everyone in the WordPress community that has helped make this happen by allowing me to be a part of the community over the last few years.

The early years

As I was growing up in smalltown Alabama, I always wanted to be a writer. From about the time I could hold a crayon, I was writing something. Writing on the walls. The kitchen table. Occasionally, on paper. From what my parents tell me, I could do this quite well at about the age of 3.

During my pre-teen years, I wanted to follow in my father’s footsteps and write songs, so music and lyrics were my first introduction to how beautiful language could be.

Eventually, I outgrew my songwriting phase. Be glad I did. The world certainly doesn’t need any more boy-band pop songs. I figured I could offer something of a little more substance to the world.

High school

In high school, I had the most wonderful English teacher. She was one of those teachers that understood that literacy is not just about basic reading and writing skills. Literature. Technology. Music. Film. Those are the things that matter. Don’t get me wrong. We still had to do the boring high school English class stuff. But, she opened my mind to the world outside of the small town I was living in.

At some point during my senior year I realized that I wanted to write. I mean really write. It was the first time I’d ever put “write a book” on my list of life goals.

College

I graduated from Auburn University in 2007 with a B.A. in English and a concentration in creative writing and journalism.

When I began college, I didn’t plan on having a degree in English. I was in software engineering. Then I was in hotel and restaurant management. Then I was in software engineering again. Like many other college students, I bounced around majors a few times. It was tough finding something that was both enjoyable and challenging.

Despite protests from friends and a few from my family, I decided to take the plunge and declare myself as an English major. What I found was something that I loved. How could anyone not love reading 20+ books a semester? I had the time of my life exploring ethnographic studies, novels, and even the Bible as literature.

Each professor impacted my life in some way. Each class allowed me to explore other cultures. Each friend I got to know, helped shape me.

By the time I graduated, I had narrowed my list of life goals down to a few things. At the top of that list: Write something that has an impact on someone’s life.

At some point during college, I also started learning HTML, CSS, PHP, and WordPress.

After college

Harsh realization that life is not all roses and peaches.

…Time spent wandering the globe…

I moved back to Alabama last year because I wanted to get back to my roots. I wanted to engulf myself in the white-trash, trailer-park, tobacco-chewing culture that I hadn’t been a part of in so long.

The plan: Observe the culture. Write.

I could give you at least 100 reasons why I haven’t finished a novel yet, but I won’t. There’s no point in trying to justify losing sight of my goal.

I also spent some more time playing around with WordPress during this phase of my life. I suppose that time could’ve been spent working on the great Southern American novel.

An opportunity

A few months ago, I received an email about collaborating on a WordPress plugin development book for Wrox, a company devoted to publishing books “by programmers for programmers.”

At first, I was a bit hesitant to take on any extra WordPress projects. It also meant that I wouldn’t be able to apply for teaching jobs this school year, which was one of my goals for 2010. And, it wasn’t quite what I had in mind when I put “write a book” on my list of life goals.

However, it was an opportunity to write about something I’m passionate about.

The book

We have a great team of WordPress minds melding for what will be an awesome WordPress plugin development book. Brad Williams, Ozh Richard, and I are the writers. We’ve also picked up Andrew Nacin as our WordPress technical editor.

As a sidenote to this: I’m convinced that Andrew is actually a super-advanced robot that has been programmed to do nothing other than write awesome WordPress code. And, I’m happy to have him on the team.

I don’t want to get into too many technical details about the book yet. I do want to say that it will be a great resource for professional plugin development. We will put everything we have into making this the best book on creating plugins available for WordPress.

For me, this book announcement is mostly about sharing my personal journey to this point. I am thankful that Wrox, Brad, and Ozh are giving me an opportunity to realize one of my lifelong dreams. And, I hope that all my readers will come along on this journey with me (and buy the book when it’s published in March).

Also, check out theses posts by Brad and Ozh:


YoastWordPress - Archives - Yoast - Tweaking Websites: Quick tip: paths and URLs in WordPress

September 1st, 2010

I was reading an article on Sitepoint about custom write panels the other day when I got heavily annoyed. The direct reason for this was one of their code examples and the authors apparent incomplete knowledge of the WordPress API's most basic functions and constants. In that example, he does the following:

define(  
  'MY_WORDPRESS_FOLDER',
  $_SERVER['DOCUMENT_ROOT']  
);  
define(  
  'MY_THEME_FOLDER',  
  str_replace("",'/',dirname(__FILE__))  
);  
define(  
  'MY_THEME_PATH',  
  '/' . substr(  
    MY_THEME_FOLDER,  
    stripos(MY_THEME_FOLDER,'wp-content')  
  )  
);

That annoyed me, quite a bit. Why? Well because if people write articles about stuff like custom write panels, I expect them to know a bit about the basics of the WordPress API. And well, the WordPress API has constants and functions for these things. So let me introduce you to them in the same order as the author of the articles did his defines above:

ABSPATH constant

Not only is their method inconvenient, it's wrong for a lot of installs. You see, some people install WordPress in a subdirectory, and depending on what you need, there are two different paths you might need. ABSPATH is a constant that always returns the home of WordPress. So if WordPress is in the wp/ subdirectory, it would give you something like: /home/username/public_html/wp/. If WordPress were installed in the root, it would just return /home/username/public_html/. Now I don't know how they're using it, as it's not used in this particular article, but they'd have to be very cautious with that.

TEMPLATEPATH constant

The second two things they're doing are possibly even weirder. First they define a constant MY_THEME_FOLDER, which is basically the path to the current theme. WordPress has a very convenient constant for that: TEMPLATEPATH. Since they're using it in an include, that's probably what they need. Would save about 4 lines of code. Note that what they call a "folder" is actually a path.

get_template_directory_uri()

This is were they really go wrong. You see, they define a constant MY_THEME_PATH, and then use it as a URL in a call to wp_enqueue_style(), in other words: to enqueue a style sheet. Now paths and URLs are different animals altogether, and they don't mix well. Take this example:

  • My blog is installed in a subdirectory /wp/
  • Because of that MY_THEME_FOLDER has been defined as follows:
    /home/user/public_html/wp/wp-content/themes/example-theme
  • The code that sets MY_THEME_PATH turns that into:
    /wp-content/themes/example-theme
  • The stylesheet is now included with the following path:
    /wp-content/themes/example-theme/custom/book_panel.css
  • This causes a 404 (file not found error) because that directory simply doesn't exist! It should have been:
    /wp/wp-content/themes/example-theme/custom/book_panel.css

The proper way of doing the enqueue would thus have been the following:

wp_enqueue_style(  
    'my_meta_css',  
     get_template_directory_uri(). '/custom/book_panel.css'  
  );

Conclusion

I hope you understand why this annoys me. This is exactly the kind of coding that gives WordPress coders out there a bad name, as 5 - 10% of people out there trying this will not get it to work. If you want to prevent from making such mistakes, there's plenty of resources to learn about these things, or look them up. Two starting points would be the codex and my own cross reference of the WordPress source along with its very convenient WordPress source search function.

Quick tip: paths and URLs in WordPress is a post from Joost de Valk's Yoast - Tweaking Websites.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on WordPress hosting!


planetOzh: Into Plugins? You Will Love This. #plugindevbook

September 1st, 2010

So, peeps, I have good news and bad news. And by good news, I mean super mega hyper exciting announcement.

The good news: three persons, carefully handpicked among all the three most important people in WordPress, are writing a book, I mean, THE book, on WordPress Plugin Development. These three fine chaps are Brad Williams, Justin Tadlock and me.

Let me rephrase this in a way that will more reflect my state of mind and how I think about this. OMFG I’m writing a fucking book!!!1!!one!!eleven

Ozh' State of mind (allegory)

The book, entitled “Professional WordPress Plugin Development” (yeah, my suggestion of “Pluginz That Pwn” didn’t make it through) should hit shelves in March 2011 and will be published by the cool geek lovers from WROX, in the same collection as Brad’s “Professional WordPress“.

Not only this is a super author team, but also we’ll be lended a hand by a top notch Technical Editor, an incredible guy who is a bit more active than hyperactive kids drinking coffee on steroids, who blogs, commits, speaks, twitts and never sleeps, also known as Andrew Nacin. His role will be to crack the whip and molest us when we write dumbities and acting like we actually know a thing or two about a thing or two (which should happen more than he hopes)

So far the project is running great and what we have written already is, hmm, let me carefully pick an appropriate word, I’d say, like, awesome.

In the next few months be sure to follow @Brad, @Justin and @me for some cool info and exciting news about the book and how we’re doing :)

Oh, and the bad news: I have a fracking sprained index finger on my right hand. Which means I can kiss good bye my 60ish WPM, precisely when I have to write pages as if they were raining. Bleh²x100.


(cc) Ozh for planetOzh, 2010. | Permalink | 8 comments | Add to del.icio.us | splogmenotplz
Read more posts tagged with: , ,

Related posts

Feed enhanced by Better Feed from Ozh


Brad Williams Blog: New Book: Professional WordPress Plugin Development!

September 1st, 2010

I couldn’t be more excited to announce a new book I’m co-authoring: Professional WordPress Plugin Development!

WROX logoThis book will continue the Professional WordPress series with a focus on plugin development in WordPress. This alone is exciting news, but of course I’m not writing this book on my own. I’ve brought in two of the best known WordPress developers in the business: Ozh Richard and Justin Tadlock! Anyone who works with WordPress will be very familiar with these two guys. They both have a huge reputation for writing some of the most detailed, easy to understand, and extremely knowledgeable tutorials out there for plugin and WordPress development.

The excitement doesn’t stop there! We’ve also brought in two great Technical Editors for our new book. The first is Andrew Nacin. Anyone who follows the core development of WordPress will be very familiar with Andrew. Andrew is one of the most active core contributors to the WordPress project and his endless knowledge of the internals of WordPress are sure to help take our book to the next level. The second Tech Editor is Doug Vann. Doug is known for his expertise and knowledge in the open source CMS world. Doug will approach this book as a CMS user, thinking outside the box of a normal developer.

This book will be jam packed with plugin knowledge from beginner topics like creating your first plugin, security, and settings, to more advanced topics like JavaScript and AJAX, Cron, and the mysterious Rewrite API. This book will have something for everyone looking to learn or expand their knowledge on building professional plugins in WordPress.

You can following our process during the writing of this book using the hash tag #plugindevbook on Twitter. The book is currently planned for a March 2011 release date.

Related posts:

  1. Professional WordPress – New Book Coming Soon!
  2. Professional WordPress Is In Production!
  3. Professional WordPress Has Hit The Shelves!


Digging into WordPress: Version 3.0 Launch!

September 1st, 2010

It’s here! Digging into WordPress Version 3.0 is here and it’s packed with goodness, including a new chapter on WordPress 3, updated core content, and a super-sleek new cover. Check it out:

[ Digging into WordPress V3 ]
DiW3 cover by Chris Coyier

Updated Core Material

Much has changed with WordPress since our previous book update (v2), so for version 3.0 we went through the book and updated/removed outdated core content. Everything is now hot-wired and fine-tuned to the latest version of WordPress, with new popouts and fresh links throughout the book. Here’s a close-up of one the updated pages (a flow-chart for templates):

[ Digging into WordPress Screenshot ]

New Chapter on WordPress 3.0

WordPress 3.0 is better than ever. Released on June 17th 2010, WP3.0 features tons of new functionality and CMS capabilities. So much good stuff, that we added an entire chapter covering all the best new WP3.0 features:

  • New default theme
  • Custom Admin usernames
  • How to customize your background
  • How to setup and use WP MultiSite
  • Custom taxonomies, menus, and post types

Plus a whole bunch of other stuff, including how to use the built-in shortlink feature, author templates, comment-form template-tags, and more. It’s 20+ pages of new WP3.0 content.

[ Digging into WordPress Screenshot ]
Detail-view of new WP3 content

Included with Purchase

Here’s what you get for $27:

  • Beautiful, full-color, easy-to-read design
  • Nearly 450 pages of practical, how-to WordPress content
  • 3 Free Themes: All Ajax, Lines & Boxes, and Plastique
  • Free Lifetime Updates (current book owners received version 3.0 yesterday)
  • Friendly, helpful customer support :)

Like WordPress itself, Digging into WordPress gets better with each new version. And the nice thing about PDF format is that you can read the book anywhere, even on the iPad. Plus you get useful stuff like actual, clickable hyperlinks and linked Table of Contents. Also the PDF format makes it easy to copy/paste code and other content, so you have everything all in one place. You can learn more and get the book here.

Printed Copies

We were sort of on the fence about printing more physical copies of the book, but after some great feedback, everything fell into place. Our current goal is to make printed copies of v3.0 available in September/October. The printed books seem to disappear quickly, so if you want a copy stay tuned for the announcement post.

Updated Sample PDF

Here is an updated Sample Chapter showing the new Table of Contents and part of Chapter 3. For more information on Digging into WordPress, check out the Official DiW Bookstore at DigWP.com, the free companion site for the book, featuring tons of awesome WordPress tips, tricks, and tutorials. So here’s to DiW version 3.0 and no sign of slowing down ;)

Questions about the book?

Shortlink for this post:


Perishable Press: Digging into WordPress Version 3.0

September 1st, 2010

It’s here! Digging into WordPress Version 3.0 is packed with goodness, including a new chapter on WP3, updated core content, and a super-sleek new cover.

[ Digging into WordPress V3 ]
DiW3 cover by Chris Coyier

Updated Core Material

Much has changed with WordPress since our previous book update (v2), so for version 3.0 we went through the book and updated/removed outdated core content. Everything is now hot-wired and fine-tuned to the latest version of WordPress, with new popouts and fresh links throughout the book. Here’s a shot from one of the updated core pages (a flow-chart for page templates – more graphic wizardry from Chris!):

[ Digging into WordPress Screenshot ]

New Chapter on WordPress 3.0

WordPress 3.0 is better than ever. Released on June 17th 2010, WP3.0 features tons of new functionality and CMS capabilities. So much good stuff, that we added an entire chapter covering all the best new WP3.0 features:

  • New default theme
  • Custom Admin usernames
  • How to customize your background
  • How to setup and use WP MultiSite
  • Custom taxonomies, menus, and post types

Plus other great stuff like how to use the built-in shortlink feature, author templates, comment-form template-tags, and more. It’s 20+ pages of new WP3.0 content.

[ Digging into WordPress Screenshot ]

[ Digging into WordPress Screenshot ]

Included with Purchase

Here’s what you get for your hard-earned $27:

  • Beautiful, full-color, easy-to-read design
  • Nearly 450 pages of practical, how-to WordPress content
  • 3 Free Themes: All Ajax, Lines & Boxes, and Plastique
  • Free Lifetime Updates (current book owners received version 3.0 yesterday)
  • Friendly, helpful customer support :)

[ Get the book ] Like WordPress itself, Digging into WordPress gets better with each new version. And the nice thing about PDF format is that you can read the book anywhere, even on eReaders like the iPad. Plus you get useful stuff like actual, clickable hyperlinks and linked Table of Contents. Also, the PDF format makes it easy to copy/paste code and other content, so you have everything all in one place. You can learn more and get the book here.

Printed Copies

[ Print Edition ] We were sort of on the fence about printing more copies of the book, but after some great feedback, everything fell into place. Our current goal is to make printed copies of v3.0 available sometime in September/October. The printed books tend to go fast, so if you want a copy stay tuned for the announcement post and more information.

Updated Sample PDF

[ PDF Download ] Here is an updated Sample Chapter showing the new Table of Contents and part of Chapter 3. For more information on Digging into WordPress, check out the Official DiW Bookstore at DigWP.com, the free companion site for the book, featuring tons of awesome WordPress tips, tricks, and tutorials. As always, comments, suggestions, and concerns are welcome.

Get the book!

Source: Perishable Press

Take your WordPress skills to the next level with Digging into WordPress!

Related articles


The WordPress PodcastPodcast Archives - The WordPress Podcast: Listen to Liz Strauss: “Treat Your Blog Like a Business!”

August 31st, 2010

Liz StraussLiz Strauss gave a masterclass tonight; at least, that’s how it felt to both Frederick and myself. We talked about communicating with your audience, and Liz shared some experiences about open comment nights. We discussed positioning yourself and your blog, and how important personal branding can be.

She told us about feedback loops, and how to use them to listen to your users / clients / audience. She tought us to build our network before we need it, and why and how you should be treating your blog like a business, even if it’s just a hobby. Aren’t you curious yet? Start listening then. You’ll be a wiser man or woman for it at the end of this.


coffee2code.com: Show Pending Comments Count v1.1

August 31st, 2010

I’d like to announce the official release of the updated Show Pending Comments Count plugin (v1.1) for WordPress.

Display the pending comments count next to the approved comments count in the admin listing of posts.

Minor update. Miscellaneous tweaks; renamed class; noted compatibility with WP 3.0+.

For more details, instructions, and the download link, visit the plugin’s official homepage at :
http://coffee2code.com/wp-plugins/show-pending-comments-count/.

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

Read more for a detailed ChangeLog of the release.

Detailed ChangeLog

These are the detailed changes, which may or may not make sense to you depending on your familiarity with the previous features and internals of the plugin.

  • Don’t even define class if not in the admin
  • Rename class from ‘ShowPendingCommentsCount’ to ‘c2c_ShowPendingCommentsCount’
  • Output JS via ‘admin_print_footer_scripts’ hook rather than ‘admin_footer’
  • Assign object instance to global variable, $c2c_show_pending_comments_count, to allow for external manipulation
  • Instantiate object within primary if(!class_exists()) check (at end)
  • Note compatibility with WP 3.0+
  • Minor code reformatting (spacing)
  • Remove documentation and instructions from top of plugin file (all of that and more are contained in readme.txt)
  • Add Upgrade Notice section to readme.txt
  • Remove trailing whitespace

Lorelle on WordPress News: Mind Blowing WordPress Plugins

August 31st, 2010
In Dallas, August 29, 2010, at OpenCamp I presented “Mind Blowing WordPress Plugins.” Here are the WordPress Plugins and more features during my presentation. Let me first define what my qualifications for a “mind blowing WordPress Plugin” were, as I had to sift through thousands of Plugins and then filter down to include the following [...]

coffee2code.com: Text Replace v3.0

August 31st, 2010

I’d like to announce the official release of the updated Text Replace plugin (v3.0) for WordPress.

Replace text with other text. Handy for creating shortcuts to common, lengthy, or frequently changing text/HTML, or for smilies.

The plugin’s official homepage is located at :
http://coffee2code.com/wp-plugins/text-replace.

Significant and recommended update. Highlights: re-implementation; added more settings and hooks for customization; allow replacing HTML; allow case insensitivity; disable autowrap in textarea; misc improvements; verified WP 3.0 compatibility; dropped compatibility with WP older than 2.8.

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

Read more for a detailed ChangeLog of the release.

Detailed ChangeLog

These are the detailed changes, which may or may not make sense to you depending on your familiarity with the previous features and internals of the plugin.

  • Re-implementation by extending C2C_Plugin_012, which among other things adds support for:
  • * Reset of options to default values
  • * Better sanitization of input values
  • * Offload of core/basic functionality to generic plugin framework
  • * Additional hooks for various stages/places of plugin operation
  • * Easier localization support
  • Full localization support
  • Allow for replacement of tags, not just text wrapped by tags
  • Disable auto-wrapping of text in the textarea input field for replacements
  • Support localization of strings
  • Add option to indicate if text replacement should be case sensitive. Default is true.
  • NOTE: The plugin is now by default case sensitive when searching for potential replacements
  • For text_replace(), remove ‘case_sensitive’ argument
  • Allow filtering of text replacements via ‘c2c_text_replace’ filter
  • Allow filtering of hooks that get text replaced via ‘c2c_text_replace_filters’ filter
  • Allow filtering/overriding of text_replace_comments option via ‘c2c_text_replace_comments’ filter
  • Allow filtering/overriding of case_sensitive option via ‘c2c_text_replace_case_sensitive’ filter
  • Filter ‘widget_text’ for text replacement
  • Rename class from ‘TextReplace’ to ‘c2c_TextReplace’
  • Assign object instance to global variable, $c2c_text_replace, to allow for external manipulation
  • Remove docs from top of plugin file (all that and more are in readme.txt)
  • Change description
  • Update readme
  • Minor code reformatting (spacing)
  • Add Filters and Upgrade Notice sections to readme.txt
  • Add .pot file
  • Update screenshot
  • Add PHPDoc documentation
  • Add package info to top of file
  • Update copyright date
  • Remove trailing whitespace

aaron.jorb.in: Users / Roles / Capabilities

August 31st, 2010

I presented on August 30, 2010 to the DC WordPress group on the topic of the Users / Roles / Capabilities system in WordPress.  I presented a small number of slides, and wrote four simple plugins to demonstrate some specific features.   My slides (In HTML / CSS / JS, not some proprietary format) are available at http://aaron.jorb.in/slides/dcwp0810/.  You can navigate through them with your arrow keys, or you press esc and it will take you to thumbnails where you can jump around.

I’ve also posted each of the plugins I wrote, along with a detailed explanation of them.

Shortcodes for Discrimination – Provides shortcodes that allow either users or non users to see certain content

Personalize Read More – Changes the Read More link to call out logged in users by name

Add Role – This adds a role for managing links and removes editors ability to

Replacing Jabber, AIM, and Yahoo messenger with twitter on profile Pages

Repository containing all the code: http://code.google.com/p/wp-user-plugins/

Happy Coding.


aaron.jorb.in: Adding a twitter box to the Profile page in WordPress

August 31st, 2010

I haven’t used AIM in years and I haven’t used Yahoo Messager in even longer.  What I do use is twitter.  Therefore, having a box in the WordPress admin for twitter name is better and with some code I wrote for the , super easy.

add_filter('user_contactmethods', 'jorbin_user_contactmethods');

/**
 * Removes AIM, YAHOO, and Jabber boxes from profile page and adds Twitter in it's place
 *
 */
function jorbin_user_contactmethods($user_contactmethods){
	$new_user_contactmethods['twitter'] = __('Twitter');

	return $new_user_contactmethods;
}

Filtering user_contactmethods is one of the easiest things you can do. All you need to do is return an array where the key is the code based name you want and the value is the public facing name. Easy. As. Pie.


aaron.jorb.in: Add Role

August 31st, 2010

This simple plugin, built for my WordPress DC Presentation on the Users API adds a role called link master, that gets the capability to edit links and also read private posts and pages and also removes the ability for editors to manage categories.

This plugin only needs to run once, and in fact to make sure it doesn’t run the actual adding or roles multiple times, we are going to use an option to prevent it from happening.

class jorbin_role_master{

	/**
	 * Add our init action
	 */
	function __construct(){
		add_action('init', array($this, 'init') );

	}

We start by creating our class, and when it is initialized add an action to the WordPress init hook.

	/**
	 * Check to see if we need to do anything
	 *
	 */
	function init(){
		if ( FALSE === get_option('jorbin_role_master') ):
			$this->populate_role_1();
			add_option('jorbin_role_master', '1', '', 'yes');
		endif;
	}

On the init hook, we check to see if our option exists. If it doesn’t, we call our method that add the roles and then add an option to prevent the role from getting added over and over again.

	/**
	 * Initial role population for link master and strip editor of manage cats
	 *
	 */
	function populate_role_1(){
		add_role('link_master', 'Link Master');

		$role =& get_role('link_master');
		$role->add_cap('read');
		$role->add_cap('manage_links');
		$role->add_cap('read_private_posts');
		$role->add_cap('read_private_pages');

		$role =& get_role('editor');
		$role->remove_cap('manage_categories');

	}

}

$jorbin_role_master = new jorbin_role_master();

Our method that actually calls the option first adds the role, the loads it into a variable where we can call add_cap to add the specific capabilities we want. After that, we remove the manage_categories capability from the editor. After we create a new object with our class, we are good to go. Easy. As. Pie.


aaron.jorb.in: Personalized Read More

August 31st, 2010

Want to make the read more link in WordPress call out the user if they are logged in?  As part of my DC WordPress presentation, i showed that it’s easy as pie and only about 10 lines of code.

The plugin has two parts, the first is the filter that we are adding, and the second is the callback that will do the filtering. All together, it looks like:

add_filter('the_content_more_link', 'jorbin_the_content_more_link_filter', 10, 2);

function jorbin_the_content_more_link_filter($original, $more_link_text){
    global $post;

    if( is_user_logged_in() ) {
		global $current_user;
		get_currentuserinfo();
		$more_link_text = "Hey {$current_user->display_name}, why don't you read more";
    }

    return  '<a href="' . get_permalink() . "#more-{$post->ID}\" class='more-link'>$more_link_text</a>";

}

The callback works by checking if our current user is logged in, if they are we use the $current_user global that we know will be fully populated by get_currentuserinfo() and change the $more_link_text. Otherwise the $more_link_text is the same as what it was originally. Either way, we return the full link. Pretty easy, eh?


aaron.jorb.in: WordPress Shortcodes for Users and Non Users

August 31st, 2010

One of the plugins I wrote for the DC WordPress group’s meeting on Users / Roles / Capabilities demonstrates how to create shortcode that makes some content only visable by users with a certain capability and other content only visable to non logged in viewers.  You can download Shortcodes for Discrimination (along with the other three ) from google code.  Beyond the jump, I go over the code and an explanation of how it works.

The plugin starts with the usual plugin headers and then includes some license information. After that, we start to get to the good stuff.


class jorbin_user_shortcodes{

    /**
     * Add our Init action, which is where the real work begins
     */
    function __construct(){
	add_action( 'init', array( $this , 'init') );
    }

Our first function is the class constructor. This this will get fired before the majority of WordPress is ready to act, all I do is add an action to the init hook which is where the real additions take place.

    /**
     * Starter up
     *
     */
    function init(){
	add_shortcode('user', array( $this, 'logged_in_shortcode') );
	add_shortcode('notuser', array( $this, 'not_logged_in_shortcode') );
    }

The plugins init method (which I hooked to init above) adds two shortcodes using the Shortcode API. The first argument is what our shortcode will be, and the second is our callback. Since it’s happening in a class, our callback is an array. Let’s take a look at the first callback that controls the [user] shortcode.

/**
 *  Shortcode Callback to return shortcode contents only for users with a certain capability
 *
 */
    function logged_in_shortcode($atts, $content){
	extract( shortcode_atts(
	    array('capability' => 'read',)
	    , $atts));

	 if ( current_user_can ($capability)  )
		return $content;
	 else
		return '';

    }

The first part of the function extracts our shortcode attributes so if I did a shortcode like [shortcode foo='bar'], then $foo would be equal to bar. In this case, capability is the attribute and it has the default setting of ‘read’ if no attribute is specified.

After that, we do a check of current_user_can with the capability specified. If it returns true, the content (What is between [user] and [/user] ) is included in the post. Otherwise, nothing is included in that spot.


    function not_logged_in_shortcode($atts, $content){

	if ( is_user_logged_in() )
		return '';
	else
		return $content;

    }

The second callback does something similiar, only this time we check is_user_logged_in which returns true when the person viewing the page is logged in. if it’s true, the content disappears. If it’s false, it’s visible. Easy. As. Pie.

All we have to do to finish things up is call

$jorbin_user_shortcodes = new jorbin_user_shortcodes();

and our shortcode is active. Download the plugin from google code and have fun!


WordPress for Beginners » Tutorials: How to Create a Custom Post Types Archive Page in WordPress

August 31st, 2010

Custom Post Types was one of the awesome features included in WordPress 3.0. One of our users asked us a question on twitter (@wpbeginner), how to create a custom post types archive page. We covered it in our initial article about Custom Post Types, but it wasn’t explained thoroughly. So in this article, we will show you a step by step guide on creating a custom post types archive page in WordPress.

1. Creating a Custom Page Template

First step would be creating a custom page template in WordPress. All we will do is add the following code at the top of our new .php file which we will call (custompt-archives.php).

<?php /* Template Name: Custom Post Type Archive */ ?>

2. Adding the Necessary Template Codes

Next, you will need to add the necessary template codes including but not limited to header, footer, sidebar etc. This area will vary for each site, but for basics it would look like this:

<?php get_header(); ?>
This is where our Loop codes will go in the next step.
<?php get_sidebar(); ?>
<?php get_footer();?>

3. Creating our Custom Archive Loop

The loop is explained in details at the WordPress Codex, and we will be using different aspects of it to create our custom archives loop. Our loop will simply list posts with the necessary information surrounding it. You will be responsible for adding styling around it. Our loop:

<?php
global $query_string;
query_posts($query_string . "post_type=YOUR-CUSTOM-POST-TYPE&post_status=publish&posts_per_page=10");
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>

<?php endwhile;
endif; ?>
<div class="navigation">
	<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>

You can change the number of posts being displayed on the page by changing posts_per_page variable value.

Final Code

Your final code for the custom page should look like this:

<?php /* Template Name: Custom Post Type Archive */
get_header(); ?>

<?php
global $query_string;
query_posts($query_string . "post_type=YOUR-CUSTOM-POST-TYPE&post_status=publish&posts_per_page=10");
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>

<?php endwhile;
endif; ?>
<div class="navigation">
	<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>

<?php get_sidebar(); ?>
<?php get_footer();?>

Now upload this file in your theme’s directory. After you have done that, you need to go to your WordPress admin panel, and create a new page. Call it “Your Custom Post Type” Archives (or whatever you like to call it) and change the page template to “Custom Post Type Archive” as shown here. Do not add anything in the page content area, and simply publish the page. You should now have a custom post types archive page in WordPress.

How to Create a Custom Post Types Archive Page in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Create a Page that Displays a Random Post in WordPress
  2. How to use Custom Post Types in WordPress 3.0
  3. How to Create a Custom Page in WordPress


YoastWordPress - Archives - Yoast - Tweaking Websites: 7 reasons for malfunctioning plugins (and their fixes)

August 31st, 2010

It happens to every plugin author: you receive emails from people that your plugin isn't working. There are about 7 reasons that - for me - seem to be the root cause of up to 95% of these emails, and I thought I'd write them down and show you how I try to handle them.

1. Missing hooks

It annoys the *peep* out of me when I find out that my plugin is in fact working fine, but the *peep* theme author didn't think it necessary to add a wp_head or wp_footer call. This happens more than you'd think, but in most cases you can't really blame the user in question, the theme author is just a moron. For your reference: the wp_head() call needs to exist right before the closing </head> call, and the wp_footer() call should be right before the closing </body> tag.

I used to check for this in my plugin, but the code doing the check caused even more problems, so if you have a good solution for this, that'd be appreciated. I personally think WordPress shouldn't even activate themes without these two hooks.

2. A caching plugin

If you're looking at a cached version of a page, and you've just installed or reconfigured the plugin, chances are the changes aren't reflected in the output yet. In my Google Analytics plugin, I've actually added cache clearing code for W3 Total Cache and WP Super Cache, if you're a plugin author you might find it useful:

<?php
if ( function_exists('w3tc_pgcache_flush') ) {
  w3tc_pgcache_flush();
} else if ( function_exists('wp_cache_clear_cache') ) {
  wp_cache_clear_cache();
}
?>

This is only necessary to do after you've saved settings that would change the output of your plugin of course.

3. You're not supposed to see anything

My Google Analytics plugin has the option to hide the tracking code for certain user levels. Turns out that, when you enable this feature, you're actually not seeing anything at all in the code. That's a good thing, right? Wrong. It meant dozens of emails coming to me in the course of like 6 months, until I was smart enough to add the following message to the output of my plugin for those users:

echo "<!-- Google Analytics tracking code not 
  shown because users over level ".$options["ignore_userlevel"]." 
  are ignored -->n";

Remember that when people use W3 Total Cache's minification feature, they won't even see this. The solution is to wrap it in CDATA tags.

4. You have to actually enable the plugin!

Seems obvious right? Well it doesn't always seem to be. I get this email about once every 2 months "your plugin doesn't work, it's shit. Help me fix it" (sometimes they're nicer, oftentimes they're worse :) ). The best part is when it's followed, like 5 hours later, by "ehm I actually forgot to activate your plugin". Happens to all of us, you know.

5. You haven't configured the plugin yet

There's a reason my plugins now scream at you to configure them as soon as they're activated: I got emails saying it didn't work, when the person emailing simply hadn't even configured the plugin yet. Yeah I know, my plugin should be able to just guess what your analytics account is, I'd love to be able to, but alas... So, especially for those people who think I have magic skills, there's now a warning in the admin:

Not configured warning

And a notice in the source output:

echo "<!-- Google Analytics tracking code not shown because
  you haven't configured the plugin yet. -->";

6. You can't change the settings

Either you're blind or another plugin is malfunctioning, but you can't find the settings page for the plugin you want to configure. Luckily, WordPress has you covered (and yes, some people think that emailing the plugin author is the solution for that). Go to the plugins page, and click on the Settings link for the plugin:

That is of course, if the particular plugin actually was kind enough to include that link... For some reason, some plugin authors seem to think these standards don't have to be adhered to. They deserve to get more email.

7. The plugin is incomplete

When you uploaded the plugin, you might have missed a file, or two. Or the upload went bust. Or the auto install went bust. It happens. I haven't had to build in a check for this yet, since my plugins aren't that big usually, but I noticed this in W3 Total Cache most recent changelog:

Added an additional notification to help users identify
  incomplete installations upon activation.

That shows you two things: A, Frederick knows what he's doing and prevents people from emailing him over issues like that, B, it happens more often than you'd guess.

Your experiences

All the code examples above have been added to my plugin after several support requests for that particular issue. They might save you a fair bit of time if you've just started developing plugins, so feel free to use them. I know a fairly large portion of my readers dabbles with this stuff themselves, I'd love for you to share your experiences in the comments!

7 reasons for malfunctioning plugins (and their fixes) is a post from Joost de Valk's Yoast - Tweaking Websites.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on WordPress hosting!


Brad Williams Blog: SitePoint Podcast Interview with Authors of Wicked WordPress Themes

August 31st, 2010

Last week I had the pleasure of interviewing two of the authors of SitePoint.com’s new book Build Your Own Wicked WordPress Themes on the SitePoint Podcast. I had a great time talking WordPress themes with Allan Cole and Jeffrey Way.

During the podcast we covered some great topics including:

  • Intro to WordPress themes
  • Where to start when building a theme
  • Theme frameworks
  • Theme options
  • Selling themes and what to consider
  • GPL and split-license

I had a chance to read the new book prior to the interview. I would classify this book as a must read for any designer looking to learn how to develop amazing WordPress themes. The chapter on selling themes is worth the book price alone!

If you haven’t done so be sure to pick up a copy of Wicked WordPress Themes and starting creating beautiful themes today!

Related posts:

  1. SitePoint Podcast Interview for Professional WordPress
  2. My Interview on the WordPress Weekly Podcast
  3. My Interview with Matt Mullenweg of WordPress


WP Engineer: WordPress Child Themes – Remove Widget Areas

August 31st, 2010

In a WordPress Framework or Basic-Theme are one or several Widget Areas (Sidebars) defined. But how can you remove the widget areas if you don't need them and just confuse other backend users.

The line unregister_sidebar('my-sidebar'); in functions.php of Child-Themes doesn't do anything. Why? WordPress loads first the function.php of Child-Themes and then of the Framework. The Sidebar, which we like to remove is not there yet. It will be registered while loading the Basic-Themes/Frameworks.

But you can solve the problem with a Hook in the registry of your Framework/Basic-Theme.

//Code of the Framework to register 2 Sidebars
function xtreme_register_dynamic_sidebars() {
  register_sidebar( array(
    'name' => 'Sidebar One',
    'id' => 'sidebar-one',
    'description' => 'Sidebar One',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h5 class="widget-title">',
    'after_title' => '</h5>'
    ));
  register_sidebar( array(
    'name' => 'Sidebar Two',
    'id' => 'sidebar-two',
    'description' => 'Sidebar Two',
    'before_widget' => '  <li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h5 class="widget-title">',
    'after_title' => '</h5>'
    ));
  do_action('childtheme_sidebars');
}
add_action( 'widgets_init', 'xtreme_register_dynamic_sidebars' );

You see the Hook do_action('childtheme_sidebars');
let's use this Hook:

//functions.php im Child-Theme
function xtreme_unregister_sidebar() {
    unregister_sidebar('sidebar-two');
}
add_action( 'childtheme_sidebars', 'xtreme_unregister_sidebar' );

And the Sidebar is removed. Easy huh? :)


WP Engineer Favicon Thanks for subscribing our feed! Sponsor the WP Engineer Blog and get your brand in front of several hundred users per day!
© WP Engineer Team, All rights reserved (Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)


YoastWordPress - Archives - Yoast - Tweaking Websites: A reader story: One Project Closer

August 30th, 2010

One Project Closer WebsiteI got an email from Fred of One Project Closer this weekend, outlining how he had handled improving the load time of his blog, and I was so happy with it that I asked whether I could post it online, to which he graciously agreed. So you can now read it in full:

Joost,

I wanted to pass along a HUGE thank you for pointing me in the direction of VPS.Net.

About 2 weeks ago we decided it was time to move off of our Dreamhost shared hosting. I had remembered visiting your site several months back and seeing your note in the sidebar for a fast WordPress hosting solution. When we decided to move 2 weeks ago, I sought out your site again.

In a matter of two weeks we have:

1) switched to VPS.Net
2) optimized with Litespeed
3) installed W3 Total Cache
4) signed up for Akamai and started delivering via CDN.
5) started to optimize our code every way we can.

Our home page load times are down to less than 4 seconds from 10-11 seconds on Dreamhost. We saw an INSTANT increase in our affiliate conversions on some pages which will make the VPS.Net solution pay for itself in no time...

I'm now on a mission to optimize the heck out of the rest of our code -- moving more to the CDN and figuring out how to keep our rich presentation but streamlining the delivery.

Your site speed is an inspiration. I'm looking forward to figuring out ways to squeeze every last drop of waste out of our loads.

I hope to get to meet you sometime and share our story.

Thanks,
Fred

It's great to see how people improve their sites just by taking my freely given advice. He's also very right about affiliate money paying for the somewhat more expensive hosting fees. I'll tell you this time and again: you get what you pay for... If you've got a story like this to tell, please do share it with me! Either through my contact form or through the comments below!

A reader story: One Project Closer is a post from Joost de Valk's Yoast - Tweaking Websites.A good WordPress blog needs good hosting, you don't want your blog to be slow, or, even worse, down, do you? Check out my thoughts on WordPress hosting!


kovshenin.com: WordPress and Magic Quotes

August 29th, 2010

This is crazy, and based on a post called WordPress and PHP magic quotes: you want to run me crazy! by Stefano Lissa. I’m writing a plugin prototype for WordPress that uses the new Facebook Graph API to post stuff to my wall on Facebook (upcoming blog post). The original Facebook PHP SDK comes in very handy when working with the Facebook API, and I had quite some fun using it, but..

How to Kill the get_magic_quotes_gpc Function

How to Kill the get_magic_quotes_gpc Function

I’ve been trying to figure this out for hours! I had code working outside WordPress and once I pumped it into a plugin it suddenly stopped authorizing me. I had to dig through the facebook.php code to figure out what’s happening, and here it is. The getSession() method uses the get_magic_quotes_gpc function and strips the slashes from the $_COOKIE superglobal if it’s switched on. Of course, that’s the correct logic supporting both php 5 and php 6, but not WordPress.

I looked through the latest (3.0.1) WordPress core code and was quite surprised to see a function called wp_magic_quotes(). Oh my god, thought I! Commented as:

Add magic quotes and set up $_REQUEST ( $_GET + $_POST )

What the hell is that? Okay, let’s see:

$_GET = add_magic_quotes($_GET);
$_POST = add_magic_quotes($_POST);
$_COOKIE = add_magic_quotes($_COOKIE);
$_SERVER = add_magic_quotes($_SERVER);

How does that sound? So all my apps, plugins, external libraries working with server variables (like Facebook does with cookies) are not allowed to use the magic quotes function? This means that working with WordPress, we must initially assume that all these are quoted, no matter what the php settings are. I don’t even know what question to ask here, perhaps: Is this the way things are done? Why?

To be honest this is getting me a little frustrated. Not by the fact that they’re slashing the whole input (although I don’t see a reason to) but, heh, I’ve been coding based on WordPress for over two years now, and never came across anything like this. Did I miss something in the Getting Started guide? ;) Anyways, the easiest way to get this working is to replace your get_matic_quotes_gpc function with 1, which says it is always switched on.

Eh, Monday morning disappointment ;) Cheers, and thanks for retweeting the post!

Related posts:

  1. Counting Facebook Fans in PHP: The Graph API Way
  2. jQuery in WordPress: wp_enqueue_script
  3. WordPress: Recent Comments by Category


sillybean.net: Building a user directory, part 3: a page for each author

August 28th, 2010

how to allow HTML in user description field:

remove_filter( 'pre_user_description', 'wp_filter_kses' );


coffee2code.com: List More Custom Field Names v1.2

August 28th, 2010

I’d like to announce the official release of the updated List More Custom Field Names plugin (v1.2) for WordPress.

Allows for more existing custom field names to be listed in the dropdown selection field when writing a post.

Minor update. Highlights: added filter to customize number of custom field names to list; moved functionality out of anonymous function and into dedicated function; verified WP 3.0 compatibility.

For more details, instructions, and the download link, visit the plugin’s official homepage at :
http://coffee2code.com/wp-plugins/list-more-custom-field-names/.

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

Read more for a detailed ChangeLog of the release.

Detailed ChangeLog

These are the detailed changes, which may or may not make sense to you depending on your familiarity with the previous features and internals of the plugin.

  • Functionality now in new `c2c_list_more_custom_field_names()` rather than in an anonymous function
  • Allow overriding of the default number of custom field names, via the ‘c2c_list_more_custom_field_names’ filter (default is 200)
  • Note compatibility with WP 3.0+
  • Remove docs from top of plugin file (all that and more are in readme.txt)
  • Add Upgrade Notice section to readme.txt