[WPSNIPP]List All Available wordpress Roles

From: wpsnipp.com
By: Alicia Ramirez

Here is a snippet showing how to list all available roles. I recently used this snippet to add a role selector in the registration page. You could also use it for user searches, or post filters.

link: List All Available wordpress Roles


List All Available wordpress Roles is a post from: wpsnipp.com - WordPress Snippets, Code, Hacks, 615+ for your wordpress theme or blog.

[WPSNIPP]List all the ‘Authors’, with WP_User_Query

From: wpsnipp.com
By: Alicia Ramirez

Introduced in WordPress 3.1, the WP_User_Query class allows you to query the wp_users, and wp_usermeta tables. This allows you to create lists of authors that match a certain criteria (in this example, the role of author), and display information about each user.

The following code lists all the ‘Authors’, showing for each author its Gravatar, name with a link to an archive of their posts, and their bio.

link: List all the ‘Authors’, with WP_User_Query


List all the ‘Authors’, with WP_User_Query is a post from: wpsnipp.com - WordPress Snippets, Code, Hacks, 615+ for your wordpress theme or blog.

[WordPress Canada]Use Custom Domains With Xampp

A few weeks ago I published a two part tutorial on how to install both WordPress and XAMPP on your Windows PC. Part One of that article is here and Part Two is here.

I originally wrote that tutorial back in January of 2011 but it has been updated and republished with the latest information and more current screen shots.

Anyway, if you’re familiar with working with XAMPP you know that the URLs to your various web projects look something like this … http://localhost/yoursite

Did you know that you can set up custom domains on your PC so that those URLs will look something like this … http://yoursite.dev

The process is very easy and includes modifying just 2 files: the Windows Hosts file and an Apache configuration file.

Windows Hosts File

The Windows Hosts file is simply a plain text file that maps hostnames to IP addresses. In Windows 8.1 it is located at C:\Windows\System32\Drivers\etc By modifying this file we can tell our PC not to go out on to the internet to look for a particular domain but to look for it on the computer itself.

Here is what an untouched Windows Hosts file looks like …

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handle within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost

What we are going to do is add an entry to this file so that we can map our custom domain to the IP address 127.0.0.1 which is each computer’s loopback address. This is a special IP address reserved for use on each PC.

Important note: please make a backup of your Hosts file first.

Windows 8.1 and Windows 7 includes something called User Account Control (UAC) which prevents certain changes to your PC if the source of that change lacks administrator-level permission. In other words, in order to modify the Hosts file you’ll need to grant yourself administrator-level permission.

But we’re not going to mess around with the UAC settings – just leave them be. We’ll grant ourselves temporary permission.

To modify the Hosts file we’ll use Notepad. Right-click on Notepad and from the pop up menu select Run as administrator. It is now running with the necessary administrator-level permission.

Click on File > Open. Navigate to C:\Windows\System32\Drivers\etc and select the hosts file. Make sure the All Files option is active otherwise the hosts file may be hidden. See the screen shot below.

open the hosts file

At the bottom of that file add the following …

127.0.0.1       yoursite.dev

Save and close the file. We’re now done with it.

Your hosts file now should look something like this …

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handle within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost
        127.0.0.1       yoursite.dev

This of course assumes you have a folder named yoursite.dev within XAMPP’s htdocs folder.

Now when you point your browser to http://yoursite.dev your PC will look for that site on your computer and not the internet because we have mapped it to 127.0.0.1. Cool, yes?

Add as many entries as needed. Here is an example of a few of mine …

	127.0.0.1		wpcanada.dev
	127.0.0.1		wpcanada2.dev
	127.0.0.1		wpcanada3.dev
	127.0.0.1		wordpress.dev
	127.0.0.1		wordpress2.dev
	127.0.0.1		wordpress3.dev

Okay, now that we’ve instructed our PC to look for these sites internally we have to tell the Apache webserver included with XAMPP how to handle these requests. We do so by utilizing Apache’s virtual hosts feature.

Virtual Hosts

By using the Apache’s virtual hosts feature we can create as many local sites as we want and have them served with our custom domains.

Navigate to C:\xampp\apache\conf\extra and look for the file named httpd-vhosts.conf Open httpd-vhosts.conf in a plain text editor such as Notepad or Notepad++ etc and at the end of the file add the following …

