ebook img

WordPress App PDF

459 Pages·2014·14.12 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview WordPress App

Building Web Apps with WordPress Brian Messenlehner and Jason Coleman Building Web Apps with WordPress by Brian Messenlehner and Jason Coleman Copyright © 2014 Brian Messenlehner and Jason Coleman. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editors: Meghan Blanchette and Allyson MacDonald Indexer: Ellen Troutman Production Editor: Nicole Shelby Cover Designer: Randy Comer Copyeditor: Charles Roumeliotis Interior Designer: David Futato Proofreader: Amanda Kersey Illustrator: Rebecca Demarest April 2014: First Edition Revision History for the First Edition: 2014-04-07: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449364076 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Building Web Apps with WordPress, the picture of a common iguana, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-36407-6 [LSI] Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi 1. Building Web Apps with WordPress. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What Is a Website? 1 What Is an App? 1 What Is a Web App? 1 Features of a Web App 2 Why Use WordPress? 3 You Are Already Using WordPress 4 Content Management Is Easy with WordPress 4 User Management Is Easy and Secure with WordPress 4 Plugins 5 Flexibility Is Important 5 Frequent Security Updates 6 Cost 6 .NET App 6 WordPress App 7 Responses to Some Common Criticisms of WordPress 7 When Not to Use WordPress 10 You Plan to License or Sell Your Site’s Technology 10 There Is Another Platform That Will Get You “There” Faster 10 Flexibility Is NOT Important to You 11 Your App Needs to Be Highly Real Time 11 WordPress as an Application Framework 11 WordPress Versus MVC Frameworks 12 Anatomy of a WordPress App 15 What Is SchoolPress? 15 SchoolPress Runs on a WordPress Multisite Network 15 iii The SchoolPress Business Model 15 Membership Levels and User Roles 16 Classes Are BuddyPress Groups 16 Assignments Are a Custom Post Type 16 Submissions Are a (Sub)CPT for Assignments 17 Semesters Are a Taxonomy on the Class CPT 17 Departments Are a Taxonomy on the Class CPT 17 SchoolPress Has One Main Custom Plugin 17 SchoolPress Uses a Few Other Custom Plugins 18 SchoolPress Uses the StartBox Theme Framework 18 2. WordPress Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 WordPress Directory Structure 21 Root Directory 22 /wp-admin 22 /wp-includes 22 /wp-content 22 WordPress Database Structure 23 wp_options 23 Functions Found in /wp-includes/option.php 24 wp_users 26 Functions Found in /wp-includes/… 27 wp_usermeta 30 wp_posts 34 Functions found in /wp-includes/post.php 34 wp_postmeta 38 Functions Found in /wp-includes/post.php 38 wp_comments 42 Functions Found in /wp-includes/comment.php 42 wp_commentsmeta 46 Functions Found in /wp-includes/comment.php 47 wp_links 49 wp_terms 50 Functions Found in /wp-includes/taxonomy.php 50 wp_term_taxonomy 53 /wp-includes/taxonomy.php 53 wp_term_relationships 54 Extending WordPress 55 3. Leveraging WordPress Plugins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 The GPLv2 License 58 Installing WordPress Plugins 58 iv | Table of Contents Building Your Own Plugin 59 File Structure for an App Plugin 60 /adminpages/ 61 /classes/ 61 /css/ 62 /js/ 63 /images/ 63 /includes/ 63 /includes/lib/ 64 /pages/ 64 /services/ 65 /scheduled/ 65 /schoolpress.php 65 Add-Ons to Existing Plugins 66 Use Cases and Examples 66 The WordPress Loop 66 WordPress Global Variables 67 Action Hooks 77 Filters 77 Free Plugins 79 All in One SEO Pack 79 BadgeOS 79 Custom Post Type UI 80 Posts 2 Posts 80 Members 81 W3 Total Cache 81 Premium Plugins 81 Gravity Forms 81 Backup Buddy 81 WP All Import 82 Community Plugins 82 BuddyPress 82 4. Themes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Themes Versus Plugins 95 When Developing Apps 95 When Developing Plugins 96 When Developing Themes 97 The Template Hierarchy 97 Page Templates 99 Sample Page Template 99 Using Hooks to Copy Templates 102 Table of Contents | v When to Use a Theme Template 103 Theme-Related WP Functions 103 Using locate_template in Your Plugins 104 Style.css 106 Versioning Your Theme’s CSS Files 106 Functions.php 108 Themes and Custom Post Types 108 Popular Theme Frameworks 108 WP Theme Frameworks 109 Non-WP Theme Frameworks 110 Creating a Child Theme for StartBox 111 Including Bootstrap in Your App’s Theme 111 Menus 113 Nav Menus 113 Dynamic Menus 114 Responsive Design 115 Device and Display Detection in CSS 115 Device and Feature Detection in JavaScript 116 Device Detection in PHP 118 Final Note on Browser Detection 122 Versioning CSS and JS Files 122 5. Custom Post Types, Post Metadata, and Taxonomies. . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Default Post Types and Custom Post Types 125 Page 125 Post 125 Attachment 126 Revisions 126 Nav Menu Item 126 Defining and Registering Custom Post Types 126 register_post_type( $post_type, $args ); 127 What Is a Taxonomy and How Should I Use It? 135 Taxonomies Versus Post Meta 135 Creating Custom Taxonomies 137 register_taxonomy( $taxonomy, $object_type, $args ) 137 register_taxonomy_for_object_type( $taxonomy, $object_type ) 141 Using Custom Post Types and Taxonomies in Your Themes and Plugins 141 The Theme Archive and Single Template Files 142 Good Old WP_Query and get_posts() 142 Metadata with CPTs 145 add_meta_box( $id, $title, $callback, $screen, $context, $priority, $callback_args ) 146 vi | Table of Contents Custom Wrapper Classes for CPTs 148 Extending WP_Post Versus Wrapping It 150 Why Use Wrapper Classes? 151 Keep Your CPTs and Taxonomies Together 151 Keep It in the Wrapper Class 152 Wrapper Classes Read Better 154 6. Users, Roles, and Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Getting User Data 156 Add, Update, and Delete Users 158 Hooks and Filters 161 What Are Roles and Capabilities? 162 Checking a User’s Role and Capabilities 163 Creating Custom Roles and Capabilities 164 Extending the WP_User Class 166 Adding Registration and Profile Fields 168 Customizing the Users Table in the Dashboard 172 Plugins 174 Theme My Login 174 Hide Admin Bar from Non-Admins 174 Paid Memberships Pro 174 PMPro Register Helper 174 Members 175 7. Other WordPress APIs, Objects, and Helper Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Shortcode API 177 Shortcode Attributes 178 Nested Shortcodes 179 Removing Shortcodes 180 Other Useful Shortcode-Related Functions 180 Widgets API 181 Before You Add Your Own Widget 182 Adding Widgets 182 Defining a Widget Area 186 Embedding a Widget Outside of a Dynamic Sidebar 188 Dashboard Widgets API 188 Removing Dashboard Widgets 189 Adding Your Own Dashboard Widget 191 Settings API 193 Do You Really Need a Settings Page? 194 Could You Use a Hook or Filter Instead? 194 Use Standards When Adding Settings 196 Table of Contents | vii Ignore Standards When Adding Settings 196 Rewrite API 197 Adding Rewrite Rules 198 Flushing Rewrite Rules 199 Other Rewrite Functions 200 WP-Cron 202 Adding Custom Intervals 203 Scheduling Single Events 204 Kicking Off Cron Jobs from the Server 204 Using Server Crons Only 206 WP Mail 206 Sending Nicer Emails with WordPress 207 File Header API 209 Adding File Headers to Your Own Files 211 Adding New Headers to Plugins and Themes 212 8. Secure WordPress. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Why It’s Important 215 Security Basics 216 Update Frequently 216 Don’t Use the Username “admin” 216 Use a Strong Password 217 Examples of Bad Passwords 217 Examples of Good Passwords 218 Hardening Your WordPress Install 218 Don’t Allow Admins to Edit Plugins or Themes 218 Change Default Database Tables Prefix 218 Move wp-config.php 219 Hide Login Error Messages 220 Hide Your WordPress Version 220 Don’t Allow Logins via wp-login.php 221 Add Custom .htaccess Rules for Locking Down wp-admin 221 Backup Everything! 222 Scan Scan Scan! 223 Useful Security Plugins 223 Spam-Blocking Plugins 223 Backup Plugins 224 Scanner Plugins 224 Login and Password-Protection Plugins 225 Writing Secure Code 225 Check User Capabilities 225 Custom SQL Statements 226 viii | Table of Contents

Description:
While every precaution has been taken in the preparation of this book, the publisher and authors assume Functions Found in /wp-includes/taxonomy.php. 50 .. and “teachers” to better organize your code using OOP techniques Thanks to our great technical editors Peter MacIntyre and Pippin Wil‐.
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.