-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·634 lines (513 loc) · 21.8 KB
/
index.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Developing for WordPress - Dos and Dont's - Silvan Hagen</title>
<meta name="description" content="A presentation of learnings and tips to develop themes and plugins for WordPress">
<meta name="author" content="Silvan Hagen">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/beige.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Developing for WordPress</h1>
<h3>Dos and Dont's</h3>
<p>
Hashtag for today: <strong>#WPKonferenz</strong>
</p>
<small>Created by <a href="http://required.ch">Silvan Hagen</a> / <a href="http://twitter.com/neverything">@neverything</a></small>
</p>
</section>
<section>
<section>
<h1>What's on the menu today?</h1>
</section>
<section>
<h2>Developing Themes</h2>
<ul>
<li>Where to start?</li>
<li>How to use assets</li>
<li>Child Theme or not?</li>
<li><code>Code:</code> Theme or Plugin?</li>
<li>Ressources</li>
</ul>
</section>
<section>
<h2>Developing Plugins</h2>
<ul>
<li>Where to start?</li>
<li>Meet the APIs</li>
<li>The Good and the Bad</li>
<li>Ressources</li>
</ul>
</section>
</section>
<section>
<h1>Themes</h1>
</section>
<section>
<section>
<h1>Where to start?</h1>
</section>
<section>
<h2>From scratch?</h2>
<p class="fragment">
<strong>Nah</strong>, there are too many solid boilerplates!
</p>
</section>
<section>
<h2>With a theme framework or blank theme?</h2>
<p class="fragment">
There are some fantastic WordPress theme frameworks and blank themes!
</p>
</section>
<section>
<h2>Free <small>Yeah!</small></h2>
<ul>
<li>
<a href="http://underscores.me/">Underscores (_S)</a>
</li>
<li>
<a href="http://themeshaper.com/thematic/">Thematic</a>
</li>
<li>
<a href="http://themehybrid.com/themes/hybrid">Hybrid</a> (paid option available)
</li>
<li>
<a href="http://upthemes.com/upthemes-framework/">UpThemes Framework</a>
</li>
<li>
<a href="http://www.rootstheme.com/">Roots</a>
</li>
<li>
<a href="http://themble.com/bones/">Bones</a>
</li>
<li>
<a href="http://themes.required.ch">required+ Foundation</a> (shameless advertisting)
</li>
</ul>
</section>
<section>
<h2>Paid</h2>
<ul>
<li>
<a href="http://my.studiopress.com/themes/genesis/">Genesis</a>
</li>
<li>
<a href="http://www.pagelines.com/pricing/">PageLines</a>
</li>
<li>
<a href="http://headwaythemes.com/">Headway</a>
</li>
</ul>
</section>
<section>
<h2>So should I use a theme framework?</h2>
<p class="fragment">
<strong>Yes</strong>, but it depends. Look at them individually and decide for yourself and the project ahead.
</p>
<p class="fragment">
I usually strive for base themes or frameworks that are very close to WordPress using the <strong>original template structure</strong>, not bloated with options, and so on.
</p>
</section>
</section>
<section>
<section>
<h1>How to use assets?</h1>
<p class="fragment">
Stylesheets, JavaScripts and other external ressources in your theme.
</p>
</section>
<section>
<h2>Meet action and filter hooks</h2>
<p>
<blockquote>
Hooks are the backbone of WordPress. They enable developers to hook into the WordPress workflow to change how it works without directly modifying the core code.
</blockquote>
<small><a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-WordPress-Plugin-Development.productCd-0470916222.html">Professional WordPress Development</a> - Chapter 3</small>
</p>
</section>
<section>
<h2>Example of an action and a filter hook</h2>
<p>
Example of an <a href="http://codex.wordpress.org/Plugin_API#Actions">action hook</a>:
</p>
<pre><code contenteditable class="php">function req_email_friends() {
wp_mail(...);
}
add_action ( 'wp_title', 'req_email_friends' );</code></pre>
<p>
Example of a <a href="http://codex.wordpress.org/Plugin_API#Filters">filter hook</a>:
</p>
<pre><code contenteditable class="php">function req_add_heart_to_title( $title, $sep ) {
$heart = '♥';
// Append the heart to the title
$title .= $sep . ' ' . $heart;
return $title;
}
add_filter( 'wp_title', 'req_add_heart_to_title', 10, 2 );</code></pre>
</section>
<section data-state="alert">
<h2>You could do - but shouldn't</h2>
<br>
<pre><code contenteditable class="php">function req_my_scripts() {
echo '<script src="<?php echo get_stylesheet_directory_uri(); ?>/javascripts/application.js"></script>';
}
add_action ( 'wp_head', 'req_my_scripts' );</code></pre>
<p class="fragment">It's a little better than putting everything in the <code>header.php</code>, but how about letting WordPress know about the assets in your theme?</p>
</section>
<section data-state="soothe">
<h2>You should do</h2>
<p>Example from <a href="https://github.com/Automattic/_s/blob/master/functions.php#L135-L151">Underscores</a>:</p>
<pre><code contenteditable class="php">/**
* Enqueue scripts and styles
*/
function _s_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_script(
'small-menu', // ID
get_template_directory_uri() . '/js/small-menu.js',
array( 'jquery' ), // dependencies
'20120206', // version
true // in footer
);
}
add_action( 'wp_enqueue_scripts', '_s_scripts' );</code></pre>
<p class="fragment">
This will still print your themes stylesheet in the header through <code>wp_head()</code> and add the <code>small-menu.js</code> to the footer using <code>wp_footer()</code>.
</p>
</section>
</section>
<section>
<section>
<h1>Child Theme or not?</h1>
<p class="fragment">
Inherit the good (and the bad) stuff from your parents can be handy!
</p>
</section>
<section>
<h2>What the heck is a child theme?</h2>
<p>
<blockquote>
A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme, and allows you to modify, or add to, the functionality of that parent theme.
</blockquote>
<small><a href="http://codex.wordpress.org/Child_Themes">The Codex on Child Themes</a></small>
</section>
<section>
<h2>Child Themes in a nutshell</h2>
<pre><code>/wp-content
/themes
/your-parent-theme // your example parent theme
/your-child-theme // name doesn't matter here
style.css // required to make it work</code></pre>
<p>In your child themes <code>style.css</code></p>
<pre><code class="css">/*
Theme Name: Your Child Theme
Description: Child theme for the Your Parent Theme theme
Author: Your name here
Template: your-parent-theme
*/
@import url("../your-parent-theme/style.css");</code></pre>
<p class="fragment">
This is all it takes to create a child theme. So far it does nothing different than the parent.
</p>
</section>
</section>
<section>
<section>
<h1>Theme or Plugin?</h1>
<p class="fragment">
Where should you put your custom code? An ongoing discussion in the community.
</section>
<section data-state="alert">
<h2>Don't bloat your theme with shortcodes!</h2>
<p class="fragment">... and don't believe in theme authors selling you <code>[shortcodes]</code> as theme features.</p>
</section>
<section data-state="soothe">
<h2>Develop universal Shortcode Plugins!</h2>
<p class="fragment">A good example is the <a href="http://justintadlock.com/archives/2012/10/03/grid-columns-wordpress-plugin">Grid Columns Plugin by Justin Tadlock</a></p>
</section>
<section>
<h2>What about Custom Post Types?</h2>
<p class="fragment">Custom Post Types are WordPress one-fits-all (most) model to store content in almost any form you like.</p>
<p class="fragment">So <strong>it's up to you</strong> wether you add the custom post type to your theme or create a plugin.</p>
</section>
</section>
<section>
<section>
<h1>Ressources</h1>
<p class="fragment">
With a community this big, consider yourself lucky!
</section>
<section>
<h2>Create a theme</h2>
<ul>
<li><a href="http://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tutorial-2nd-edition/">The ThemeShaper WordPress Theme Tutorial: 2nd Edition</a></li>
<li><a href="http://codex.wordpress.org/Child_Themes">Create a child theme with TwentyTwelve</a></li>
</ul>
</section>
<section>
<h2>Debug your theme</h2>
<ul>
<li><a href="http://nacin.com/2010/04/23/5-ways-to-debug-wordpress/">5 Ways to Debug WordPress</a></li>
<li><a href="http://wordpress.org/extend/plugins/debug-bar/">Debug Bar Plugin</a></li>
<li><a href="http://wordpress.org/extend/plugins/developer/">Developer Plugin</a></li>
<li><a href="http://wordpress.org/extend/plugins/log-deprecated-notices/">Log Deprecated Notices</a></li>
</ul>
</section>
<section>
<h2>Test your theme</h2>
<ul>
<li><a href="http://codex.wordpress.org/Theme_Unit_Test">Official Theme Unit Test</a></li>
<li><a href="http://wordpress.org/extend/plugins/theme-check/">Theme-Check Plugin</a></li>
</ul>
</section>
</section>
<section>
<h1>Plugins</h1>
</section>
<section>
<section>
<h1>Where to start?</h1>
</section>
<section>
<h2>From scratch?</h2>
<p class="fragment"><strong>Nope</strong>, there is the fantastic <a href="https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate">WordPress Plugin Boilerplate</a> and even a <a href="http://themergency.com/generators/wordpress-plugin-boilerplate/">code generator</a> for the lazy ones.</p>
</section>
<section>
<h2>Using the WordPress Plugin Boilerplate</h2>
<pre><code contenteditable class="php">class DemoPlugin {
public function __construct() {
load_plugin_textdomain( 'demo-plugin', false,
dirname( plugin_basename( __FILE__ ) ) . '/lang' );
add_action( 'wp_enqueue_scripts',
array( $this, 'register_plugin_styles' ) );
add_action( 'wp_enqueue_scripts',
array( $this, 'register_plugin_scripts' ) );
add_filter( 'the_content',
array( $this, 'append_post_notification' ) );
}
}</code></pre>
<p>This example is from <a href="http://wp.tutsplus.com/tutorials/plugins/two-ways-to-develop-wordpress-plugins-object-oriented-progamming/">WP Tuts+</a>.</p>
</section>
<section>
<h2>Create your own?!</h2>
<p class="fragment">After you wrote a few plugins yourself, you might feel the need to create your own boilerplate.</p>
</section>
</section>
<section>
<section>
<h1>Meet the APIs</h1>
<p class="fragment">
WordPress currently <a href="http://codex.wordpress.org/WordPress_API's">lists 16 different APIs</a> available for you to work with.
</p>
</section>
<section>
<h2>Plugin API</h2>
<p>
WordPress <a href="http://codex.wordpress.org/Plugin_API">Plugin API</a> is the <strong>action and filter hooks system</strong>, that allows you to hook in where your plugin has to.
</p>
<pre class="fragment"><code contenteditable class="php">// Create a new filter hook
$my_args = apply_filters( 'req_args_filter', $args );
// Create your own action hook
do_action( 'req_header_action' );</code></pre>
</section>
<section>
<h2>Plugin API</h2>
<p>Now people can filter your <code>$my_args</code> and attach an action to <code>req_header_action</code>:</p>
<pre><code contenteditable class="php">// Add a filter to $my_args
function my_custom_args_filter( $args ) {
// do something with the data
return $args;
}
add_filter( 'req_args_filter', 'my_custom_args_filter' );
// Add an action to req_header_action
function my_custom_header_action() {
// Do whatever you like ;-)
echo 'Hello my friend';
}
add_action( 'req_header_action', 'my_custom_header_action' );</code></pre>
</section>
<section>
<h2>Plugin API</h2>
<p>Your plugin might leave data as options or you need custom tables, please make use of the <strong>activation/deactivation and uninstall hooks</strong> to add or remove data.</p>
<ul>
<li><code>register_activation_hook()</code> run code on plugin activation</li>
<li><code>register_deactivation_hook()</code> run code on plugin deactivation</li>
<li><code>register_uninstall_hook()</code> or <code>uninstall.php</code> here you actually delete whatever your plugin created</li>
</section>
<section>
<h2>Options API</h2>
<p>Need to save global plugin options? Use the <a href="http://codex.wordpress.org/Options_API">Options API</a>.</p>
<pre class="fragment"><code contenteditable class="php">// Store some data
$my_option = array( 'state' => 'yellow', 'version' => '0.1.0' );
update_option( 'my_plugin_option', $my_option );
// Get the data back
$options = get_option( 'my_plugin_option' );
$state = $options['state'];
$version = $options['version'];</code></pre>
</section>
<section>
<h2>Settings API</h2>
<p>
<blockquote>
Dealing with user inputs introduces new constraints in the option process: You need to design a user interface, monitor form submissions, handle security checks, and validate user inputs. To easily manage these common tasks, WordPress wraps the option functions into a comprehensive Settings API.
</blockquote>
<small><a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-WordPress-Plugin-Development.productCd-0470916222.html">Professional WordPress Development</a> - Chapter 7</small>
</p>
</section>
<section>
<h2>Settings API</h2>
<p>The <a href="http://codex.wordpress.org/Settings_API">Settings API</a> offers you to register groups of settings and settings fields. It also helps creating the form and handles the errors for you.</p>
</section>
<section>
<h2>HTTP API</h2>
<p>The <a href="http://codex.wordpress.org/HTTP_API">HTTP API</a> is an easy and standardized API to fetch remote data.</p>
<pre class="fragment"><code contenteditable class="php">$request = wp_remote_get( 'http://example.com' );
$body = wp_remote_retrieve_body( $request );
// $body contains the actual page content returned by the server</code></pre>
</section>
<section>
<h2>Transients API</h2>
<p>With the <a href="http://codex.wordpress.org/Transients_API">Transients API</a> you can store data that expires.</p>
<pre class="fragment"><code contenteditable class="php">// Get any existing copy of our transient data
if ( false === ( $custom_query = get_transient( 'special_query' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$custom_query = new WP_Query( 'cat=5&order=random&tag=tech' );
set_transient( 'special_query', $custom_query, 12 * HOUR_IN_SECONDS );
}
// Use the data like you would have normally...</code></pre>
</section>
</section>
<section>
<section>
<h1>The Good and the Bad</h1>
<p class="fragment">
Some simple rules for plugin development and how to find good plugins.
</p>
</section>
<section data-state="alert">
<h2>The Bad</h2>
<p>If you do any of these things you gonna have a bad time.</p>
<ul>
<li>Includes a custom version of jQuery</li>
<li>Loads JS and CSS on all requests and admin pages</li>
<li>Not ready for translation or doing it wrong</li>
<li>Direct DB access without <code>$wpdb->prefix</code></li>
<li>Want some more? Visit <a href="http://crappycode.wordpress.com/">Crappy Code</a></li>
</ul>
</section>
<section data-state="soothe">
<h2>The Good</h2>
<p>It's not that hard to be the good guy, test your stuff and respect others.</p>
<ul>
<li>Respect the global namespace</li>
<li>Prefer API methods over direct access</li>
<li>Add custom action and filter hooks where appropriate</li>
<li>Stay close to WordPress styling in the backend</li>
<li>Only use custom DB tables when needed</li>
</ul>
</section>
</section>
<section>
<section>
<h1>Ressources</h1>
<p class="fragment">
Ready to write better plugins? Here are some inputs!
</p>
</section>
<section>
<h2>Create a plugin</h2>
<ul>
<li><a href="https://codex.wordpress.org/Writing_a_Plugin">The Codex on Writing a Plugin</a></li>
<li><a href="http://wp.tutsplus.com/tutorials/plugins/two-ways-to-develop-wordpress-plugins-object-oriented-progamming/">Develop Plugins: Object-Oriented Programming</a></li>
<li><a href="http://wp.tutsplus.com/tutorials/plugins/two-ways-to-develop-wordpress-plugins-functional-programming/">Develop Plugins: Functional Programming</a></li>
</ul>
</section>
<section>
<h2>Internationalization and Translations</h2>
<ul>
<li><a href="http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/">Internationalization: You’re probably doing it wrong</a></li>
<li><a href="http://ottopress.com/2012/more-internationalization-fun/">More Internationalization Fun</a></li>
</ul>
</section>
<section>
<h2>WordPress UI</h2>
<ul>
<li><a href="http://wp.tutsplus.com/tutorials/integrating-with-wordpress-ui-the-basics/">Integrating With WordPress’ UI: The Basics</a></li>
<li><a href="https://github.com/bueltge/WordPress-Admin-Style">WordPress Admin Style Plugin</a></li>
</ul>
</section>
<section>
<h2>Books</h2>
<ul>
<li><a href="http://digwp.com/book/">Digging into WordPress</a></li>
<li><a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-WordPress-Plugin-Development.productCd-0470916222.html">Professional WordPress Plugin Development</a></li>
</ul>
</section>
</section>
<section>
<h1>Five more things!</h1>
<ol>
<li class="fragment">The core is your friend, read the WordPress code.</li>
<li class="fragment">Inspire yourself by digging through great plugins.</li>
<li class="fragment">Get involved in the community, we need everyone.</li>
<li class="fragment">Localize your stuff, so people can <strong>easily translate it</strong>.</li>
<li class="fragment"><strong>Go and build something awesome!</strong></li>
</ol>
</section>
<section>
<h1>Questions?</h1>
<p class="fragment">
Further questions? Contact me: <a href="mailto:[email protected]?subject=Saw your presentation dude!">[email protected]</a> / <a href="http://twitter.com/neverything">@neverything</a>
</p>
</section>
<section>
<h1>Thank you!</h1>
<p class="fragment">
This presentation is available on <a href="https://github.com/neverything/developing-for-wordpress">GitHub</a>, <a href="#"><s>SlideShare</s></a> and <a href="http://required.ch/presentations/silvan/developing-for-wordpress/">our website</a>.
</p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>