<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs"
	ServerName localhost
</VirtualHost>

The above is important so that we don’t lose access to the htdocs folder. Now we’re ready to start adding our virtual hosts.

Again, assuming our dev site is located at http://yoursite.dev add the following to the httpd-vhosts.conf file. (it will go directly beneath the bit I posted above)

<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs\yoursite.dev"
	ServerName yoursite.dev
	<Directory "C:\xampp\htdocs\yoursite.dev">
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>

The end of that file should now look like this …

<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs"
	ServerName localhost
</VirtualHost>
<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs\yoursite.dev"
	ServerName yoursite.dev
	<Directory "C:\xampp\htdocs\yoursite.dev">
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>

Any additional sites you want to include would be added underneath. Let’s say you have 3 local sites you want to create virtual hosts for. This is what the end of the file would look like …

<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs"
	ServerName localhost
</VirtualHost>
<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs\yoursite.dev"
	ServerName yoursite.dev
	<Directory "C:\xampp\htdocs\yoursite.dev">
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>
<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs\yoursite2.dev"
	ServerName yoursite2.dev
	<Directory "C:\xampp\htdocs\yoursite2.dev">
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>
<VirtualHost *>
	DocumentRoot "C:\xampp\htdocs\yoursite3.dev"
	ServerName yoursite3.dev
	<Directory "C:\xampp\htdocs\yoursite3.dev">
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>

You get the idea. Just keep adding them by following the above format.

When you’re done save the httpd-vhosts.conf file and close it. If Apache is running you will need to stop and restart it for the changes to take effect.

Now fire up XAMPP and visit your local dev site with its shiny new custom URL.

The post Use Custom Domains With Xampp appeared first on WPCanada.

[WPSNIPP]Add a Class to ‘the_post_thumbnail’ a Featured Image

From: wpsnipp.com
By: Alicia Ramirez

When adding a featured image to a template, you may want to add a class to the image tag that is being generated. This extra class will allow you to use CSS to format it better.

link: Add a Class to ‘the_post_thumbnail’ a Featured Image


Add a Class to ‘the_post_thumbnail’ a Featured Image is a post from: wpsnipp.com - WordPress Snippets, Code, Hacks, 615+ for your wordpress theme or blog.

[WPSNIPP]Redirect a successful registration to specific page

From: wpsnipp.com
By: Kevin Chard

When you allow user registration on our wordpress site you may want to add something extra. Interested in thanking people after they register or just send them to a specific page for newly registered members.

link: Redirect a successful registration to specific page


Redirect a successful registration to specific page is a post from: wpsnipp.com - WordPress Snippets, Code, Hacks, 615+ for your wordpress theme or blog.

[WP First Aid]Adding Plugin Row Meta

Most plugins just have some standard details shown just below the plugin description when you look at your listing found under Plugins > Installed … wouldn’t it be nice to add your own specific links to the default ones WordPress already display?

You can, and it really is quite easy. A standard hook call and a relatively straight forward callback function and you are all set … and without further ado (and because it really is quite simple) here is a working callback function you can use:

/**
 * Plugin Row Meta
 * Add plugin row meta by merging array elements into the existing $links
 * array which will then add these elements to the end of the standard
 * plugin row meta details.
 *
 * Also to note, this will not appear while the plugin is not active.
 *
 * @package    WPFA_Sample_Widget
 * @since      0.5
 * @date       March 22, 2014
 *
 * @internal   for use with `plugin_row_meta` hook
 *
 * @param    $links
 * @param    $file
 *
 * @uses       plugin_basename
 *
 * @return array|null
 */
