SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Wordpress Develompent
A Modern Approach
Who am I ?
Backend Developer
@Populis
@whitekross on twitter
Alessandro Fiore
The most used PHP software
https://wordpress.org/download/counter/
24,5%(of the Web)
http://w3techs.com/technologies/overview/content_management/all
Innovator’s Dilemma ?
Wordpress, we have some problems
● Poor Core Codebase
● 3th Party Codebase even poorer
● Lack of standards
Use Better Tools!
Wordpress ❤ Composer
Custom Installers
At times it may be necessary for a
package to require additional actions
during installation, such as installing
packages outside of the default
vendor library.
{
"name": "my-vendor/my-lib-plugin",
"type": "my-lib-plugin",
"require": {
"my-vendor/my-lib-installer": "*"
}
}
ComposerInstallerInstallerInterface
interface InstallerInterface
{
//Decides if the installer supports the given type
public function supports($packageType);
//Checks that provided package is installed.
public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package);
//Installs specific package.
public function install(InstalledRepositoryInterface $repo, PackageInterface $package);
//Updates specific package.
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target);
//Uninstalls specific package.
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package);
//Returns the installation path of a package
public function getInstallPath(PackageInterface $package);
}
A basic Installer Plugin
1. The package file: composer.json
2. The Plugin class, e.g.: MyProjectComposerPlugin.php, implements
ComposerPluginPluginInterface.
3. The Installer class, e.g.: MyProjectComposerInstaller.php, implements
ComposerInstallerInstallerInterface.
Wordpress Core itself is a dependency
2) johnpbloch/wordpress
A fork of WordPress with Composer support added. Synced every 15
minutes.
1) johnpbloch/wordpress-core-installer
A custom installer to handle deploying WordPress with composer.
Wordpress Core itself is a dependency
use ComposerInstallerLibraryInstaller;
use ComposerPackagePackageInterface;
class WordPressCoreInstaller extends LibraryInstaller {
const TYPE = 'wordpress-core';
public function getInstallPath( PackageInterface $package ) {
$extra = $package->getExtra();
if ( ! $installationDir && ! empty( $extra['wordpress-install-dir'] ) ) {
$installationDir = $extra['wordpress-install-dir'];
}
return $installationDir;
}
public function supports( $packageType ) {
return self::TYPE === $packageType;
}
}
Wordpress Core itself is a dependency
"require": {
"johnpbloch/wordpress": "4.3.1"
},
"extra": {
"wordpress-install-dir": "wp"
},
Manage Plugins with Composer
composer/installers
A Multi-Framework Composer Library Installer. It will magically install their package to the
correct location based on the specified package type.
● wordpress-plugin => wp-content/plugins/{$name}
● wordpress-theme => wp-content/themes/{$name}
● wordpress-muplugin => wp-content/mu-plugins/{$name}
Manage Plugins with Composer
"extra": {
"installer-paths": {
"src/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"src/plugins/{$name}/": ["type:wordpress-plugin"],
"src/themes/{$name}/": ["type:wordpress-theme"]
},
}
Manage Plugins with Composer
Limited to plugins that already have a
composer.json.
What about 3th party plugins from
https://wordpress.org/plugins/ ?
Wordpress Packagist
Mirrors the WordPress Plugin and
Theme directories as a Composer
repository.
Manage Plugins with Composer
"repositories":[{
"type":"composer",
"url":"http://wpackagist.org"
}
],
"require": {
"aws/aws-sdk-php":"*",
"wpackagist-plugin/akismet":"dev",
"wpackagist-plugin/captcha":"3.9",
"wpackagist-theme/hueman":"*"
},
Wordpress ❤ Composer
├── composer.json
├── composer.lock
├── index.php
├── src/
├── vendor/
└── wp/
├── index.php
├── wp-activate.php
├── wp-admin/
├── wp-blog-header.php
├── wp-comments-post.php
├── wp-config.php
├── wp-content/
├── wp-cron.php
├── wp-includes/
├── wp-links-opml.php
├── wp-load.php
├── wp-login.php
├── wp-mail.php
├── wp-settings.php
├── wp-signup.php
├── wp-trackback.php
└── xmlrpc.php
Change WP Directory Structure
// INDEX.php (under our new webroot)
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
/** Change Content dir */
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/../src' );
define( 'WP_CONTENT_URL', 'http://<domain>//src' );
// WP_CONFIG.php
/** Change WORDPRESS url */
define( 'WP_SITEURL','http://<domain>/wp');
define( 'WP_HOME','http://<domain>/');
A CLI for Wordpress
composer require wp-cli/wp-cli
WP-CLI is a set of command-line tools for managing WordPress installations.
Run Commands with WP-CLI
wp <command> <sub-command> <params>
● core: Download, install, update, manage WordPress.
● db: Perform basic database operations.
● plugin: Manage, install, activate, deactivate plugins.
● post: Manage, generate, publish posts.
● scaffold: Generate code for post types, plugins, etc.
● and many more... http://wp-cli.org/commands/
Wordpress Automated Testing
Official test suite repository.
https://develop.svn.wordpress.org/trunk/
Time: 4.58 minutes, Memory: 97.75Mb
There was 1 failure:
FAILURES!
Tests: 4251, Assertions: 15938, Failures: 1, Skipped: 65.
https://make.wordpress.org/core/handbook/testing/automated-testing/
Test Your Plugins!
$ wp scaffold plugin test_plugin
├──bin/
│ └──install-wp-tests.sh
├──phpunit.xml
├──test_plugin.php
└──tests/
├──bootstrap.php
└──test-sample.php
└──.travis.yml
// This will install WP test suite
// under “/tmp/wordpress”
$ bash bin/install-wp-tests.sh wordpress_test root ''
Test Your Plugins!
class FooTest extends WP_UnitTestCase
{
function test_bar() {
// replace this your test
$this->assertTrue( true );
}
}
● Object Factories:
$this->factory->post->create();
● Custom Asserts:
$response = wp_remote_get( $url );
$this->assertWPError( $response );
$this->assertQueryTrue( 'is_tag', 'is_archive' );
● Useful Methods:
setUp() | tearDown() | go_to() |
remove_added_uploads() ecc..
Grazie!
Code Samples:
● https://github.com/whitekross/wp-composer
● https://github.com/whitekross/wp-badge-poser
Useful Links:
● https://roots.io/bedrock/
● http://composer.rarst.net/
● http://codesymphony.co/writing-wordpress-plugin-unit-tests/

