getolympus / olympus-code-field
v0.0.14
2023-12-20 22:09 UTC
Requires (Dev)
- phpunit/phpunit: ~5.3
README
Dionysos 代码字段
该组件是针对 WordPress 的 Olympus Dionysos 字段 的一部分。
它使用与 codemirror JS 组件完全集成的默认 WordPress 代码字段。
composer require getolympus/olympus-dionysos-field-code
目录
字段初始化 • 变量定义 • 接受模式 • 检索数据 • 发布历史 • 贡献
字段初始化
使用以下行在您的 WordPress 管理页面或自定义帖子类型元字段中添加 代码字段
return \GetOlympus\Dionysos\Field\Code::build('my_code_field_id', [ 'title' => 'How do Penguins code their icebergs?', 'default' => 'With a frozen bug.', 'description' => 'A simple question to let you know how to seduce a penguin.', 'mode' => 'json', 'rows' => 4, /** * Code mirror settings * @see https://developer.wordpress.org/reference/functions/wp_get_code_editor_settings/ */ 'settings' => [ 'indentUnit' => 2, 'indentWithTabs' => false, 'tabSize' => 2, ], ]);
变量定义
变量 | 类型 | 未设置时的默认值 | 接受值 |
---|---|---|---|
title |
字符串 | 'Code' |
empty |
default |
字符串 | empty | empty |
description |
字符串 | empty | empty |
mode |
字符串 | text/html |
见 接受模式 |
rows |
整数 | 4 |
> 1 |
settings |
数组 | 见 字段初始化 | 见 WordPress 参考 |
接受模式
text/css
或css
text/x-diff
或x-diff
或diff
text/html
或html
text/javascript
或javascript
或js
application/json
或json
text/x-markdown
或markdown
或md
application/x-httpd-php
或x-httpd-php
或php
text/x-python
或x-python
或python
text/x-ruby
或x-ruby
或ruby
text/x-sh
或x-sh
或sh
text/x-mysql
或x-mysql
或mysql
text/x-mariadb
或x-mariadb
或mariadb
application/xml
或xml
text/x-yaml
或x-yaml
或yaml
使用示例
正确填写表单(在此示例中使用 JSON)
{ "response": "With a frozen bug." }
检索数据
使用简单的 get_option('my_code_field_id', '')
从数据库中检索您的值(见 WordPress 参考文档)
// Get code from Database $code = get_option('my_code_field_id', ''); // Display code in HTML tag echo '<pre>'.htmlspecialchars($code).'</pre>';
发布历史
版本 | 备注 |
---|---|
0.0.14 | 修复 domReady 上的 jQuery 集成 |
0.0.13 | 添加新的 CodeMirror CSS 以实现小部件集成 |
0.0.12 | 新增与 Olympus 组件的兼容性 将存储库更改为 Dionysos 字段的一部分 |
贡献
- 将其分支(https://github.com/GetOlympus/olympus-dionysos-field-code/fork)
- 创建您的功能分支(
git checkout -b feature/fooBar
) - 提交您的更改(
git commit -am '添加一些 fooBar'
) - 将分支推送到远程(
git push origin feature/fooBar
) - 创建新的拉取请求
由 Achraf Chouk 用爱心打造 ~ (c)长时间以来。