function wpfa_add_plugin_row_meta( $links, $file ) {

	/** Get the plugin file name for reference */
	$plugin_file = plugin_basename( __FILE__ );

	/** Check if $plugin_file matches the passed $file name */
	if ( $file == $plugin_file ) {

		/**
		 * Using `array_merge` add elements to the `$link` array to be
		 * returned. Identifying the link elements in the array will make
		 * them clearer if the need arises to review the array entries.
		 */

		/** @var array $links - sample element linking to GitHub to share code */
		$links = array_merge( $links, array( 'fork_link' => '<a href="https://github.com/Cais/wpfa-sample-plugin">' . __( 'Fork on Github', 'wpfa-sample' ) . '</a>' ) );
		/** @var array $links - sample element linking to my personal (Edward Caissie) Amazon wish list. Thanks in advance! */
		$links = array_merge( $links, array( 'wish_link' => '<a href="http://www.amazon.ca/registry/wishlist/2NNNE1PAQIRUL">' . __( 'Grant a wish?', 'bns-fc' ) . '</a>' ) );

		/**
		 * Separate entries were used for example purposes. A single call to
		 * the `array_merge` function would have worked as well where all of
		 * the new elements were added at the same time.
		 */

	} /** End if - plugin file name matched passed value */

	/** Return the `$link` array for use in the `plugin_row_meta hook` */
	return $links;

} /** End function - add plugin row meta */ 

Now you may have noticed some tell-tale signs this was taken from my favorite sample plugin “WPFA Sample Plugin” and you are more than welcome to simply download or fork a copy from GitHub here. At the time of this writing the plugin had just recently been updated to a better level of code practices as well as the addition of the method above (remember, all your code should be in the plugin’s class) and released as version 0.5.

For the purposes of this exercise I will write the hook call as though it was not within the class but making those changes are fairly straight forward as well and I would expect you can sort that our on your own (if not, feel free to contact me for more specifics).

add_filter( 'plugin_row_meta', 'wpfa_add_plugin_row_meta', 10, 2 );

Don’t forget we need the parameters value as two (2) are being passed into the callback function; and, the priority value is simply the default which should be used in this case.

[BuyNowShop]BNS Login Version 2.3.3

Just a quick update … this plugin just seems to do what it needs to do and not much more ever really get requested or considered to be added to it.

That being the case, this plugin will also most likely be moving to a twice yearly release; unless, of course, a great idea comes along …

Here’s the latest change log:

To see the changelog click here.To hide the changelog click here.

= Version 2.3.3 =
* Released March 2014
* Inline documentation, version compatibility, and copyright years updated
* Added `plugin_data` method
* Added `plugin_row_meta` links

© 2014, Edward Caissie. All rights reserved.

[BuyNowShop]BNS Featured Category Version 2.6

There were some interesting requests and a few discussions since the last release of this plugin and I have adopted some of those into this version.

Also to note, this plugin will also likely be going into a more “mature” development cycle which basically means I will be looking at twice yearly releases going forward.

Obviously if there are any significant issues or really great (easy to implement) ideas that come up sooner then I may simply jump on them and release sooner than planned.

In the meantime, here is the latest change log:

To see the changelog click here.To hide the changelog click here.
= Version 2.6 =

* Released March 2014
* Added `bnsfc-container` wrapper CSS element
* Added `bnsfc-widget-title` class
* Added `bnsfc_no_posts_message` hook to no posts message
* Added option to only show posts from child categories
* Added a “wish link” and “support_link” to the plugin meta row
* Code Reformatting to better match current WordPress Coding Standards
* Extracted code to create `plugin_data` method
* Moved BNSFC Plugin Meta function into main class of plugin
* Raised required version to WordPress 3.6
* Updates to the `readme.txt` documentation

Enjoy!

© 2014, Edward Caissie. All rights reserved.

[WordPress Canada]Malcolm, Marcus Updated v1.0.2

Both Malcolm and Marcus child themes have been updated to v1.0.2. This is a maintenance release that fixes an error in the style.css files of both themes.

The specifics:

.genesis-nav-menu > .rss a::before,
.genesis-nav-menu > .twitter::before {
	color: #999;
	content: "\f303";
	display: inline-block;
	font: normal 20px/1 'dashicons';
	margin-right: 5px;
	vertical-align: top;
	-webkit-font-smoothing: antialiased;
}

The declaration highlighted red is the icon font for the RSS character and should not be there. It has been removed. The RSS icon font has been declared on its own line now as such …

.genesis-nav-menu > .rss a::before {
	content: "\f303";
}

Also …

.genesis-nav-menu li.right {
		/*display: none;*/
	}

This is redundant and has been removed.

The changes apply to both themes and the updated versions are live on GitHub.

The post Malcolm, Marcus Updated v1.0.2 appeared first on WPCanada.

