Loading...
November 24, 2012#
1353776123.jpg
1353776172.jpg
1353776192.jpg
1353776238.jpg

Well after MANY delays, the office only needs to be hooked into the electric panel before it’s ready for move in. I love the way the office looks and it’s so nice inside. It will be a great place to work. I am looking very forward to moving my stuff in and actually doing my first day of work here.

I am excited that the shed is from a local company. It’s great that they pride themselves on energy efficiency and sustainable materials (two things that were very important to me). The overall look is very cool and it seems like it will be very workable for a long time…

The journey getting to this point, however has been HORRIBLE. Delays in building, parts not complete, a four day build that took over three weeks, broken windows, ZERO customer service…oy! I am glad that part is over and SO hopeful that I don’t ever have to try and warranty anything with Studio Shed.

+ At any rate, here are some photos – more to come as we get everything moved in (and get the Christmas lights hung).

November 7, 2012#

Customizing the WordPress Backend

Not much explanation here, but I told one of my students that I would post up some code – so here it is…everything you need to get started customizing the admin area of WordPress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* HIDE NAVIGATION AREAS IN ADMIN */
function remove_menus () {
	global $menu;
 
	// check if admin and hide these for admins
	if( (current_user_can('install_themes')) ) { 
		// $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); 
		//$restricted = array(__('Dashboard'), __('Media'), __('Links'), __('Tools'), __('Users'), __('Settings'), __('Gallery'), __('Comments'), __('Plugins'));
	} else { // hide these for other roles
		//$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); 
		$restricted = array(__('Dashboard')/*, __('Media')*/, __('Links'), __('Tools'), __('Users'), __('Settings'), __('Gallery'), __('Comments'), __('Plugins')); 
	}
 
	end ($menu);
 
	while (prev($menu)){
		$value = explode(' ',$menu[key($menu)][0]);
		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
	}
}
add_action('admin_menu', 'remove_menus');
 
 
function customAdmin() {
    if( (current_user_can('install_themes')) ) { 
		$url = get_settings('siteurl');
	    $url = $url . '/wp-content/themes/soccer/css/wp-admin.css';
	    echo '<!-- custom admin css -->
	          <link rel="stylesheet" type="text/css" href="' . $url . '" />
	          <!-- /end custom adming css -->';
	} else { // hide these for other roles
		$url = get_settings('siteurl');
	    $url = $url . '/wp-content/themes/soccer/css/wp-admin.css';
	    echo '<!-- custom admin css -->
	          <link rel="stylesheet" type="text/css" href="' . $url . '" />
	          <!-- /end custom adming css -->'; 
	}
 
 
}
add_action('admin_head', 'customAdmin');
/* end: HIDE NAVIGATION AREAS IN ADMIN */
 
 
/* ADD CUSTOMIZED LOGIN STYLES */
function my_login_stylesheet() { 
	$url = get_settings('siteurl');
	$url = $url . '/wp-content/themes/soccer/css/wp-admin-login.css';
 
	 echo '<!-- custom admin css -->
	          <link rel="stylesheet" type="text/css" href="' . $url . '" />
	          <!-- /end custom adming css -->';
}
add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );
/* end: ADD CUSTOMIZED LOGIN STYLES */
 
 
 
/* CUSTOMIZE DASHBOARD */
/*Custom Dashboard Widget*/
add_action('wp_dashboard_setup', 'add_instructions');
 