Weitere ähnliche Inhalte

Was ist angesagt?

DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus Magento
Magento Dev
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
Mainak Goswami
 

Was ist angesagt? (20)

Die .htaccess richtig nutzen
Die .htaccess richtig nutzenDie .htaccess richtig nutzen
Die .htaccess richtig nutzen
 
DevHub 3 - Composer plus Magento
DevHub 3 - Composer plus MagentoDevHub 3 - Composer plus Magento
DevHub 3 - Composer plus Magento
 
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with Composer
 
HTTPS + Let's Encrypt
HTTPS + Let's EncryptHTTPS + Let's Encrypt
HTTPS + Let's Encrypt
 
How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.
 
The wp config.php
The wp config.phpThe wp config.php
The wp config.php
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Nahlédněte za oponu VersionPressu
Nahlédněte za oponu VersionPressuNahlédněte za oponu VersionPressu
Nahlédněte za oponu VersionPressu
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
 
Webinar: 5 Tricks for WordPress web administrators
Webinar: 5 Tricks for WordPress web administratorsWebinar: 5 Tricks for WordPress web administrators
Webinar: 5 Tricks for WordPress web administrators
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Why it's dangerous to turn off automatic updates and here's how to do it
Why it's dangerous to turn off automatic updates and here's how to do itWhy it's dangerous to turn off automatic updates and here's how to do it
Why it's dangerous to turn off automatic updates and here's how to do it
 
