How I Became a WordPress Hacker
-
Upload
mike-zielonka -
Category
Documents
-
view
329 -
download
3
description
Transcript of How I Became a WordPress Hacker
![Page 1: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/1.jpg)
How I Became a WordPress Hacker
Mike Zielonka @mikezielonka
![Page 2: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/2.jpg)
Co-Founder and Director of Web StrategyAt Tuna Traffic
Loves Pizza, Dogs, More Pizza and Coffee
I Am Mike Zielonka
![Page 3: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/3.jpg)
What We’ll Cover
● Why the struggle is part of the journey● The basics of using Actions & Filters● How to make a plugin for your Hooks
![Page 4: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/4.jpg)
Successful WordPress Hackers Can...
Customize WordPress Themes and Plugins without writing a lot of code.
![Page 5: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/5.jpg)
The Struggle Is…
● PHP is scary● Making your own plugin is scary● PHP is very scary● You just never have the options you need
![Page 6: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/6.jpg)
My Journey
2011 Mike “The SEO”
2012 Mike “Frameworks”
2013 Mike “The Hacker”
2014 Mike “Expert Generalist”
![Page 7: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/7.jpg)
Whats a Hook According to the Codex
“Hooks are specified, by the developer, in Actions and Filters. “
“In technical and strict terms: a Hook is an event, i.e. event as understood by Observer pattern, invoked by the do_action() or apply_filters() call that afterwards triggers all the action or filter functions, previously hooked to that event using add_action() or add_filter(), respectively.”
![Page 8: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/8.jpg)
Where do Hooks Live
Generally speaking, you have 3 different places where “hooks” live.● Core● Themes● Plugins
![Page 9: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/9.jpg)
Allows you to “do something” to insert something at a “checkpoint”.
Action Defined
![Page 10: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/10.jpg)
Action Exampleadd_action( ‘wp_head’, ‘wc_your_function_name’ );
function wc_your_function_name() {
?>
<!--hi people-->
<?php
}
![Page 11: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/11.jpg)
add_actionadd_action( ‘wp_head’, ‘wc_your_function_name’ );
Where You Hook In What To Add
![Page 12: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/12.jpg)
Adding What You Want (Writing a Function)
function wc_your_function_name() {
?>
<!--hi people-->
<?php
}
Your function name
PHP On and Off
Your HTML
![Page 13: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/13.jpg)
Real Life Example//Adding A Credit Link to TwentyFourteen
add_action( 'twentyfourteen_credits' , 'mz_site_credits' );
function mz_site_credits() {
echo "<a href='http://iammike.co' title='mike zielonka'>Designed by Mike Zielonka</a>";
}
![Page 14: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/14.jpg)
Allows you to “filter the result” and return something different at a “fancy checkpoint”.
Filter
![Page 15: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/15.jpg)
Filter Exampleadd_filter( ‘wp_title’, ‘wc_your_function_filter_name’, 10, 2 );
function wc_your_function_filter_name($title, $sep) {
$name = ‘My Site is Called ’;
$title .= $sep . ' ' . $name;
return $title;
}
![Page 16: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/16.jpg)
add_filteradd_filter( ‘wp_title’,‘wc_your_function_filter_name’, 10, 2 );
Where You Hook In What To Add Priority
Accepted Arguments
![Page 17: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/17.jpg)
Returning What You Want (Writing a Function)
function wc_your_function_filter_name($title, $sep) {
$name = ‘My Site is Called ’;
$title .= $sep . ' ' . $name;
return $title;
}Your function name
Return your changes
Arguments
![Page 18: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/18.jpg)
Real Life Example//Adding a Phrase the Site Title
add_filter( 'wp_title', 'wc_your_function_filter_name', 10, 2 );
function wc_your_function_filter_name($title, $sep) {
$name = 'My Site is Called ';
$title .= $sep . ' ' . $name;
return $title;
}
![Page 19: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/19.jpg)
Where To Put Your Hooks
● Functions.php of your theme○ Preferably in a child theme
● Plugin
![Page 20: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/20.jpg)
Adding Hooks To A PluginAdd Opening PHP Tag and Add A Plugin Header<?php
/*
Plugin Name: Mike's Sample Plugin
Plugin URI:
Description: Adds some sample hooks.
Author: Mike Zielonka
Version: 1.0
Author URI: http://iammike.co
Text Domain: mz-sample-plugin
*/
![Page 21: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/21.jpg)
Putting It All Together
![Page 22: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/22.jpg)
Basic Rookie Tips
● Namespace your functions to avoid conflicts. ie: mz_function
● Do not start functions with numbers.● Always take back ups.● Learn more about the PHP function
function_exists() to prevent headaches when switching themes and plugins
![Page 23: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/23.jpg)
Helpful ToolsFor Hooking Efficiently
![Page 24: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/24.jpg)
![Page 25: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/25.jpg)
Debug Bar w/ Debug Bar Actions and Filters Addon
![Page 26: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/26.jpg)
Searching for Actions in Sublime Text 3
![Page 27: How I Became a WordPress Hacker](https://reader031.fdocuments.in/reader031/viewer/2022020110/5455fee5b1af9fc0638b4c42/html5/thumbnails/27.jpg)
Follow Me On Twitter@mikezielonka
Thank You