of 23 /23
Intro To Plugin Development Emptying out functions.php Intro To Plugin Development Topher DeRosia @topher1kenobe

Intro to Plugin Development, Miami WordCamp, 2015

Embed Size (px)

Text of Intro to Plugin Development, Miami WordCamp, 2015

  1. 1. Intro To Plugin Development Emptying out functions.php Intro To Plugin Development Topher DeRosia @topher1kenobe
  2. 2. Hi, my name is Topher Im a WordPress developer from Grand Rapids MI @topher1kenobe Intro To Plugin Development Topher DeRosia @topher1kenobe
  3. 3. Just put this code in your themes functions.php file JUST SAY NO Intro To Plugin Development Topher DeRosia @topher1kenobe
  4. 4. Plugins are packages of code that affect your sites functionality. Themes are packages of code that affect your sites design. DO NOT MIX. Intro To Plugin Development Topher DeRosia @topher1kenobe
  5. 5. Plugins are either single files or folders in /wp-content/plugins Intro To Plugin Development Topher DeRosia @topher1kenobe
  6. 6. Typically inside each plugin folder is a file with the same name as the folder, plus any other files it needs. Intro To Plugin Development Topher DeRosia @topher1kenobe
  7. 7. In the top of every main plugin file is a header block with information about the plugin. Intro To Plugin Development Topher DeRosia @topher1kenobe
  8. 8. The only option absolutely required is the Plugin Name. The others are merely strongly recommended. VERY strongly recommended: License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: custom-header, custom-menu, editor-style, featured-images (etc) Intro To Plugin Development Topher DeRosia @topher1kenobe
  9. 9. The Secret Sauce: Any code you might have put into functions.php in your theme could go into a plugin.* *with a few exceptions Intro To Plugin Development Topher DeRosia @topher1kenobe
  10. 10. Example: Intro To Plugin Development Topher DeRosia @topher1kenobe
  11. 11. Longer Example: Intro To Plugin Development Topher DeRosia @topher1kenobe
  12. 12. Explanation: function phlog_scripts() { wp_enqueue_style( 'phlog_styles', plugins_url( '/css/phlog.css' , __FILE__ ) ); } add_action( 'wp_enqueue_scripts', 'phlog_scripts' ); I made a function called `phlog_scripts()` Inside it is a function that properly enqueues a CSS file. wp_enqueue_style takes 2 arguments, a name I made up and the path to the CSS file. The path to the CSS file is determined with the WordPress function plugins_url(). Intro To Plugin Development Topher DeRosia @topher1kenobe
  13. 13. Releasing a Plugin A plugin built for release on WordPress.org must meet a list of requirements. The requirements are listed at https://developer.wordpress.org/plugins/wordpress-org/ Best practices are found in the WordPress Plugin Handbook https://developer.wordpress.org/plugins/ Intro To Plugin Development Topher DeRosia @topher1kenobe
  14. 14. mu-plugins: mu == must use Plugins that are stored in mu-plugins are automatically activated, and cannot be deactivated. The main file of a plugin must be stored directly in the /mu-plugins/ directory, OR be included. Intro To Plugin Development Topher DeRosia @topher1kenobe
  15. 15. mu-plugins Intro To Plugin Development Topher DeRosia @topher1kenobe
  16. 16. mu-plugins To convert a regular plugin to mu-plugins, put it in the /mu-plugins directory and then make a new, single-file plugin that looks like this: Intro To Plugin Development Topher DeRosia @topher1kenobe
  17. 17. Extra Credit: WP-CLI WP-CLI is the command line tool for WordPress. It can create an empty plugin with the proper header in place: wp scaffold plugin --prompt This will ask questions like this: 1/4 : topher-test 2/4 [--plugin_name=]: Topher's Test 3/4 [--skip-tests] (Y/n): Y 4/4 [--activate] (Y/n): Y Success: Created /home/topher1/topher1kenobe.com/wp-content/plugins/topher-test 1/1 : topher-test Success: Created test files. Intro To Plugin Development Topher DeRosia @topher1kenobe
  18. 18. Real World Example Easy Digital Downloads - Customer Contact Intro To Plugin Development Topher DeRosia @topher1kenobe
  19. 19. Easy Digital Downloads - Customer Contact