0

嗨,我仍然习惯于在 wordpress 中使用操作。我只是想知道我想要什么。

我想echo在不触及代码的情况下删除生成下面某些表单的 s。我看到do_action他们之前和之后都有。但我想知道它们对我做我想做的事有什么用处,如果是的话,如何影响do_actions 之间的内容。

例如,只是说我想删除

            echo "
        <p>
            <label for='log'>".__( 'Username', 'jigoshop' )."</label>
            <input type='text' name='log' id='log' class='input-text username' />
        </p>
        ";

从...

do_action( 'jigoshop_widget_login_before_form' );

        // Get redirect URI
        $redirect_to = apply_filters( 'jigoshop_widget_login_redirect', get_permalink( jigoshop_get_page_id('myaccount') ) );
        $user_login = isset( $user_login ) ? $user_login : null;

        echo "<form action='".esc_url(wp_login_url( $redirect_to ))."' method='post' class='jigoshop_login_widget'>";

        // Username
        echo "
        <p>
            <label for='log'>".__( 'Username', 'jigoshop' )."</label>
            <input type='text' name='log' id='log' class='input-text username' />
        </p>
        ";

        // Password
        echo "
        <p>
            <label for='pwd'>".__( 'Password', 'jigoshop' )."</label>
            <input type='password' name='pwd' id='pwd' class='input-text password' />
        </p>
        ";

        echo "
        <p>
            <input type='submit' name='submit' value='".__( 'Login', 'jigoshop' )."' class='input-submit' />
            <a class='forgot' href='".esc_url(wp_lostpassword_url( $redirect_to ))."'>".__( 'Forgot it?', 'jigoshop' )."</a>
        </p>
        ";

        if (Jigoshop_Base::get_options()->get_option( 'jigoshop_enable_signup_form' ) == 'yes' ) {
            echo '<p class="register">';
            wp_register(__('New user?','jigoshop') . ' ' , '');
            echo '</p>';
        }

        echo "</form>";

        do_action( 'jigoshop_widget_login_after_form' );

        $links = apply_filters( 'jigoshop_widget_login_user_links', array() );
4

1 回答 1

0

do_action()不幸的是,在上述场景中使用or并没有真正的“干净”方式来实现这一点remove_action()。该do_action()函数完全按照听起来的方式执行;它标记了发生特定操作的特定点,然后您可以将不同的功能挂钩/取消挂钩。您可以在表单之前和之后运行函数,但在表单内没有运行任何操作,这限制了您的选择。

实际上对您更有用的是filter,因为它可以让您实际影响对变量/内容的更改。唉,在回显这些特定字段之前似乎没有应用过滤器,所以你又不走运了。

在我看来,您唯一实用的选择是使用 CSS/JS 隐藏该字段,或者派生一个小部件的副本并根据需要进行更改:将user_login.php文件复制到您的插件文件夹,重命名类名,使其不冲突与现有课程。然后注册并加载小部件:

class My_Custom_Widget_User_Login extends WP_Widget
{ 
     /**
     * Constructor
     * Setup the widget with the available options
     * Add actions to clear the cache whenever a post is saved|deleted or a theme is switched
     */
    public function __construct()
    {
        $options = array(
            'classname' => 'widget_user_login',
            'description' => __('Displays a handy login form for users', 'jigoshop')
        );
        // Ensure you also change the base ID of you widget
        parent::__construct('custom-user-login', __('Jigoshop: Login', 'jigoshop'), $options);
    }
    // Rest of class definition here; edit as you wish
} // End class

// Register and load the widget
function my_load_widget() {
    register_widget( 'custom-user-login' );
}
add_action( 'widgets_init', 'my_load_widget' );

这应该为您提供一个您可以根据需要调整的小部件副本,与 Jigoshop 插件的其余部分分开,因此它不会受到更新的直接影响。我还没有机会测试它,但希望它能让你走上正轨。

于 2015-05-07T19:57:05.623 回答