Get options in show in shortcode
-
I’m trying get option in shortcode , how i can make this.
<?php function chat_bot_conversational() { $args = array( 'id' => 'principal_bot_response', 'title' => 'Principal', 'object_types' => array( 'options-page' ), 'admin_menu_hook' => 'network_admin_menu', 'option_key' => 'bot_conversation', 'tab_group' => 'bot_conversation', 'tab_title' => 'Principal', ); if ( version_compare( CMB2_VERSION, '2.4.0' ) ) { $args['display_cb'] = 'bots_responses'; } $main_options = new_cmb2_box( $args ); $group_id = $main_options->add_field( array( 'id' => 'questoes_multisite', 'type' => 'group', 'description' => 'Perguntas ', 'options' => array( 'group_title' => 'Questão {#}', 'add_button' => 'Adicionar Questão', 'remove_button' => 'Remover Questão', 'sortable' => true ) )); $main_options->add_group_field( $group_id, array( 'name' => 'Nome do Campo', 'id' => 'nome', 'type' => 'text', )); $main_options->add_group_field( $group_id, array( 'name' => 'Questão', 'id' => 'questao', 'type' => 'textarea_small', )); $main_options->add_group_field( $group_id, array( 'name' => 'Grupo', 'id' => 'grupo', 'type' => 'text', )); $main_options->add_group_field( $group_id, array( 'id' => 'opcoes_pergunta', 'name' => __('Opções ', 'opcoes'), 'type' => 'text', 'sortable' => true, 'repeatable' => true, )); } function myprefix_get_option( $key = '', $default = false ) { if ( function_exists( 'cmb2_get_option' ) ) { return cmb2_get_option( 'bot_conversation', $key, $default ); } // Fallback to get_option if CMB2 is not loaded yet. $opts = get_option( 'bot_conversation', $default ); $val = $default; if ( 'all' == $key ) { $val = $opts; } elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) { $val = $opts[ $key ]; } return $val; } add_action( 'cmb2_admin_init', 'chat_bot_conversational' ); function foobar_func( $atts ){ $bla = myprefix_get_option( 'questoes_multisite'); print_r($bla); return $bla; } add_shortcode( 'foobar', 'foobar_func' );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Get options in show in shortcode’ is closed to new replies.