WordPress 3 Plugin Development Essentials.pdf

时间:2022-09-03 07:38:13
【文件属性】:

文件名称:WordPress 3 Plugin Development Essentials.pdf

文件大小:5.37MB

文件格式:PDF

更新时间:2022-09-03 07:38:13

WordPress Plugin Development Essentials

Table of Contents Preface 1 Chapter 1: Preparing for WordPress Development 7 WordPress background 7 Extending WordPress 8 Understanding WordPress architecture 8 Templating 9 Introducing plugins 9 Summarizing architecture 10 Tools for web development 11 WordPress 11 Mac 12 Windows 12 Text editor 12 Using an IDE 13 FTP client 14 MySQL client 14 Coding best practices 15 Basic organization 15 Isolate tasks into functions 16 Use classes 16 Use descriptive variable names 16 Use descriptive function names 17 Separate logic and display layers 17 Go modular, to a point 18 Avoid short tags 18 Planning ahead / starting development 18 Interfaces 19 Localization 19 Table of Contents [ ii ] Documentation for the developer 19 Version control 20 Environment 20 Tests 20 Security 21 Printing user-supplied data to a page 21 Using user-supplied data to construct database queries 22 Debugging 22 Clearing your browser cache 23 Updating your php.ini file 23 Configuring your wp-config.php file 23 Checking your syntax 24 Checking values 24 Exercise 25 Summary 26 Chapter 2: Anatomy of a Plugin 29 Deconstructing an existing plugin: "Hello Dolly" 29 Activating the plugin 29 Examining the hello.php file 30 Information header 30 Exercise—breaking the header 30 Location, name, and format 31 Understanding the Includes 32 Exercise – parse errors 32 Bonus for the curious 33 User-defined functions 34 Exercise—an evil functionless plugin 34 What just happened 36 Omitting the closing "?>" PHP tag 38 A better example: Adding functions 38 Referencing hooks via add_action() and add_filter() 39 Actions versus Filters 40 Exercise—actions and filters 40 Exercise—filters 41 Reading more 43 Summary 44 Chapter 3: Social Bookmarking 45 The overall plan 46 Proof of concept 46 Avoiding conflicting function names 47 Table of Contents [ iii ] The master plugin outline 48 The plugin information header 50 In your browser—information header 51 Adding a link to the post content 51 Documenting our functions 52 In your browser—linking to the post content 52 Adding JavaScript to the head 52 Making our link dynamic 55 Adding a button template 57 Getting the post URL 58 In your browser—getting the post URL 60 Getting the post title 60 Getting the description 60 Getting the media type 62 Getting the post topic 62 In your browser—title, description, and topic 64 Checking WordPress versions 64 Summary 66 Chapter 4: Ajax Search 67 What is Ajax? 67 The overall plan 70 The proof of concept mock up 71 Hooking up jQuery 74 Test that jQuery has loaded 74 What happened? 75 Using the FireBug console directly 75 Writing HTML dynamically to a target div 76 Multi-line strings 77 Viewing the generated page 78 Anonymous functions 79 Adding a div on the fly 79 Create a listener 80 Fetching data from another page 81 Creating our plugin 83 Creating index.php and activating the plugin 84 Creating our first PHP class 85 Updating index.php 86 Testing your version of PHP 87 Testing for searchable pages 89 Adding your own CSS files 90 Adding your search handler 92 Adding your own JavaScript 92 Handling Ajax search requests 96 Table of Contents [ iv ] Formatting your search results 99 Summary 102 Chapter 5: Content Rotator 105 The plan 105 Widget overview 106 Preparation 106 Activating your plugin 110 Activating the widget 110 Having problems? 111 Parents and children: extending classes 112 Objects vs. libraries: when to use static functions 114 Add custom text 115 Adding widget options 116 Generating random content 121 Expiration dates: adding options to our widget 125 Expiration dates: enforcing the shelf life 126 Explaining the $instance 127 Adding a custom manager page 129 Adding options to the custom manager page 131 Randomizing content from the database 134 Review of PHP functions used 135 Summary 135 Chapter 6: Standardized Custom Content 137 What WordPress does for you: custom fields 138 What WordPress doesn't do for you 138 Standardizing a post's custom fields 139 Creating a new plugin 139 Removing the default WordPress form for custom fields 140 Creating our own custom meta box 143 Defining custom fields 145 Generating custom form elements 149 Saving custom content 155 Having trouble saving data? 157 Displaying custom data in your Templates 158 Copying a theme 158 Modifying the theme 159 Granular display of custom fields 161 Bonus for the MySQL curious 163 Known limitations 164 Summary 165 Table of Contents [ v ] Chapter 7: Custom Post Types 167 Background: What's in a name? 168 Understanding register_post_type() 169 Customizing our post type 175 Using shortcodes 177 Testing our shortcode 180 Customizing our plugin 181 Creating a settings shortcut link 186 Cleaning up when uninstalling 188 Summary 190 Chapter 8: Versioning Your Code with Subversion (SVN) 191 Why Subversion? 192 Understanding the terminology and concepts 192 Checking out a local working copy 193 SVN folder structure 194 Checkout, revisited 196 Setting up an SVN repository 197 Checking out a local working copy of our repo 198 Adding files 199 Committing changes to the repository 200 Overcoming errors 201 Verifying the new state of your repository 202 Adding more files to your repository 203 Removing files from the repository 204 Updating your working copy 204 Tagging a version 205 Reverting an entire project 206 Reverting a single file 207 Moving files 208 Exporting your working copy 208 Quick reference 209 Summary 211 Chapter 9: Preparing Your Plugin for Distribution 213 Public enemy number one: PHP notices 213 PHP short tags 215 Conflicting names 215 Modifying loader.php 220 Testing WordPress version 222 Testing PHP version 222 Testing MySQL version 223 Download from Wow! eBook Table of Contents [ vi ] Testing PHP modules 223 Testing WordPress installed plugins 224 Custom tests 226 Unit tests 226 WordPress limitations 227 Health check page 227 Storing test results in the database 229 Death to clippy: Use sensible configurations 229 Double check your interface 230 Documentation 230 Identify the purpose 230 Learning to drive: Keeping it relevant 231 Phrasebooks vs. dictionaries: Give examples 232 Analogy: The three bears 232 Analogy: PC load letter 232 The decalog of documentation 233 Summary 235 Chapter 10: Publishing Your Plugin 237 Internationalization and localization 237 Processing each message 238 Choosing a textdomain 240 Best practices 240 Working with formatting 241 More advanced messages 242 Plural vs. singular 242 More complex messages 243 Notes to translators 244 Language files 245 Creating a POT file 246 Creating translations: .po files 248 Loading a textdomain 250 Updating a translation 251 Format for the readme.txt file 252 Section – installation 253 Section – Frequently Asked Questions 253 Section – screenshots 253 New addition – videos 254 Section – summary 254 Requesting and using SVN access 255 Publicity and promotion 257 Summary 258 Table of Contents [ vii ] Appendix A: Recommended Resources 259 PHP reference 259 Function reference 259 The WordPress forums 259 WebDev Studios 260 Viper007Bond 260 Kovshenin 260 SLTaylor 260 XPlus3 260 WP Engineer 261 Other plugins 261 Appendix B: WordPress API Reference 263 PHP functions 263 dirname 263 file_get_contents 263 preg_match 264 preg_replace 264 print_r 264 sprintf 265 strtolower 265 substr 265 WordPress Functions 266 __ 266 _e 266 add_action 266 add_filter 267 add_meta_box 267 add_options_page 267 check_admin_referer 267 esc_html 268 get_option 268 get_post_meta 268 get_the_ID 268 register_post_type 269 remove_meta_box 269 screen_icon 269 the_content 269 the_meta 269 update_post_meta 270 wp_count_posts 270 Table of Contents [ viii ] wp_die 270 wp_nonce_field 270 Actions 270 admin_init 270 admin_menu 270 do_meta_boxes 271 init 271 save_post 271 widgets_init 271 wp_head 272 Filters 272 the_content 272 Index 273


网友评论