這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

ACF WYSIWYG Styling

描述

A very tiny plugin that adds the ACF field key, field name, Flexible Content field name and Flexible Content layout name to the WYSIWYG
editor body tag, allowing you to target these classes, along with the existing post-type-* classes added by default by WordPress, in
your editor-style.css for a better admin/editor experience.

This works for both ACF and ACF Pro, version 5.

Usage

  1. Install the plugin through the Install Plugins interface or by uploading the acf-plugin-wysiwyg-styling folder to your /wp-content/plugins/ directory.
  2. Activate the ACF WYSIWYG Styling plugin from the Admin > Plugins menu.
  3. Create or edit your editor-style.css in your theme directory and use the newly added classes to style your WYSIWYG editors.

For example:

  • The ACF WYSIWYG field with key field_9999ffff11112222 can be targeted with the following CSS:

    body.acf-field-key-field_9999ffff11112222 {
    background-color: red;
    }

  • The ACF WYSIWYG field with key field_9999ffff11112222 in the “room” post type can be targeted with the following CSS:

    body.post-type-room.acf-field-key-field_9999ffff11112222 {
    background-color: blue;
    }

  • All ACF WYSIWYG fields named “my_wysiwyg” can be targetted with the following CSS:

    body.acf-field-name-my_wysiwyg {
    background-color: yellow;
    }

  • All ACF WYSIWYG fields in the Flexible Content field named “page_content” can be targetted with the following CSS:

    body.acf-flex-name-page_content {
    color: green;
    }

  • All ACF WYSIWYG fields in the Flexible Content layout field named “test_layout” can be targetted with the following CSS:

    body.acf-layout-test_layout {
    font-family: “Computer Modern Serif”;
    }

  • The ACF WYSIWYG field named “my_wysiwyg” in the Flexible Content layout field named “test_layout” can be targetted with the following CSS:

    body.acf-layout-test_layout.acf-field-name-my_wysiwyg {
    border: 4px solid red;
    height: 100%;
    margin: 0 auto;
    max-width: 100px;
    }

N.B. I target using the body tag so that a user cannot accidentally target the admin CSS in their edit of the field (regardless of how unlikely
that would be).

安裝

  1. Install the plugin through the Install Plugins interface or by uploading the acf-plugin-wysiwyg-styling folder to your /wp-content/plugins/ directory.
  2. Activate the ACF WYSIWYG Styling plugin from the Admin > Plugins menu.

常見問題

Do I need to install a plugin to do this?

Not at all. For the time being ACF doesn’t add these classes to the editor, but you can do it either by installing this plugin or by placing the
following code in your functions.php file:

function acf_plugin_wysiwyg_styling() { ?>
    <script>
        (function($) {
            acf.add_filter('wysiwyg_tinymce_settings', function(mceInit, id) {
                var mceInitElements = $('#' + mceInit.elements);
                var acfEditorField = mceInitElements.closest('.acf-field[data-type="wysiwyg"]');
                var fieldKey = acfEditorField.data('key');
                var fieldName = acfEditorField.data('name');
                var flexContentName = mceInitElements.parents('[data-type="flexible_content"]').first().data('name');
                var layoutName = mceInitElements.parents('[data-layout]').first().data('layout');
                mceInit.body_class += " acf-field-key-" + fieldKey;
                mceInit.body_class += " acf-field-name-" + fieldName;
                if (flexContentName) {
                    mceInit.body_class += " acf-flex-name-" + flexContentName;
                }
                if (layoutName) {
                    mceInit.body_class += " acf-layout-" + layoutName;
                }
                return mceInit;
            });
        })(jQuery);
    </script>
<?php
}
add_action('acf/input/admin_footer', 'acf_plugin_wysiwyg_styling');
Can I change the prefix of the classes added to the editor?

Not with this plugin. The prefixes are hard-coded to acf-field-key-, acf-field-name-, acf-flex-name- and acf-layout-. If you wish to change
these prefixes, I would suggest not using this plugin and using the code shown above in your functions.php, changing the desired prefixes
in the code.

Will you be adding any features?

I doubt it. Hopefully the developers of ACF provide this functionality in an upcoming version themselves, since it is quite simple and really should
be part of the core function. At that time, this plugin will become redundant. I look forward to that date 🙂

There is a feature that i want it implemented, can you do something about it?

Again, this is a plugin to provide very basic functionality that allows for complete targetting of WYSIWYG editors within the ACF framework. I don’t
plan on adding any functionality to the plugin. But the code is released under GPLv2, so go at it yourself if you so desire!

評價

There are no reviews for this plugin.

貢獻者及開發者

“ACF WYSIWYG Styling” 是一個開源的軟體。以下的人對這個外掛作出了貢獻。

貢獻者

將 ACF WYSIWYG Styling 外掛本地化為台灣繁體中文版。

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

修改日誌

1.0

  • Initial Release