getolympus/olympus-code-field

此软件包已被放弃,不再维护。作者建议使用 getolympus/olympus-dionysos-field-code 软件包。

代码字段,该组件是 Olympus Dionysos 字段的一部分。

v0.0.14 2023-12-20 22:09 UTC

This package is auto-updated.

Last update: 2023-12-20 22:11:59 UTC


README

field-code.png

Dionysos 代码字段

Olympus Component CodeFactor Grade Packagist Version MIT

该组件是针对 WordPressOlympus 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/csscss
  • text/x-diffx-diffdiff
  • text/htmlhtml
  • text/javascriptjavascriptjs
  • application/jsonjson
  • text/x-markdownmarkdownmd
  • application/x-httpd-phpx-httpd-phpphp
  • text/x-pythonx-pythonpython
  • text/x-rubyx-rubyruby
  • text/x-shx-shsh
  • text/x-mysqlx-mysqlmysql
  • text/x-mariadbx-mariadbmariadb
  • application/xmlxml
  • text/x-yamlx-yamlyaml

使用示例

正确填写表单(在此示例中使用 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 字段的一部分

贡献

  1. 将其分支(https://github.com/GetOlympus/olympus-dionysos-field-code/fork
  2. 创建您的功能分支(git checkout -b feature/fooBar
  3. 提交您的更改(git commit -am '添加一些 fooBar'
  4. 将分支推送到远程(git push origin feature/fooBar
  5. 创建新的拉取请求

Achraf Chouk 用爱心打造 ~ (c)长时间以来。