उपयोगकर्ता प्रोफ़ाइल व्यवस्थापक पृष्ठ से जीवनी कैसे निकालें


14

मैं प्रोफाइल पेज से जीवनी इनपुट फ़ील्ड को निकालना या छिपाना चाहूंगा। आप यह कैसे करते हैं? मैंने पहले ही इस पृष्ठ से कुछ संपर्क विधियाँ हटा दी हैं, लेकिन मुझे यकीन नहीं है कि जीवनी से छुटकारा कैसे मिलेगा।

जवाबों:


21

कोई समर्पित हुक नहीं है - वर्डप्रेस में उपयोगकर्ता प्रबंधन एक कम प्राथमिकता है। आपको आउटपुट बफ़रिंग का उपयोग करना होगा (हाँ, अच्छा नहीं)।

यहाँ एक सरल प्रदर्शन है कि यह कैसे किया जा सकता है:

add_action( 'personal_options', array ( 'T5_Hide_Profile_Bio_Box', 'start' ) );

/**
 * Captures the part with the biobox in an output buffer and removes it.
 *
 * @author Thomas Scholz, <info@toscho.de>
 *
 */
class T5_Hide_Profile_Bio_Box
{
    /**
     * Called on 'personal_options'.
     *
     * @return void
     */
    public static function start()
    {
        $action = ( IS_PROFILE_PAGE ? 'show' : 'edit' ) . '_user_profile';
        add_action( $action, array ( __CLASS__, 'stop' ) );
        ob_start();
    }

    /**
     * Strips the bio box from the buffered content.
     *
     * @return void
     */
    public static function stop()
    {
        $html = ob_get_contents();
        ob_end_clean();

        // remove the headline
        $headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' );
        $html = str_replace( '<h2>' . $headline . '</h2>', '', $html );

        // remove the table row
        $html = preg_replace( '~<tr>\s*<th><label for="description".*</tr>~imsUu', '', $html );
        print $html;
    }
}

आप कोड को एक स्टैंडअलोन प्लगइन के रूप में डाउनलोड कर सकते हैं: प्लगइन निकालें बायो बॉक्स

इससे पहले

यहाँ छवि विवरण दर्ज करें

उपरांत

यहाँ छवि विवरण दर्ज करें

पासवर्ड फ़ील्ड अब संपर्क जानकारी के अंतर्गत हैं ... यदि आपको वह पसंद नहीं है, तो हेडलाइन जोड़ें stop()- और I18n की देखभाल करें। ;)


यह मेरे लिए बहुत उपयोगी है, और बस इसके बाद मैं क्या था। धन्यवाद!
मार्क

1
अच्छा लगा। IS_PROFILE_PAGEनिरंतर के बारे में ज्ञात नहीं है :)
Anh Tran

यह
14.1 पर

@realtebo हाँ, <h3>एक है <h2>अब। मैंने कोड तय कर लिया है।
FUXIA

7

चूंकि हाल ही में वर्ग परिवर्तन इस काम करता है:

add_action( 'personal_options', array ( 'T5_Hide_Profile_Bio_Box', 'start' ) );

/**
 * Captures the part with the biobox in an output buffer and removes it.
 *
 * @author Thomas Scholz, <info@toscho.de>
 *
 */
class T5_Hide_Profile_Bio_Box
{
    /**
     * Called on 'personal_options'.
     *
     * @return void
     */
    public static function start()
    {
        $action = ( IS_PROFILE_PAGE ? 'show' : 'edit' ) . '_user_profile';
        add_action( $action, array ( __CLASS__, 'stop' ) );
        ob_start();
    }

    /**
     * Strips the bio box from the buffered content.
     *
     * @return void
     */
    public static function stop()
    {
        $html = ob_get_contents();
        ob_end_clean();

        // remove the headline
        $headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' );
        $html = str_replace( '<h3>' . $headline . '</h3>', '', $html );

        // remove the table row
        $html = preg_replace( '~<tr class="user-description-wrap">\s*<th><label for="description".*</tr>~imsUu', '', $html );
        print $html;
    }
}

1
मैं बस इसे इस $headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' )में बदलने का सुझाव देता हूं$headline = ( IS_PROFILE_PAGE ? __('About Yourself') : __('About the user' ));
realtebo

इसके अलावा: शीर्षक अब एक <h2>टैग में है
realtebo

2

पिछले उत्तरों पर निर्माण, यहाँ मैं उपयोगकर्ता पृष्ठ के उन हिस्सों को हटाने के लिए उपयोग कर रहा हूँ जिन्हें मैं नहीं चाहता:

$pagesToAffect = [
    '/wp-admin/user-edit.php',
    '/wp-admin/profile.php'
];