Drupal Development Tips
Drupal Development TipsDrupal Development Tips
Drupal Development Tips
 

Ähnlich wie Wordpress development: A Modern Approach

Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
LumoSpark
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
ylefebvre
 

Ähnlich wie Wordpress development: A Modern Approach (20)

WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
 
Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008
 
Composer
ComposerComposer
Composer
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin Development
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Managing a WordPress Site as a Composer Project by Rahul Bansal @ WordCamp Na...
Managing a WordPress Site as a Composer Project by Rahul Bansal @ WordCamp Na...Managing a WordPress Site as a Composer Project by Rahul Bansal @ WordCamp Na...
Managing a WordPress Site as a Composer Project by Rahul Bansal @ WordCamp Na...
 
WPDay Bologna 2013
WPDay Bologna 2013WPDay Bologna 2013
WPDay Bologna 2013
 
Using Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websitesUsing Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websites
 
Composer
ComposerComposer
Composer
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
Deploying WP Multisite to Heroku
Deploying WP Multisite to HerokuDeploying WP Multisite to Heroku
Deploying WP Multisite to Heroku
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2
 
Using Composer with Drupal and Drush
Using Composer with Drupal and DrushUsing Composer with Drupal and Drush
Using Composer with Drupal and Drush
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Wordpress development: A Modern Approach

  • 2. Who am I ? Backend Developer @Populis @whitekross on twitter Alessandro Fiore
  • 3. The most used PHP software https://wordpress.org/download/counter/
  • 6.
  • 7. Wordpress, we have some problems ● Poor Core Codebase ● 3th Party Codebase even poorer ● Lack of standards
  • 9. Wordpress ❤ Composer Custom Installers At times it may be necessary for a package to require additional actions during installation, such as installing packages outside of the default vendor library. { "name": "my-vendor/my-lib-plugin", "type": "my-lib-plugin", "require": { "my-vendor/my-lib-installer": "*" } }
  • 10. ComposerInstallerInstallerInterface interface InstallerInterface { //Decides if the installer supports the given type public function supports($packageType); //Checks that provided package is installed. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package); //Installs specific package. public function install(InstalledRepositoryInterface $repo, PackageInterface $package); //Updates specific package. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target); //Uninstalls specific package. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package); //Returns the installation path of a package public function getInstallPath(PackageInterface $package); }
  • 11. A basic Installer Plugin 1. The package file: composer.json 2. The Plugin class, e.g.: MyProjectComposerPlugin.php, implements ComposerPluginPluginInterface. 3. The Installer class, e.g.: MyProjectComposerInstaller.php, implements ComposerInstallerInstallerInterface.
  • 12. Wordpress Core itself is a dependency 2) johnpbloch/wordpress A fork of WordPress with Composer support added. Synced every 15 minutes. 1) johnpbloch/wordpress-core-installer A custom installer to handle deploying WordPress with composer.
  • 13. Wordpress Core itself is a dependency use ComposerInstallerLibraryInstaller; use ComposerPackagePackageInterface; class WordPressCoreInstaller extends LibraryInstaller { const TYPE = 'wordpress-core'; public function getInstallPath( PackageInterface $package ) { $extra = $package->getExtra(); if ( ! $installationDir && ! empty( $extra['wordpress-install-dir'] ) ) { $installationDir = $extra['wordpress-install-dir']; } return $installationDir; } public function supports( $packageType ) { return self::TYPE === $packageType; } }
  • 14. Wordpress Core itself is a dependency "require": { "johnpbloch/wordpress": "4.3.1" }, "extra": { "wordpress-install-dir": "wp" },
  • 15. Manage Plugins with Composer composer/installers A Multi-Framework Composer Library Installer. It will magically install their package to the correct location based on the specified package type. ● wordpress-plugin => wp-content/plugins/{$name} ● wordpress-theme => wp-content/themes/{$name} ● wordpress-muplugin => wp-content/mu-plugins/{$name}
  • 16. Manage Plugins with Composer "extra": { "installer-paths": { "src/mu-plugins/{$name}/": ["type:wordpress-muplugin"], "src/plugins/{$name}/": ["type:wordpress-plugin"], "src/themes/{$name}/": ["type:wordpress-theme"] }, }
  • 17. Manage Plugins with Composer Limited to plugins that already have a composer.json. What about 3th party plugins from https://wordpress.org/plugins/ ? Wordpress Packagist Mirrors the WordPress Plugin and Theme directories as a Composer repository.
  • 18. Manage Plugins with Composer "repositories":[{ "type":"composer", "url":"http://wpackagist.org" } ], "require": { "aws/aws-sdk-php":"*", "wpackagist-plugin/akismet":"dev", "wpackagist-plugin/captcha":"3.9", "wpackagist-theme/hueman":"*" },
  • 19. Wordpress ❤ Composer ├── composer.json ├── composer.lock ├── index.php ├── src/ ├── vendor/ └── wp/ ├── index.php ├── wp-activate.php ├── wp-admin/ ├── wp-blog-header.php ├── wp-comments-post.php ├── wp-config.php ├── wp-content/ ├── wp-cron.php ├── wp-includes/ ├── wp-links-opml.php ├── wp-load.php ├── wp-login.php ├── wp-mail.php ├── wp-settings.php ├── wp-signup.php ├── wp-trackback.php └── xmlrpc.php
  • 20. Change WP Directory Structure // INDEX.php (under our new webroot) /** Loads the WordPress Environment and Template */ require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' ); /** Change Content dir */ define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/../src' ); define( 'WP_CONTENT_URL', 'http://<domain>//src' ); // WP_CONFIG.php /** Change WORDPRESS url */ define( 'WP_SITEURL','http://<domain>/wp'); define( 'WP_HOME','http://<domain>/');
  • 21. A CLI for Wordpress composer require wp-cli/wp-cli WP-CLI is a set of command-line tools for managing WordPress installations.
  • 22. Run Commands with WP-CLI wp <command> <sub-command> <params> ● core: Download, install, update, manage WordPress. ● db: Perform basic database operations. ● plugin: Manage, install, activate, deactivate plugins. ● post: Manage, generate, publish posts. ● scaffold: Generate code for post types, plugins, etc. ● and many more... http://wp-cli.org/commands/
  • 23. Wordpress Automated Testing Official test suite repository. https://develop.svn.wordpress.org/trunk/ Time: 4.58 minutes, Memory: 97.75Mb There was 1 failure: FAILURES! Tests: 4251, Assertions: 15938, Failures: 1, Skipped: 65. https://make.wordpress.org/core/handbook/testing/automated-testing/
  • 24. Test Your Plugins! $ wp scaffold plugin test_plugin ├──bin/ │ └──install-wp-tests.sh ├──phpunit.xml ├──test_plugin.php └──tests/ ├──bootstrap.php └──test-sample.php └──.travis.yml // This will install WP test suite // under “/tmp/wordpress” $ bash bin/install-wp-tests.sh wordpress_test root ''
  • 25. Test Your Plugins! class FooTest extends WP_UnitTestCase { function test_bar() { // replace this your test $this->assertTrue( true ); } } ● Object Factories: $this->factory->post->create(); ● Custom Asserts: $response = wp_remote_get( $url ); $this->assertWPError( $response ); $this->assertQueryTrue( 'is_tag', 'is_archive' ); ● Useful Methods: setUp() | tearDown() | go_to() | remove_added_uploads() ecc..
  • 26. Grazie! Code Samples: ● https://github.com/whitekross/wp-composer ● https://github.com/whitekross/wp-badge-poser Useful Links: ● https://roots.io/bedrock/ ● http://composer.rarst.net/ ● http://codesymphony.co/writing-wordpress-plugin-unit-tests/