• Resolved Andry

    (@blackstar1991)


    Hi I need to show Custom Tabs in menu only for current user. How to make it ?

    I tried to use this check. But she’s not up to the task

    /// Add link for UM Navigation
    /**
     * Add a new Profile tab
     *
     * @param array $tabs
     * @return array
     */
    function um_mycustomtab_add_tab($tabs)
    {
    
        $tabs['mycustomtab'] = array(
            'name' => __('Create Post', 'pr'),
            'icon' => 'um-icon-link',
            'custom' => true
        );
    
        UM()->options()->options['profile_tab_' . 'mycustomtab'] = true;
    
        return $tabs;
    }
    
    
    /**
     * Render tab content
     *
     * @param array $args
     */
    function um_profile_content_mycustomtab_default($args)
    {
        
            $action = 'mycustomtab';
            $fields_metakey = array(
                'description'
            );
    
            $nonce = filter_input(INPUT_POST, '_wpnonce');
            if ($nonce && wp_verify_nonce($nonce, $action) && um_is_myprofile()) {
                foreach ($fields_metakey as $metakey) {
                    update_user_meta(um_profile_id(), $metakey, filter_input(INPUT_POST, $metakey));
                }
                UM()->user()->remove_cache(um_profile_id());
            }
    
            $fields = UM()->builtin()->get_specific_fields(implode(',', $fields_metakey));
            ?>
    
            <div class="um">
                <div class="um-form custom_um_tab">
                    <p><?php _e("If you're reading this, you have the opportunity to create an Post for the site. Once published, your post will be reviewed by our editor. If it meets the quality of writing, other users will be able to evaluate it.", 'pr') ?></p>
                    <p><?php _e("Write articles that can improve the lives of others and answer important questions.", 'pr') ?></p>
                    <p><?php _e("Please check the information carefully before publishing.", 'pr') ?></p>
                    <a class="btn btn_create_post" href="/wp-admin/edit.php"
                       rel="nofollow noreferrer"><?php _e("I have something to say", 'pr') ?></a>
                </div>
            </div>
            <?php
    
    }
    
    if (um_is_myprofile()) {
        add_filter('um_profile_tabs', 'um_mycustomtab_add_tab', 1000);
        add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
    }
Viewing 1 replies (of 1 total)
  • @blackstar1991

    Your test of um_is_myprofile() is always returning false,
    nobody knows at this time which User page will be processed.
    WP is collecting all known callbacks for later usage.

    Make the um_is_myprofile() test in the functions instead.

Viewing 1 replies (of 1 total)
  • The topic ‘Show tabs only for current user’ is closed to new replies.