[WordPress Canada]Custom Author Box With Genericons

In case you haven’t noticed I absolutely love the Genesis framework. It’s an awesome piece of software packed with oodles of features not the least of which is an author box that includes a brief summary about the author and a Gravatar image. You can choose to display the Genesis author box on single post pages, the author archive page or both.

Having said that, I wanted something a little bit different. There is nothing wrong with the built-in Genesis author box – it works just fine. But I’m the type of person who loves to tinker and break stuff. As such I wanted to see if I could come up with something just a tad bit different so off to Google I went. It didn’t take long for me to find exactly what I was looking for.

The end result is a completely custom author box complete with Genericons which are an icon font. You can see a live example of it in action at the end of this very post. Or you can check out the screen capture below.

custom author box with Genericons

Now you may be asking why I elected to use Genericons especially when I showed you how to integrate Dashicons in the previous post. The only reason for that is because I wanted to include a link to my GitHub profile but couldn’t find the icon font for it at Dashicons. Genericons has a GitHub icon font so I went that route. But you could certainly use Dashicons if you wanted to as they do have the appropriate icon fonts for some of the popular social media sites like Twitter etc.

Okay, enough of the small talk. Let’s get started.

This entire tutorial is based on code written by Vivek of WPStuffs which in turn is based on code written by Chris Wiegman. Chris’s original code included text links to social media profiles. Vivek modified it by adding images to the links. I further modified it by dropping the images in favour of an icon font. The other modification I made was dropping get_the_author_id() for get_the_author_meta( 'ID' ) as the former is now deprecated.

Grab the Genericons

First step is to head on over to the Genericons website and download the ZIP file. At the time of this writing it is v3.0.3. Once you’ve downloaded the ZIP extract the contents. You’ll end up with a folder called genericons. Inside that folder is another folder called font. That’s the one we want.

Upload the font folder to your child theme’s folder. The structure should look something similar to this,

/themes
- YourChildTheme
— font
— images
—– various child theme files

Next, add the following to the top of the child theme’s style sheet …

/*
Font Import
------------------------------------------------------------------------ */

