alleyinteractive/wp-theme-migrator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alleyinteractive/wp-theme-migrator

Composer 安装命令:

composer require alleyinteractive/wp-theme-migrator

包简介

A library to migrate to a new WordPress theme incrementally.

README 文档

README

Coding Standards Testing Suite

A library to support agile, incremental theme migrations in WordPress.

Background

This library facilitates an incremental approach to migrating a WordPress site to a new theme.

The conventional strategy for re-theming a site is to build an entire theme, then activate the new theme on the production environment when it's complete. This library enables you to use a Strangler Fig pattern to move gradually from an old theme to a new theme, with both themes installed on the production environment.

The parameters of the migration strategy are passed via callbacks to the Migrator during initialization. The Migrator parses the current request early and passes the query vars to each callback so you can base the migration strategy on post type, taxonomy, publish date, language, post meta or any public query var that is added before the Migrator is run.

Furthermore, you can define your migration strategy on more than just what's available in the query. The Migrator is agnostic – it only needs to know whether the current request should be migrated to the new theme. So your strategy can draw on globals, constants, an API integration, the day of the week – or any value that's available when the Migrator is run – to determine migratability.

With thoughtfully structured callbacks, you can even A/B test redesigned pages during development. Individual content types can be built, tested, and released before the theme is complete, bringing a truly iterative cycle to your workflow.

Releases

This package follows semantic versioning conventions.

Roadmap

This package is in a pre-release status. Milestones to be completed before the first release include:

  • Adding feature testing.

Install

Requires Composer and PHP >= 8.0.

Use

Install a new valid theme. To be valid, it must exist in the /wp-content/themes/ directory, be compatible with the local WordPress and PHP versions, and include at least a style.css file. Do not activate the new theme.

Install this package via Composer.

composer require alleyinteractive/wp-theme-migrator

Ensure that the Composer autoloader is loaded into your project.

require_once __DIR__ . '/vendor/autoload.php';

Initialize the Migrator in your project. The Migrator performs its magic on the setup_theme hook so it must be initialized before that. Here, the Migrator object is created on the plugins_loaded hook:

/**
* Initialize WP Theme Migrator early.
*/
function init_migrator() {
	try {
		$migrator = new \Alley\WP\Theme_Migrator\Migrator();
		$migrator->init();
	} catch( Exception  $e ) {
		// Do something. The Migrator will throw an Exception when it's
		// initialized with an invalid theme or callback. Be sure to catch
		// the Exception to fatal errors.
	}
}
add_action( 'plugins_loaded', 'init_migrator' );

Pass the name of the new theme and a list of one or more callbacks to the Migrator through filters. A callback must return true if a given request should be handled with the new theme. If more than one callback is provided, the Migrator will call each one once until one returns true. Then, the Migrator will load the new theme and no more callbacks will be called on that request. If none of the provided callbacks return true, the old theme will be loaded.

/**
 * Pass the new theme to WP Theme Migrator.
 */
add_filter( 'wp_theme_migrator_theme', fn() => 'new-theme-slug' );

/**
* Add callbacks for WP Theme Migrator to determine migratability.
*
* @param callable[] $callbacks Array of callbacks.
* @param Migrator   $migrator Migrator instance.
*/
function filter_wp_theme_migrator_callbacks( $context, $migrator) {
	return [
		'a_callback', // This can be any callable.
		'another_callback',
	];
}
add_filter( 'wp_theme_migrator_callbacks', 'filter_wp_theme_migrator_callbacks', 10, 2 );

Define your migration strategy through your callbacks.

/**
* Callback to manage theme migration.
*
* @param array $query_vars Array of query vars for the current request.
* @return bool Whether to load the new theme.
*/
function a_callback( $query_vars ): bool {
	// Do something to decide if the current request is migratable.
}

Once you've migrated the entire site, activate your new theme, remove this package from your project, and uninstall your old theme.

From Source

To work on this project locally, first add the repository to your project's composer.json:

{
	"repositories": [
		{
			"type": "path",
			"url": "../path/to/wp-theme-migrator",
			"options": {
				"symlink": true
			}
		}
	]
}

Next, add the local development files to the require section of composer.json:

{
	"require": {
		"alleyinteractive/wp-theme-migrator": "@dev"
	}
}

Finally, update composer to use the local copy of the package:

composer update alleyinteractive/wp-theme-migrator --prefer-source

Changelog

This project keeps a changelog.

Development Process

See instructions above on installing from source. Pull requests are welcome from the community and will be considered for inclusion. Releases follow semantic versioning and are shipped on an as-needed basis.

Contributing

See our contributor guidelines for instructions on how to contribute to this open source project.

Project Structure

This is a Composer package that is published to Packagist. Classes are autoloadable using alleyinteractive/composer-wordpress-autoloader. They live in the src directory and follow standard WordPress naming conventions for classes.

Third-Party Dependencies

Dependencies are managed by Composer, and include:

  • alleyinteractive/composer-wordpress-autoloader: Used for autoloading classes that follow the standard WordPress conventions for filenames.
  • alleyinteractive/alley-coding-standards: Used for running phpcs linting.
  • mantle-framework/testkit: Used for running unit tests.
  • symfony/filesystem: Used for copying files into the WordPress test installation for testing.

Maintainers

Alley logo

Contributors

Thanks to all of the contributors to this project.

License

This project is licensed under the GNU Public License (GPL) version 2 or later.

alleyinteractive/wp-theme-migrator 适用场景与选型建议

alleyinteractive/wp-theme-migrator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.37k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「alleyinteractive」 「wp-theme-migrator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alleyinteractive/wp-theme-migrator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alleyinteractive/wp-theme-migrator 我们能提供哪些服务?
定制开发 / 二次开发

基于 alleyinteractive/wp-theme-migrator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 22
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-04-12