if (isset($PHP_SELF) && in_array($PHP_SELF, $pagesToAffect)) {
    add_action('admin_head', [UserProfileCleaner::class, 'start']);
    add_action('admin_footer', [UserProfileCleaner::class, 'finish']);
    add_filter('user_contactmethods',[UserProfileCleaner::class, 'hideInstantMessaging'],10000,1);
}

class UserProfileCleaner {
    public static function start() {
        ob_start(function($buffer) {
            // Personal Options
            if (!IS_PROFILE_PAGE) {
                $startHeading = 'Personal Options';
                $pattern = "@<(h[0-9]) ?[^>]*?>".preg_quote(_x($startHeading))."</\\1 ?>@is";
                preg_match($pattern, $buffer, $start, PREG_OFFSET_CAPTURE);

                $endHeading = 'Name';
                $pattern = "@<(h[0-9]) ?[^>]*?>".preg_quote(_x($endHeading))."</\\1 ?>@is";
                preg_match($pattern, $buffer, $end, PREG_OFFSET_CAPTURE);

                if (isset($start[0][1]) && isset($end[0][1]) && $start[0][1]<$end[0][1]) {
                    $buffer = substr($buffer, 0, $start[0][1]).substr($buffer,$end[0][1]);
                }
            }

            $buffer = self::removeSectionHeading($buffer, 'Name');
            $buffer = self::removeSectionHeading($buffer, 'Contact Info');

            $buffer = self::removeSectionHeading($buffer, 'Additional Capabilities');
            $buffer = self::removeSectionRow($buffer, 'Capabilities');

            $buffer = self::removeSectionHeading($buffer, 'Forums');

            // About / Bio
            $heading = IS_PROFILE_PAGE ? 'About Yourself' : 'About the user';
            $buffer = self::removeStandardSection($buffer, $heading);

            // Yoast
            $heading = 'Yoast SEO Settings';
            $buffer = self::removeStandardSection($buffer, $heading);

            $heading = 'Memberships';
            $pattern = "@<(h[0-9]) ?[^>]*?>".preg_quote(_x($heading))."</\\1 ?>.*?</p>@is";
            $buffer = preg_replace($pattern, "", $buffer, 1);

            return $buffer;
        });
    }

    private static function removeStandardSection($buffer, $heading) {
        $pattern = "@<(h[0-9]) ?[^>]*?>".preg_quote(_x($heading))."</\\1 ?>.*?</table>@is";
        return preg_replace($pattern, "", $buffer, 1);
    }

    private static function removeSectionHeading($buffer, $heading) {
        $pattern = "@<(h[0-9]) ?[^>]*?>".preg_quote(_x($heading))."</\\1 ?>@is";
        return preg_replace($pattern, "", $buffer, 1);
    }

    function removeSectionRow($buffer, $heading) {
        $pattern = "@<tr ?[^>]*?>[^<]*?<th ?[^>]*?>[^<]*?".preg_quote(_x($heading))."[^<]*?</th ?[^>]*?>.*?</tr ?>@is";
        return preg_replace($pattern, "", $buffer, 1);
    }

    public static function finish() {
        ob_end_flush();
    }

    public static function hideInstantMessaging( $contactmethods ) {
        unset($contactmethods['googleplus']);
        unset($contactmethods['twitter']);
        unset($contactmethods['facebook']);
        return $contactmethods;
    }
}

यह अभी भी HTML की संरचना पर निर्भर है, लेकिन यह मेरे लिए काम करता है।


मैं उपयोगकर्ता-new.php से वेबसाइट कैसे निकाल सकता हूं? मैंने पृष्ठ को $ PagesToAffect में जोड़ा और एक पंक्ति के रूप में वेबसाइट को हटा दिया, लेकिन यह अभी भी है।
जेसन

2

सबसे सरल और सबसे हल्का समाधान सीएसएस का उपयोग केवल इसे देखने से छिपाने के लिए है।

.user-description-wrap {
   display: none;
}

0

यदि आप नीचे दिए गए कोड को अपने functions.php फ़ाइल में जोड़ते हैं, तो यह बहु-भाषा साइट की सभी भाषाओं के लिए बायो सेक्शन को हटा देगा:

//remove the bio
function remove_plain_bio($buffer) {
    $titles = array('#<h3>'._x('About Yourself').'</h3>#','#<h3>'._x('About the user').'</h3>#');
    $buffer=preg_replace($titles,'<h3>'._x('Password').'</h3>',$buffer,1);
    $biotable='#<h3>'._x('Password').'</h3>.+?<table.+?/tr>#s';
    $buffer=preg_replace($biotable,'<h3>'._x('Password').'</h3> <table class="form-table">',$buffer,1);
    return $buffer;
}
function profile_admin_buffer_start() { ob_start("remove_plain_bio"); }
function profile_admin_buffer_end() { ob_end_flush(); }
add_action('admin_head', 'profile_admin_buffer_start');
add_action('admin_footer', 'profile_admin_buffer_end');
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.