Skip to content
Chase Wiseman edited this page Mar 30, 2018 · 18 revisions

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.

Composer

  1. Delete the plugin's /lib/skyverge directory and commit
  2. Add a new composer.json file to the plugin/project root, containing:
{
  "minimum-stability": "dev",
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/skyverge/wc-plugin-framework"
    }
  ],
  "require" : {
    "skyverge/wc-plugin-framework": "5.1.1" // change to the appropriate plugin version
  }
}
  1. Commit and run composer install

Loader Class

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:

  1. 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) is WC_Authorize_Net_AIM, then the new file would be /class-wc-authorize-net-aim.php
  2. 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.
  3. 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();.
  4. From the main plugin file, clear any code after the is_woocommerce_active() check.
  5. Replace with the contents of the framework example loader class, and clear all of the TODO items for renaming classes and methods where necessary.

Namespaces

  1. 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_1 as Framework;Be sure to replace the version namespace with the framework version you're implementing.
  2. Add the Framework\ namespace alias to every use of a framework class. Often you can simply search & replace: SV_WC_ > Framework\SV_WC_.
  3. Review the changes to ensure you've caught all of the instances, and that the new alias is used correctly in all cases.

Integrations

  1. Add the following methods to any class that implements Framework\SV_WC_API_Request or extends Framework\SV_WC_API_XML_Request:

Gateways

  1. Add the get_payment_type() method to any response class that implements Framework\SV_WC_Payment_Gateway_API_Response, returning the appropriate payment type.
  2. If overridden, ensure the gateway's do_credit_card_capture() method matches the new signature, and handles the new return value (array).
  3. If overridden, sure the gateway's get_order_for_capture() method matches the new signature.
  4. Search for any hardcoded card type strings, such as mc or diners, 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.