-
Notifications
You must be signed in to change notification settings - Fork 42
Migrating to v5
When migrating a plugin that implements this framework from v4.9 or earlier to v5, the biggest change will be handling the new namespaces. Additionally, there are a few backwards-incompatible changes that will need to be handled. The following steps should cover most of the changes required, though it's always important to test a plugin's full range of functionality after the migration.
- Delete the plugin's
/lib/skyverge
directory and commit - Add a new
composer.json
file to the plugin or project root, containing:
{
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/skyverge/wc-plugin-framework"
}
],
"require" : {
"skyverge/wc-plugin-framework": "5.3.0"
}
}
- Change the package version to the desired tagged framework version, or if working off a specific branch, use
dev-
then the branch name, e.g."skyverge/wc-plugin-framework": "dev-5.2.0-dev"
- Commit and run
composer install
Plugins will now require a loader class to handle unsupported PHP versions. The loader class must be defined and instantiated in the main plugin file, and is meant to halt any further plugin code from being included if the environment can't support it. To implement the loader class in an existing plugin:
- Create a new file in the plugin root that will contain the main plugin class and name it according to WordPress standards. For instance, if the plugin class (which should extend
SV_WC_Plugin
) isWC_Authorize_Net_AIM
, then the new file would be/class-wc-authorize-net-aim.php
- Cut the entire plugin class from the main plugin file into this new class file, also include the main plugin function definition, which usually follows the class. Do not copy the
init_
wrapping function if one exists. - Search for a usage of the legacy
sv_wc_framework_plugins_loaded
bootstrap action, usually within the main plugin class constructor, and instead call its callback directly. e.g.add_action( 'sv_wc_framework_plugins_loaded', array( $this, 'includes' ) );
becomes just$this->includes();
. - From the main plugin file, clear any code after the
is_woocommerce_active()
check. - Replace with the contents of the framework example loader class, and clear all of the TODO items for renaming classes and methods where necessary.
- On every PHP plugin file except for the main file, add a use statement directly under the
ABSPATH
check for the framework's namespaces:use SkyVerge\WooCommerce\PluginFramework\v5_1_5 as Framework;
Be sure to replace the version namespace with the framework version you're implementing. - Add the
Framework\
namespace alias to every use of a framework class. Often you can simply search & replace:SV_WC_
>Framework\SV_WC_
. - Review the changes to ensure you've caught all of the instances, and that the new alias is used correctly in all cases.
- Remove
display_php_notice
- Update the
dependencies
array to match what's expected bySV_WC_Plugin::init_dependencies()
Some plugins will handle their includes and handler loading differently, so you'll have to handle each on a case-by-case basis. Some general notes:
- We've added the
SV_WC_Plugin::init_plugin()
&SV_WC_Plugin::init_admin()
methods that are fired atinit
andadmin_init
respectively, and can be overridden for easy plugin setup. These are not required, but may be helpful. - It's generally best practice to instantiate handlers and other classes that get assigned to plugin vars on
init
, rather than in anincludes()
method from the plugin constructor.->load_class()
calls can be moved toSV_WC_Plugin::init_plugin()
ifinit
is early enough. Be sure to test each one!
Check if there is plugin code (PHP, static assets like SCSS) referencing directly files or other assets, including framework files, that are expected to be found in the /vendor
path or /lib
path. These paths may need to be updated after installing the framework and other libraries via composer.
As of v5.2.0, the plugin lifecycle methods have been moved to SkyVerge\WooCommerce\PluginFramework\v5_2_0\Plugin\Lifecycle
. If the plugin has existing upgrade or install routines, they will need to be moved to a class that extends this.
- Create a class that extends
SkyVerge\WooCommerce\PluginFramework\v5_2_0\Plugin\Lifecycle
- Copy the
upgrade()
&&install()
methods from the main plugin into this new class and adapt them as needed. The FW class has aget_plugin()
method, so instances of$this->
referencing the plugin can be changed to$this->get_plugin()->
- Important -- Be sure to fully test the execution of each upgrade and install path after migration
- Add the following methods to any class that implements
Framework\SV_WC_API_Request
or extendsFramework\SV_WC_API_XML_Request
:
- Add the
get_payment_type()
method to any response class that implementsFramework\SV_WC_Payment_Gateway_API_Response
, returning the appropriate payment type. - If overridden, ensure the gateway's
do_credit_card_capture()
method matches the new signature, and handles the new return value (array). - If overridden, sure the gateway's
get_order_for_capture()
method matches the new signature. - Search for any hardcoded card type strings, such as
mc
ordiners
, and switch them to using the gateway helper constants. Be sure to test these changes thoroughly as some gateways can return different card type strings.
That's it! The plugin should now be ready to fully test.
SV_WC_Plugin::do_install()
-
SV_WC_Plugin::install_default_settings()
->Plugin\Lifecycle::install_default_settings()
-
SV_WC_Plugin::get_missing_extension_dependencies()
->SV_WC_Plugin_Dependencies::get_missing_php_extensions()
-
SV_WC_Plugin::get_missing_function_dependencies()
->SV_WC_Plugin_Dependencies::get_missing_php_functions()
-
SV_WC_Plugin::get_incompatible_php_settings()
->SV_WC_Plugin_Dependencies::get_incompatible_php_settings()
SV_WC_Plugin::get_dependencies()
-
SV_WC_Plugin::get_extension_dependencies()
->SV_WC_Plugin_Dependencies::get_php_extensions()
-
SV_WC_Plugin::get_function_dependencies()
->SV_WC_Plugin_Dependencies::get_php_functions()
-
SV_WC_Plugin::get_php_settings_dependencies()
->SV_WC_Plugin_Dependencies::get_php_settings()
SV_WC_Plugin::set_dependencies()
- Home
- General Usage
- Payment Gateways
- WooCommerce Blocks
- Updating
- Testing
- Workflow