getolympus/olympus-dionysos-field-code

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

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

This package is auto-updated.

Last update: 2024-09-20 23:39:02 UTC


README

狄俄尼索斯代码字段

Olympus Component CodeFactor Grade Packagist Version MIT

该组件是针对WordPress的Olympus Dionysos字段的一部分。
它使用默认的WordPress代码字段,与codemirror JS组件完全集成。

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,
    ],
]);

变量定义

接受模式

  • 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>';

发布历史

贡献

  1. 分支它 (https://github.com/GetOlympus/olympus-dionysos-field-code/fork)
  2. 创建您的功能分支 (git checkout -b feature/fooBar)
  3. 提交您的更改 (git commit -am 'Add some fooBar')
  4. 将更改推送到分支 (git push origin feature/fooBar)
  5. 创建新的Pull Request

由Achraf Chouk构建于GitHub https://github.com/crewstyle ~ (c) 很久以来。