function add_instructions() {
	global $wp_meta_boxes;
	/*First, remove all stock, out of the box widgets*/
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
 
	unset($wp_meta_boxes['dashboard']['normal']['core']['wt_dashboard_statistics']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_custom_feed']);
 
 
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
 
	/*Now proceed to add our new widget*/
	wp_add_dashboard_widget('dashboard_instructions', 'Welcome to Active Youth Network', 'dashboard_instructions_widget');
}
 
function dashboard_instructions_widget() {
/*Add Our Custom Widget Code*/
?>
	<!--Put any html you want in here, you should use wordpress functions to get the url to your theme in order to include any images.-->
    <div id="ayn_dashboard">
    	<h1><?php bloginfo('name'); ?></h1>
    	<img src="<?php echo get_bloginfo('template_directory'); ?>/img/AYN-logo.png" style="float: left; margin: 0 20px 45px 0;" />
    	<h4 style="padding-top: 45px;">Keeping kids active in youth sports</h4>
    	<p>The Active Youth Network, LLC (AYN) is a Colorado based, national online ad network of youth sports websites that AYN markets t major brand, family-friendly advertisers who want to reach this premium audience. AYN is a cause related company that gives 70% of sales revenues generated back to its member clubs, schools and associations. AYN's mission is to help offset the escalating costs of participation to reduce the burden to families and keep kids active in youth sports. For more information go to <a href="http://www.activeyouthnetwork.com" target="_blank">www.activeyouthnetwork.com</a></p>
    	<br clear="both" />
    </div>	
	<!--End Html-->
<?php
}
 
 
// CUSTOM ADMIN DASHBOARD HEADER LOGO  
 
function custom_admin_logo(){  
    echo '<style type="text/css">#icon-index { background: url('.get_bloginfo('template_directory').'/images/AYN-logo-sm.png) no-repeat top left !important; }</style>';  
}  
add_action('admin_head', 'custom_admin_logo');
/* END: CUSTOMIZE DASHBOARD */
November 6, 2012#

Creating a WordPress Plugin

What is a plugin?

WordPress plugins are PHP scripts that alter your website. The changes could be anything from the simplest tweak in the header to a more drastic makeover (such as changing how log-ins work, triggering emails to be sent, and much more).

Whereas themes modify the look of your website, plugins change how it functions.

how do you make one?
All that is required is create a folder and then create a single file with one line of content. Navigate to the wp-content/plugins folder, and create a new folder named dummy_plugin. Inside this new folder, create a file named filename.php. Open the file in a text editor…

Basic Structure

1
2
3
4
5
6
7
8
9
10
<?php      
 /* 
   Plugin Name: Dummy Plugin 
   Plugin URI: http://www.hankis.me
   Description: A plugin that will set up custom post types
   Author: Hank Pantier
   Version: 1.0 
   Author URI: http://www.hankis.me 
   */ 
?>

What other files does a good plugin contain?

A readme file
This file gives information such as

  • Plugin Name
  • Description
  • Installation
  • Frequently Asked Questions
  • Screenshots
  • Changelog
  • Upgrade Notice
  • Arbitrary section
  • A brief Markdown Example

Here is an example.

License
Most Plugins use the GPL2 license used by WordPress or a license compatible with the GPL2. To indicate a GPL2 license, include the following lines in your Plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php 
/*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : PLUGIN AUTHOR EMAIL)     
This program is free software; you can redistribute it and/or modify     
it under the terms of the GNU General Public License, version 2, as      
published by the Free Software Foundation.     
 
This program is distributed in the hope that it will be useful,     
but WITHOUT ANY WARRANTY; without even the implied warranty of     
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     
GNU General Public License for more details.     
You should have received a copy of the GNU General Public License     
along with this program; if not, write to the Free Software     
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */ 
?>

After I have created a plugin, how do i make it “Work”

Actions
Actions are triggered by specific events that take place in WordPress, such as publishing a post, changing themes, or displaying a page of the admin panel.

Understanding add_action()
Actions target pre-defined areas in your templates and admin panel.

WordPress offers a comprehensive actions list in their API documentation. Below is a small list of example actions for you to get familiar with some of the pre-defined target areas.

  • publish_post – called when a post is published or when status is changed into “published”
  • save_post – called when a post/page is created from start or updated
  • wp_head – called when the template is loaded and runs the wp_head() function
  • loop_end – called immediately after the final post has been processed through the WordPress loop
  • trackback_post – called whenever a new trackback is added into a post
1
add_action('save_post', 'iW_other_function');

Filters
functions that WordPress passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or sending it to the browser screen). Filters sit between the database and the browser (when WordPress is generating pages), and between the browser and the database (when WordPress is adding new posts and comments to the database)

Understanding add_filter()
Filters change text or data from WordPress – for example with a filter, we could change $the_content which is a variable set by WordPress containing the entire post content of a WordPress article.

1
add_filter('wp_title', 'iW_func');

A “Real World” Example

Hello Dolly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
 * @package Hello_Dolly
 * @version 1.6
 */
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/extend/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.6
Author URI: http://ma.tt/
*/
 
function hello_dolly_get_lyric() {
	/** These are the lyrics to Hello Dolly */
	$lyrics = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
We feel the room swayin'
While the band's playin'
One of your old favourite songs from way back when
So, take her wrap, fellas
Find her an empty lap, fellas
Dolly'll never go away again
Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
We feel the room swayin'
While the band's playin'
One of your old favourite songs from way back when
Golly, gee, fellas
Find her a vacant knee, fellas
Dolly'll never go away
Dolly'll never go away
Dolly'll never go away again";
 
	// Here we split it into lines
	$lyrics = explode( "\n", $lyrics );
 
	// And then randomly choose a line
	return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
 
// This just echoes the chosen line, we'll position it later
function hello_dolly() {
	$chosen = hello_dolly_get_lyric();
	echo "<p id='dolly'>$chosen</p>";
}
 
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );
 
// We need some CSS to position the paragraph
function dolly_css() {
	// This makes sure that the positioning is also good for right-to-left languages
	$x = is_rtl() ? 'left' : 'right';
 
	echo "
	<style type='text/css'>
	#dolly {
		float: $x;
		padding-$x: 15px;
		padding-top: 5px;		
		margin: 0;
		font-size: 11px;
	}
	</style>
	";
}
 
add_action( 'admin_head', 'dolly_css' );
 
?>

Making Your Own

Admin Screens

http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/

Some of my favorites

Advanced Custom Fields
Easy Content Types
Google Analytics for WordPress
Gravity Forms
NextGEN Gallery
Per Page Sidebars
Regenerate Thumbnails
WP Super Cache
WordPress SEO

Additional Resources