[英]Add custom buttons with custom actions in Edit Post screen in WordPress?
[英]Wordpress: How to add buttons to post edit view
關於如何在WSYWIG編輯器上自定義TinyMCE面板的教程有上百萬,但這不是我想要做的。
我想在帖子編輯視圖中添加一個獨立按鈕,該按鈕將進行API調用並自動填充頁面上的某些字段。 到目前為止,我最接近的是鈎子simple_edit_form
和advanced_edit_form
,這兩個鈎子都允許我在編輯表單的最底部添加內容。 最好將其添加到頂部的“添加媒體”按鈕所在的位置。
這可能嗎?
有一個稱為媒體按鈕的操作。 以下是基本示例。 我從插件重力形式中獲取了此示例,並對其進行了一些改動。 祝好運。
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.