Добавить опцию CMB2, чтобы скрыть таблицу с метаданными - PullRequest
0 голосов
/ 18 февраля 2020

Мне нужна помощь, так как я все еще немного неопытен с CMB2

У меня есть эта таблица с некоторыми метаданными:

    <div class="profile-details">
        <h1 class="title-lined"><?php echo esc_html( $current_user->display_name ); ?></h1>
        <table class="table personal-information">
            <thead>
            <tr>
                <th scope="col"></th>
                <th scope="col"><strong><?php esc_html_e( 'Start', 'lsx-health-plan' ); ?></strong></th>
                <th scope="col"><strong><?php esc_html_e( 'Goal', 'lsx-health-plan' ); ?></strong></th>
                <th scope="col"><strong><?php esc_html_e( 'Current', 'lsx-health-plan' ); ?></strong></th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <th scope="row"><strong><?php esc_html_e( 'Weight:', 'lsx-health-plan' ); ?></strong></th>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'weight_start', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'weight_start', true ) . ' kg' );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'weight_goal', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'weight_goal', true ) . ' kg' );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'weight_end', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'weight_end', true ) . ' kg' );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <th scope="row"><strong><?php esc_html_e( 'Waist:', 'lsx-health-plan' ); ?></strong></th>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'waist_start', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'waist_start', true ) . ' cm' );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'waist_goal', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'waist_goal', true ) . ' cm' );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'waist_end', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'waist_end', true ) . ' cm' );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <th scope="row"><strong><?php esc_html_e( 'Fitness:', 'lsx-health-plan' ); ?></strong></th>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'fitness_start', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'fitness_start', true ) );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'fitness_goal', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'fitness_goal', true ) );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    if ( '' !== get_user_meta( get_current_user_id(), 'fitness_end', true ) ) {
                        echo wp_kses_post( get_user_meta( get_current_user_id(), 'fitness_end', true ) );
                    } else {
                        echo '/';
                    }
                    ?>
                </td>
            </tr>
            </tbody>
        </table>

    </div>

Я хотел бы добавить поле переключения, которое отключает или скрывает либо параметры, либо всю таблицу (что будет проще).

Я так долго добавил в параметр настройки:

public function stat_disable( $cmb ) {
    $cmb->add_field(
        array(
            'id'      => 'stat_disable_title',
            'type'    => 'title',
            'name'    => __( 'Disable Profile Stats', 'lsx-health-plan' ),
            'default' => __( 'Disable Profile Stats', 'lsx-health-plan' ),
        )
    );
    $cmb->add_field( array(
        'name' => 'Disable All Stats',
        'desc' => 'Disable All Stats',
        'id'   => 'stat_checkbox',
        'type' => 'checkbox',
        'value'   => 1,
        'default' => 0,         
    ) );
}   

I ' Я просто борюсь с тем, как это подключить.

Любая помощь будет признательна.

С уважением,

...