0

我想在管理面板中嵌入具有固定宽度的图像或 div 标签,以设置最小宽度。像这样的东西,

<div style="width:1000px; height:0px; border:0px;"></div>

我找不到合适的钩子。此页面http://codex.wordpress.org/Plugin_API/Action_Reference列出了可用的钩子,我尝试了其中的一些,包括wp_before_admin_bar_render, wp_after_admin_bar_render。但是嵌入图像为时已晚,因为#wpcontent已经加载和渲染。我也尝试过admin_head,但嵌入图像还为时过早;宽度没有任何影响。我需要将图像放在#wpcontent 的 div 元素之前。我猜是在渲染左侧菜单之后。

可能吗?

直接在样式表中为 #wpcontent 指定宽度在不同的 WordPress 版本中并不成功。所以我正在寻找替代品。感谢您的信息。

4

2 回答 2

3

你试过这个吗?

add_action('in_admin_header');

或者这些……

add_action('network_admin_notices');
add_action('user_admin_notices');
add_action('admin_notices');
add_action('all_admin_notices');

但我更喜欢第一个,因为其他的都是留作通知的。

于 2012-10-09T15:03:57.760 回答
0

It seems the problem was not the timing of when it is inserted but the style of the div tag. Since the purpose of this is to create a minimum width in the admin panel, the border:0px does not create a solid element. Therefore, the browser seems to ignore it.

Inserting this worked.

<div id="min-width" style="width:1000px; height:0px; border:1px; border-style:solid; border-color: rgba(0,0,0,0);"></div>

This is the sample plugin which demonstrates how to do it.

<?php
    /* Plugin Name: Sample Embed Image for Admin Page Width  */

    add_action('plugins_loaded', create_function('', 
        '$o = new AdminPageClass_EmbedImage("Sample Embed Image in Admin Panel"
                , "Sample Embed Image in Admin Panel"
                , "manage_options"
                , "sample_embed_image_in_admin_panel");
        '));

    class AdminPageClass_EmbedImage {

        function __construct($title, $menuname, $privilege, $pageslug) {
            $this->title = $title;
            $this->menuname = $menuname;
            $this->privilege = $privilege;
            $this->pageslug = $pageslug;
            add_action('admin_menu', array(&$this, 'admin_menu'));  
            add_action('wp_before_admin_bar_render', array(&$this, 'embed_image')); // inserts it between #wpcontent and #wpadminbar
            // add_action('in_admin_header', array(&$this, 'embed_image')); // inserts it between #wpadminbar and #wp-body which is after #wpcontent
            // add_action('network_admin_notices', array(&$this, 'embed_image')); // no insertion
            // add_action('user_admin_notices', array(&$this, 'embed_image')); // no insertion
            // add_action('admin_notices', array(&$this, 'embed_image')); // inserts it after #screen-meta inside #wpbody-content which is inside #wp-content
            // add_action('all_admin_notices', array(&$this, 'embed_image')); // same as 'admin_notices'
        }
        function admin_menu() {
            add_options_page($this->title, $this->menuname, $this->privilege, $this->pageslug, array(&$this, 'admin_page'));
        }
        function embed_image() {
            ?>
            <div id="min-width" style="width:1000px; height:0px; border:1px; border-style:solid; border-color: rgba(0,0,0,0);"></div>
            <?
        }
        function admin_page() {
            // $this->embed_image();
            ?>
            <div class="wrap">
                <h1>Hi there</h1>
                <?php // $this->embed_image(); ?>
                <p>Hello World!</p>
            </div>
            <?php
        }
    }
于 2012-10-10T05:58:14.763 回答