Você está na página 1de 2

26

CHAPTER 2 PLUGIN FOUNDATION

Notice the spacing technique for each statement. This makes reading and following your code logic
much easier because the code examples are clean and consistent throughout.

Shorthand PHP
You shouldnt use the shorthand PHP tags ( <? ?> ) in your code. The reason for this is that
shorthand PHP tags must be enabled on your server before they will function. Many hosting
configurations have this feature disabled by default, which means your plugin would immediately
break when activated in WordPress. Instead, you should wrap your PHP code in standard tags:
<?php ?>

SQL Statements
When making database calls in WordPress you may need to write custom SQL statements to query
the proper data from the database. SQL statements can be broke into multiple lines if the complexity
of the statement warrants it. Even though SQL is not case-sensitive, its good practice to capitalize
the SQL commands in the statement.
SELECT username FROM table1 WHERE status = active

Chapter 6, Plugin Security, discusses the proper way to use SQL statements in WordPress.

PLUGIN DEVELOPMENT CHECKLIST


When developing a new plugin in WordPress, you need to remember many things to create a proper
plugin foundation. Following is a checklist to help with the process. Following this checklist you can
be confident you have a proper plugin foundation for your new plugin:

Determine a unique and descriptive plugin name.

Is the name descriptive of your plugins function?

Have you verified the plugin doesnt exist in the Plugin Directory?

Set a unique plugin prefi x.

Is the prefi x unique enough to avoid conflicts?

Create your plugin folder structure.

Will your plugin need a PHP directory?

Will your plugin need a JavaScript directory?

Will your plugin need a CSS directory?

Will your plugin need an images directory?

Create your default plugin fi les.

Create your primary fi le named the same as your plugin folder.

Create the uninstall.php fi le for your uninstall procedures.

www.it-ebooks.info

Summary

Create your plugins header code.

Set your plugin name as you want it displayed.

Add a detailed description about your plugins purpose.

Set the proper version for your plugin.

Verify both Plugin URI and Author URI values are set.

Include a license for your plugin.

Place the license code directly below your plugin header.

Create your plugins activation function.

Does your plugin require a specific version of WordPress or higher to function?

Does your plugin require default options to be set when activated?

Create your plugins deactivation function.

27

Does your plugin require something to happen when it is deactivated?

Create your plugins uninstall script.

Create an uninstall.php fi le

Include uninstall scripts in the fi le

File references.

Use the proper directory constants and functions to determine paths within
WordPress and your plugin.

SUMMARY
This chapter discussed creating a proper foundation when developing plugins for WordPress.
Following these techniques is essential in creating plugins that work across all types of WordPress
setups. Keeping your code properly documented is also an important step in detailing how your
code functions and why. This can save time in the future when revisiting your code for updates. It
can also help other developers understand your code logic.

www.it-ebooks.info

Você também pode gostar