简体   繁体   English

WordPress:如何添加按钮以发布编辑视图

[英]Wordpress: How to add buttons to post edit view

There's a million tutorials for how to customize the TinyMCE panel on the WSYWIG editor... but that's not what I want to do. 关于如何在WSYWIG编辑器上自定义TinyMCE面板的教程有上百万,但这不是我想要做的。

I want to add a stand-alone button to the post edit view that will make an API call and auto-fill certain fields on the page. 我想在帖子编辑视图中添加一个独立按钮,该按钮将进行API调用并自动填充页面上的某些字段。 I closest I've come so far are the hooks simple_edit_form and advanced_edit_form which both allow me to add content to the very bottom of the edit form. 到目前为止,我最接近的是钩子simple_edit_formadvanced_edit_form ,这两个钩子都允许我在编辑表单的最底部添加内容。 It'd be much better to add it at the top, where the "add media" button lives. 最好将其添加到顶部的“添加媒体”按钮所在的位置。

Is this possible? 这可能吗?

There is an action called media buttons. 有一个称为媒体按钮的操作。 Below is basic example. 以下是基本示例。 I've take this example from the plugin gravity forms and changed it little. 我从插件重力形式中获取了此示例,并对其进行了一些改动。 Good luck. 祝好运。

add_action( 'media_buttons', 'add_form_button' );

function add_form_button(){
        $is_post_edit_page = in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'));
        if(!$is_post_edit_page)
            return;

        // do a version check for the new 3.5 UI
        $version    = get_bloginfo('version');

        if ($version < 3.5) {
            // show button for v 3.4 and below
            $image_btn = GFCommon::get_base_url() . "/images/form-button.png";
            echo '<a href="#TB_inline?width=480&inlineId=select_gravity_form" class="thickbox" id="add_gform" title="' . __("Add Gravity Form", 'gravityforms') . '"><img src="'.$image_btn.'" alt="' . __("Add Gravity Form", 'gravityform') . '" /></a>';
        } else {
            // display button matching new UI
            echo '<style>.gform_media_icon{
                    background:url(' . GFCommon::get_base_url() . '/images/gravity-admin-icon.png) no-repeat top left;
                    display: inline-block;
                    height: 16px;
                    margin: 0 2px 0 0;
                    vertical-align: text-top;
                    width: 16px;
                    }
                    .wp-core-ui a.gform_media_link{
                     padding-left: 0.4em;
                    }
                 </style>
                  <a href="#TB_inline?width=480&inlineId=select_gravity_form" class="thickbox button gform_media_link" id="add_gform" title="' . __("Add Gravity Form", 'gravityforms') . '"><span class="gform_media_icon "></span> ' . __("Add Form", "gravityforms") . '</a>';
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM