2 Chapter 3 FIGURE 3-1: Custom registered menu FIGURE 3‐1 : Custom registered menu NOTE Menus are a common feature in WordPress plugins and are generally expected by users. It's a good idea to mention where your plugin settings can be found in the plugin description and documentation.
FIGURE 3-2: Submenus FIGURE 3‐2 : Submenus NOTE Not all plugins will need submenus. For example, a plugin with a single settings page has no need for additional submenus. When creating your new plugin, it's important to determine if submenus will be needed for a good user experience.
FIGURE 3-3: Submenu labeled PDEV Settings FIGURE 3‐3 : Submenu labeled PDEV Settings The following is a list of all available submenu functions in WordPress: add_dashboard_page: Adds a submenu to the Dashboard menu add_posts_page: Adds a submenu to the Posts menu add_media_page: Adds a submenu to the Media menu add_links_page: Adds a submenu to the Links menu add_pages_page: Adds a submenu to the Pages menu add_comments_page: Adds a submenu to the Comments menu add_theme_page: Adds a submenu to the Appearance menu add_plugins_page: Adds a submenu to the Plugins menu add_users_page: Adds a submenu to the Users menu add_management_page: Adds a submenu to the Tools menu add_options_page: Adds a submenu to the Settings menu To use any of these functions, simply swap out the function name in the code shown earlier. NOTE If your plugin requires only a single options page, it's best practice to add it as a submenu to an existing menu. If you require more than one, create a custom top‐level menu.
FIGURE 3-4: Plugin management page FIGURE 3‐4 : Plugin management page Activate this plugin and head to Settings ➪ PDEV Settings. You'll see a similar interface to the one shown in Figure 3‐4 .
FIGURE 3-5: Error message FIGURE 3‐5 : Error message
FIGURE 3-6: Section appended FIGURE 3‐6 : Section appended You still need to whitelist this setting, with register_setting() . Omitting this step would make WordPress ignore the setting when submitting the form.
FIGURE 3-7: Singular field FIGURE 3‐7 : Singular field
FIGURE 3-8: Heading levels FIGURE 3‐8 : Heading levels
FIGURE 3-9: Dashicons FIGURE 3‐9 : Dashicons It's important to note that dashicons are automatically loaded within the WordPress Dashboard, but not on the frontend of the website. If you'd like to use dashicons on the public side, you'll need to enqueue the dashicon script, as shown here: Now your plugin has a clean header and uses the Plug icon. For more information and a complete list of all Dashicons available, see the official resource at https://developer.wordpress.org/resource/dashicons .
FIGURE 3-10: Dismissable notices FIGURE 3‐10 : Dismissable notices
FIGURE 3-11: WordPress-styled button FIGURE 3‐11 : WordPress‐styled button Links can also take the form of a button by using the appropriate class. Search Search Primary Search Secondary This example shows how a standard link can be styled to look like a button, as shown in Figure 3‐12 . To normal users, they would never know these are regular text links because they look just like a button. FIGURE 3‐12 : Link styled to look like a button
FIGURE 3-12: Link styled to look like a button FIGURE 3‐12 : Link styled to look like a button
FIGURE 3-13: WordPress-like options FIGURE 3‐13 : WordPress‐like options
FIGURE 3-14: Table style FIGURE 3‐14 : Table style
FIGURE 3-15: Pagination style FIGURE 3‐15 : Pagination style Keeping your plugin design consistent with the WordPress user interface can reduce your plugins' learning curve because users will feel comfortable with the design and styles used. This can also make your plugins' design future‐proof. If the WordPress core styles change down the road, your plugins' design will also change to match the new user interface, and you won't need to edit a single line of code!
3 Chapter 4 FIGURE 4-1: Insufficient privileges
FIGURE 4-2: Expired link message
FIGURE 4-3: Rogue JavaScript running
FIGURE 4-4: Related Posts list
4 Chapter 7FIGURE 7-1: Classic Editor, not covered in this chapterFIGURE 7-2: GutenbergFIGURE 7-3: Block Library menuFIGURE 7-4: Categories of blocksFIGURE 7-5: View optionsFIGURE 7-6: Sidebar's Document menuFIGURE 7-7: Sidebar's Block menu and formatting toolbarFIGURE 7-8: WooCommerce blocksFIGURE 7-9: Newest Products blockFIGURE 7-10: Event Calendar blocksFIGURE 7-11: Post Type Switcher pluginFIGURE 7-12: webpack finishing successfullyFIGURE 7-13: Our “Hello world!” block in the Block LibraryFIGURE 7-14: Selecting our new blockFIGURE 7-15: Editing a postFIGURE 7-16: WP-CLI scaffold generatedFIGURE 7-17: Build Step 1FIGURE 7-18: Build Step 2FIGURE 7-19: Build Step 3FIGURE 7-20: My Block in Block LibraryFIGURE 7-21: My Block in Content Area
5 Chapter 8FIGURE 8-1: Books admin menu and screenFIGURE 8-2: Tags submenu itemFIGURE 8-3: Genres submenu
6 Chapter 9FIGURE 9-1: New form on the user edit pageFIGURE 9-2: New roles
7 Chapter 10FIGURE 10-1: Scheduled Events pageFIGURE 10-2: Number output
8 Chapter 11FIGURE 11-1: Settings box
9 Chapter 12FIGURE 12-1: Unformatted JSONFIGURE 12-2: Formatted JSONFIGURE 12-3: Post resultsFIGURE 12-4: Error messageFIGURE 12-5: Authentication workedFIGURE 12-6: “My Time at Crystal Lake” post
10 Chapter 13FIGURE 13-1: Tools ➪ Network menu options
11 Chapter 14FIGURE 14-1: Simple post listFIGURE 14-2: Widgets admin screenFIGURE 14-3: Favorites listFIGURE 14-4: Custom dashboard widgetFIGURE 14-5: Custom dashboard widget
12 Chapter 15FIGURE 15-1: Admin Toolbar menu itemFIGURE 15-2: Query Monitor interfaceFIGURE 15-3: Database queries
13 Chapter 16FIGURE 16-1: Function with parametersFIGURE 16-2: Codex search optionsFIGURE 16-3: WordPress PHPXrefFIGURE 16-4: Function list
1 Cover
2 Table of Contents
3 Begin Reading FOREWORD This book will teach you how to develop for WordPress. WordPress has, over the past two decades, grown into the CMS that powers more than one‐third of all websites. If you're proficient at WordPress development, you'll never be out of a job again. Starting out as a simple blogging system, over the last few years WordPress has morphed into a fully featured and widely used content management system. It offers individuals and companies worldwide a free and open source alternative to closed source and often very expensive systems. When I say fully featured, that's really only true because of the ability to add any functionality needed in the form of a plugin. The core of WordPress is simple: you add in functionality with plugins as you need it. Developing plugins allows you to stand on the shoulders of a giant: you can showcase your specific area of expertise and help users benefit while not having to deal with parts of WordPress you don't care or know about. When I wrote the foreword of this book's first edition, nine years ago, I'd just started my own company. That company has since grown to consist of 100+ people, and our plugins are used on more than 10 million sites—all through the power of open source and plugins. I wished that when I started developing plugins for WordPress as a hobby, almost 15 years back, this book had been around. I used it as a reference countless times since, and I still regularly hand this book to new colleagues. The authors of this book have always been a source of good information and wonderful forces in the WordPress community. Each of them is an expert in his own right; together they are one of the best teams that could have been gathered to write this book, and I'm glad they're here for a second edition. WordPress makes it easy for people to have their say through words, sound, and visuals. For those who write code, WordPress allows you to express yourself in code. And it's simple. Anyone can write a WordPress plugin. With this guide in hand, you can write a plugin that is true to WordPress’ original vision: code is poetry. Happy coding! Joost de Valk Yoast.com
Читать дальше