@font-face {
    font-family: 'Genericons';
    src: url('font/genericons-regular-webfont.eot');
    src: url('font/genericons-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('font/genericons-regular-webfont.woff') format('woff'),
         url('font/genericons-regular-webfont.ttf') format('truetype'),
         url('font/genericons-regular-webfont.svg#genericonsregular') format('svg');
    font-weight: normal;
    font-style: normal;
}

Alright, we’re done with this for now.

Add Profile Fields to Your Profile Page

If you navigate to Users > Your Profile you’ll see a few profile fields under Contact Info such as E-mail, Website etc. What we’re going to do is add a few more profile fields so that we can add some links to various social media sites.

For the purposes of this tutorial we’re only going to add links to Twitter, GitHub and Google+ although you can add as many as you want.

We do so via the child theme’s functions.php file. Using your favourite FTP client download the child theme’s functions.php file to your desktop and make a backup of it. Now open it up with a plain text editor and add the following …

//* Add fields to profile page
function change_contact_info($contactmethods) {
	$contactmethods['twitter'] = 'Twitter Username';
	$contactmethods['github'] = 'GitHub Username';
	$contactmethods['gplus'] = 'Google+ Username';
	return $contactmethods;
}
add_filter( 'user_contactmethods','change_contact_info', 10, 1 );

What we have just done is add 3 new profile fields to your Profile page. Check your Profile page to make sure they are there. If they are then continue on. If not go back and make sure you did everything correctly.

Replace Genesis Author Box

Our next step is to replace the Genesis author box with our custom author box. Add the following to your child theme’s functions.php file …

//* Replace Genesis author box with custom author box on single post page
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
add_action( 'genesis_after_entry', 'theme_author_box', 8 );

//* Replace Genesis author box with custom author box on author archive page
remove_action( 'genesis_before_loop', 'genesis_do_author_box_archive', 15 );
add_action( 'genesis_before_loop', 'theme_author_box_archive', 15 );

What we have done is remove the Genesis author box from both single post pages and the author archive page (yikes!) and replaced it with our custom author box which we’ll actually build next.

The following also goes into the child theme’s functions.php file …

Note: while copy/paste from the normal code blocks is fine do not copy/paste directly from the Gist above. Use the view raw link.

We’re finished here so you can put the functions.php file away.

The CSS

Let’s head back over to the child theme’s style sheet.

Before we add the style rules I want to show you another screen capture of the custom author box, this time outlining the various elements so that you better understand the CSS.

custom author box elements

The following goes into the child theme’s style.css file …

/* Custom Author Box
--------------------------------------------- */

.postauthor {
	background-color: #fff;
	border: 1px solid #e1e1e1;
	border-radius: 3px;
	margin-top: 15px;
	overflow: hidden;
	padding: 32px;
}

.postauthor img {
	display: block;
	float: left;
	height: 100px;
	margin-right: 15px;
	width: 100px;
}

.postauthor h4 {
	color: #444;
	font-size: 20px;
	margin-bottom: 0px;
	margin-left: 105px;
	padding: 0 0 8px;
}

.postauthor p {
	color: #666;
	font-size: 16px;
	line-height: 27px;
	margin-bottom: 0;
}

.postauthor-bottom {
	margin-bottom: 20px;
	overflow: hidden;
	padding: 10px 20px 0 20px;
}

.postauthor-bottom span {
	font-weight: bold;
	font-size: 14px;
	margin: 0 10px 0 0;
}

.postauthor-bottom .author-gh::before,
.postauthor-bottom .author-gplus::before,
.postauthor-bottom .author-twitter::before {
	color: #666; 
	display: inline-block;
	font: normal 16px/1 'Genericons';
	margin-right: 5px;
	vertical-align: middle;
	-webkit-font-smoothing: antialiased;
}

.postauthor-bottom .author-gh::before {
	content: '\f200';
}

.postauthor-bottom .author-gplus::before {
	content: '\f206';
}

.postauthor-bottom .author-twitter::before {
	content: '\f202';
}

.postauthor-bottom .author-gh,
.postauthor-bottom .author-gplus,
.postauthor-bottom .author-twitter {
	color: #666;
	font-size: 14px;
	margin: 0 10px 0 0;
	padding: 0 0 0 25px;
}

.postauthor-bottom .author-gh:hover,
.postauthor-bottom .author-gplus:hover,
.postauthor-bottom .author-twitter:hover {
	color: #a90000;
}

.postauthor-bottom .author-gh:hover::before,
.postauthor-bottom .author-gplus:hover::before,
.postauthor-bottom .author-twitter:hover::before {
	color: #a90000;
}

By referring to the screen capture you should be able to easier see what the CSS is doing.

Keep in mind the above CSS was written specifically for my theme. I included it so that you can use it as a starting point. You can customize it until the cows come home.

An important point: when adjusting the font size of the Genericons icon font it is best to use multiples of 16. At least that is what the official documentation says. For example, it is currently set by this rule …

font: normal 16px/1 'Genericons';

If you wanted to increase the size you would have to go up to 32 as such …

font: normal 32px/1 'Genericons';

According to the documentation the icon fonts may look fuzzy by using off-numbers although I haven’t personally seen it. Just something to keep in mind.

As I said earlier, you can add whatever and how many profile fields you want. Just study the code under the heading Add Profile Fields to Your Profile Page and the Gist under the heading Replace Genesis Author Box and follow the same format.

One more thing. When filling out your new profile fields you need only enter your username rather than the complete URL. For example my Twitter profile is https://twitter.com/wpcanada but I enter just the wpcanada part.

For Google+ enter +YourUserName if you are using their vanity URLs. For example, my Google+ profile is https://plus.google.com/+LenKutchma so I enter +LenKutchma. (minus the period) If you’re still using the old Google+ profile URLs it will look something like this https://plus.google.com/117573566699941542724 Just enter the number into the profile field.

Now go forth and build those custom author boxes!

Update: 29 March 2014
I’ve updated the CSS on this site for the custom author box. If you want to, check view source to compare the CSS in my style sheet to the CSS I posted above. The pertinent part starts at about Line 1850.

The post Custom Author Box With Genericons appeared first on WPCanada.

Planet WordPress Canada theme by WPDesigner, syndication by Pipes, FeedWordPress, and Feedburner, powered by ?