dxw / wordpress-setup
自动配置WordPress的助手
v0.1.1
2024-09-18 13:14 UTC
Requires
- fakerphp/faker: ^1.23
- wp-cli/wp-cli-bundle: ^2.6
Requires (Dev)
- dxw/php-cs-fixer-config: ^2.1
- kahlan/kahlan: ^5.2
This package is auto-updated.
Last update: 2024-09-18 13:16:18 UTC
README
一个用于配置WordPress并填充内容的包,使其处于已知可测试或可开发状态。
使用方法
使用Composer安装
composer require-dev dxw/wordpress-setup
调用Factory以获取新的Setup实例,例如:
$setup = Dxw\WordPressSetup\Factory::create();
然后调用setup的特定模块作为属性,例如创建帖子:
$setup->post->create();
或创建菜单并将其分配给主题中的菜单位置:
$setup->menu->createAndAssignLocation('menu-name', 'menu-location');
模块及其可用方法在下面详细说明。
模块
媒体
upload
将文件上传到媒体库,并创建适当的附件元数据。
接受文件的路径或URL
$setup->media->upload(string $pathOrUrlToFile);
返回创建的附件的ID。
菜单
addCustomLink
将自定义链接项添加到菜单中,第一个参数是要分配到的菜单ID
$setup->menu->addCustomLink(int $menuId, string $menuItemTitle, string $menuItemUrl);
也可以传递作为最终参数的菜单项ID,这是其子项
$setup->menu->addCustomLink(int $menuId, string $menuItemTitle, string $menuItemUrl, int $parentMenuItemId);
返回已创建的菜单项ID。
addTaxonomyLink
将分类存档链接添加到菜单中。
$setup->menu->addTaxonomyLink(int $menuId, int $termid, int $taxonomyName)
也可以可选地传递作为其子项的菜单项ID
$setup->menu->addTaxonomyLink(int $menuId, int $termid, int $taxonomyName, int $parentMenuItemId)
返回已创建的菜单项ID。
createAndAssignLocation
创建一个新的菜单并通过名称将其分配给主题位置
$setup->menu->createAndAssignLocation(string $menuName, string $menuLocation);
返回新菜单的ID。
插件
activate
通过slug激活插件
$setup->plugin->activate(string $pluginSlug)
帖子
create
创建一个新的帖子
$setup->post->create();
默认情况下,将使用Faker生成假标题和内容,帖子类型将是post
,帖子状态将是publish
。
您可以使用与传递给wp_insert_post
相同的参数数组覆盖任何这些默认值(或添加附加参数)。
返回新帖子的ID。