我无法将is_admin控件添加到插件

时间:2020-01-13 作者:Faruk rıza

我想在管理页面上隐藏我的插件,因为它与此冲突。然而,当İ添加控件时,wp表示存在严重错误。

İ要添加此控件:

if ( ! is_admin() ) {
    // Runs only if this PHP code is in a file that displays outside the admin panels, like the theme template.
    echo \'<div style="text-align: center">Welcome to our website.</div>\';
} else {
    // Runs only if this code is in a file that displays inside the admin panels, like a plugin file.
    Return;
}
统计欢迎使用的文本代码。。必须使用topauthor函数进行更改。İ做了,但它会导致严重错误。我该怎么做?

以下是编辑前的完整代码:

<?php
/*
Plugin Name: Site Plugin for example.com
Description: Site specific code changes for example.com
*/
/* Start Adding Functions Below this Line */

/* Stop Adding Functions Below this Line */

// Register and load the widget
function wpb_load_widget() {
    register_widget( \'wpb_widget\' );
}
add_action( \'widgets_init\', \'wpb_load_widget\' );

// Creating the widget
class wpb_widget extends WP_Widget {

    function __construct() {
        parent::__construct(

        // Base ID of your widget
            \'wpb_widget\',

            // Widget name will appear in UI
            __(\'WPBeginner Widget\', \'wpb_widget_domain\'),

            // Widget description
            array( \'description\' => __( \'Sample widget based on WPBeginner Tutorial\', \'wpb_widget_domain\' ), )
        );
    }

    // Creating widget front-end
    public function widget( $args, $instance ) {
        $title = apply_filters( \'widget_title\', $instance[\'title\'] );

        // before and after widget arguments are defined by themes
        echo $args[\'before_widget\'];
        if ( ! empty( $title ) )
            echo $args[\'before_title\'] . $title . $args[\'after_title\'];

        // This is where you run the code and display the output
        echo __( \'Hello, World!\', \'wpb_widget_domain\' );
        echo $args[\'after_widget\'];
    }

    // Widget Backend
    public function form( $instance ) {
        if ( isset( $instance[ \'title\' ] ) ) {
            $title = $instance[ \'title\' ];
        }
        else {
            $title = __( \'New title\', \'wpb_widget_domain\' );
        }
        // Widget admin form
        ?>
        <p>
            <label for="<?php echo $this->get_field_id( \'title\' ); ?>"><?php _e( \'Title:\' ); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id( \'title\' ); ?>" name="<?php echo $this->get_field_name( \'title\' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
        </p>
        <?php
    }

    // Updating widget replacing old instances with new
    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance[\'title\'] = ( ! empty( $new_instance[\'title\'] ) ) ? strip_tags( $new_instance[\'title\'] ) : \'\';
        return $instance;
    }
} // Class wpb_widget ends here
//eklediğim kod

add_action(\'wp_default_scripts\', function ($scripts) {
    if (!empty($scripts->registered[\'jquery\'])) {
        $scripts->registered[\'jquery\']->deps = array_diff($scripts->registered[\'jquery\']->deps, [\'jquery-migrate\']);
    }
});

//add_action(\'init\',\'do_stuff\');
add_action(\'wp_loaded\',\'do_stuff\');
function do_stuff()
{
    TopAuthor();
}

function TopAuthor() {
    $contributor_ids = get_users( array(
        \'fields\'  => \'ID\',
        \'orderby\' => \'post_count\',
        \'order\'   => \'DESC\',
        \'who\'     => \'authors\',
    ) );

    foreach ( $contributor_ids as $contributor_id ) :
        $post_count = count_user_posts( $contributor_id );
        // Move on if user has not published a post (yet).
        if ( ! $post_count ) {
            continue;
        }
        ?>
        <div class="contributor">
            <div class="contributor-info">
                <div class="contributor-avatar"><?php echo get_avatar( $contributor_id, 132 ); ?></div>
                <div class="contributor-summary">
                    <h2 class="contributor-name"><?php echo get_the_author_meta( \'display_name\', $contributor_id ); ?></h2>
                    <p class="contributor-bio">
                        <?php echo get_the_author_meta( \'description\', $contributor_id ); ?>
                    </p>
                    <a class="button contributor-posts-link" href="<?php echo esc_url( get_author_posts_url( $contributor_id ) ); ?>">
                        <?php printf( _n( \'%d Article\', \'%d Articles\', $post_count, \'twentyfourteen\' ), $post_count ); ?>
                    </a>
                </div><!-- .contributor-summary -->
            </div><!-- .contributor-info -->
        </div><!-- .contributor -->

    <?php
    endforeach;
}
?>
İ我在手机上写作,请编辑我的英语语法。谢谢

1 个回复
最合适的回答,由SO网友:demopix 整理而成

好吧,我想你只是在TopAuthor内部做了一切

add_action( \'admin_menu\', \'TopAuthor\' );

相关推荐

阻止/wp-admin/重定向到主页?

我已将wordpress实例从生产复制到本地。在获取站点的公共端(公共主页、页面和博客帖子)后,我无法访问/wp admin/,因为该url总是重定向到/homepage。我尝试过:更新siteurl和主页至“https://tk.local“(主页和帖子工作正常)实现本地自签名ssl证书(如果是https问题。)</切换到2019主题(主题可行,但问题仍然存在)在wp配置中设置调试常量。php删除wp配置中的调试常量。php将插件目录移到一边,替换为只包含索引的/插件。php这里是一个wp adm