-
-
Notifications
You must be signed in to change notification settings - Fork 6
Version 5 Migration
Version 5 is a major release with many breaking changes. This guide to show you how to migrate your project from version 4 to version 5.
Honestly, version 5 is a huge change. It may be easier to leave existing projects on version 4.9 unless you've got time on your hands.
The majority of changes have called out using _deprecated
functions and phpdocs in version 4.10.0 of the library. It is recommended to follow this procedure before updating to version 5.
- Update to version 4.10.*
- Enable
WP_DEBUG
. - Return
true
on thedeprecated_class_trigger_error
filter (if applicable). - Run through your normal unit/regression testing and follow any prompts from the
_deprecated
system.
It may be wise to leave the project running version 4.10.* for a little while to make sure no deprecations where missed.
It is strongly recommended to use PHPStan to detect type inconsistencies as version 5 introduces a large number of strict types.
- New Requirements
- Classes Removed With No Alternative
- Classes Removed With Alternative
- Classes With Changed Signature
- Methods Removed With Alternatives
- \Lipe\Lib\Schema\Db
- WP Core version 6.3+ is now required.
- PHP version 8.1+ is now required. Version 4.10.0 introduced this requirement so if you followed Getting Started you are already on PHP 8.1.
Some classes have been removed entirely with no alternative available. To continue to use these classes, you'll want to copy them into your project.
\Lipe\Lib\Util\Image_Resize
Some classes have been refactored into composition instead of inheritance. Using the new version will require some refactoring but the majority of the original functionality has been maintained.
-
\Lipe\Lib\Schema\Db
-> Use\Lipe\Lib\Db\Custom_Table
See -
\Lipe\Lib\Schema\Meta_Box
-> Use\Lipe\Lib\Meta\Meta_Box
-
\Lipe\Lib\Schema\Post_List_Column
-> Use\Lipe\Lib\Post_Type\Post_List_Column
-
\Lipe\Lib\Schema\Settings
-> Use\Lipe\Lib\Settings\Settings_Page
-
\Lipe\Lib\Cron\Cron_Abstract
-> Use\Lipe\Lib\Cron\Runner
-
\Lipe\Lib\Query\Args_Abstract
=> Use\Lipe\Lib\Args\Args
-
\Lipe\Lib\Query\Clause\Clause_Abstract
-> Use\Lipe\Lib\Args\Clause
-
\Lipe\Lib\Meta\Translate_Abstract
-> Use\Lipe\Lib\Meta\Translate_Abstract
-
\Lipe\Lib\Query\Update_Post
-> Use\Lipe\Lib\Post_Type\Wp_Insert_Post
-
\Lipe\Lib\Query\Args
-> Use\Lipe\Lib\Query\Query_Args
Some classes remain but have slightly to massively changed signatures. Existing code may be affected by the changes. This only applies to classes which are accessed directly. You may see some PHP fatal errors related to these classes which should be easy to locate and mitigate. The best approach to migrating is to use PHPStan to detect missing properties or methods and look for similar elements on the same class.
\Lipe\Lib\Taxonomy\Taxonomy
\Lipe\Lib\Post_Type\Custom_Post_Type
\Lipe\Lib\CMB2\Group
\Lipe\Lib\Api\Route
\Lipe\Lib\Api\Zip
\Lipe\Lib\Query\Args_Interface
\Lipe\Lib\CMB2\Field
\Lipe\Lib\CMB2\Group
Some methods have been removed with an alternative avaiable.
-
\Lipe\Lib\Theme\Resources::defer_javascript
-> Usewp_script_add_data( $handle, 'strategy', 'defer' );
-
\Lipe\Lib\Theme\Resources::async_javascript
-> Usewp_script_add_data( $handle, 'strategy', 'async' );
The \Lipe\Lib\Schema
namespace contained classes which were a throwback to a time before PHP provided the necessary tools to implement strict composition and type validation. Even the name "Schema" is confusing because since it was created JSON schema has become the standard when using the "Schema" terminology.
Each class in this namespace as been removed with a similar class using the a composition pattern has taken its place. If you are heavily using a class from "Schema" it may be easier to move the class from version 4.9.0 into your project. Otherwise the @deprecated
or _deprecated_class
will point you to the new class.
The Db class has been converted from abstract to composition. The general looseness of the class has been converted to strict, static analyzable values. For projects verbosely using this class is may be easier to copy the class from version 4.9.* into your project as a refactor will be intensive.
For most accurate refactoring, pass the available generics and let PHPStan be your guide. The new Custom_Table
class supports full static analysis, so phpstan reports will help tremendously.
- Tables now require the
\Lipe\Lib\Db\Table
interface. - Class constants are no longer honored.
- 3 new generics have been introduced on the Table interface.
-
FORMATS
used for both the interface andCustom_Table
class. -
COLUMNS
mimic what theCOLUMNS
class constant used to be. -
PARTIALS
can by\Partial<COLUMNS>
. Required due to limitations with phpstan and utility types.
-
- The
$columns
parameter is no longer available in any methods exceptget_select_query
. -
get_*
methods now return a single type of result instead of changing via$count
and$columns
. - The
$where
parameter now only accepts anarray
. - The result of
get_*
methods is not an associative array instead of an object or array of objects. -
create_table
is no longer called automatically and must be managed within your project. - Returned values from
get_*
are now formatted to match the result of theget_column_formats
formats instead ofstring
for everything.
The Custom_Table
class uses composition so you may create a method in your own class to return a custom column. Here is an example method which returns a single column from results and remains static analyzable.
/**
* @phpstan-type COLUMNS array{
* ID: int,
* ip: string,
* count: int,
* date: string
* }
* @phpstan-type FORMATS array{
* ID: "%d",
* ip: "%s",
* count: "%d",
* date: "%s"
* }
*
* @implements Table<FORMATS, COLUMNS, \Partial<COLUMNS>>
*/
class Db implements Table {
/**
* @phpstan-param \Partial<COLUMNS> $wheres
* @return string[]
*/
public function get_branch( array $wheres, ?int $count = null ): array {
global $wpdb;
$query = $this->db()->get_select_query( [ 'branch' ], $wheres, $count );
return $wpdb->get_col( $query, 'ARRAY_A' );
}
/**
* @phpstan-return Custom_Table<Db>
*/
private function db(): Custom_Table {
return Custom_Table::factory( $this );
}
}