• Resolved joediego

    (@joediego)


    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)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Use myprefix_get_option( 'bot_conversation' ); instead since bot_conversation is the option key being used for this configuration, not questoes_multisite If anything, it should get you something to work with.

    Thread Starter joediego

    (@joediego)

    I will try!, Thanks!!

    Thread Starter joediego

    (@joediego)

    
    <?php
    function chat_bot_conversational() {
    
    	$args = array(
    		'id'           => 'principal_bot_response',
    		'title'        => 'Principal',
    		'object_types' => array( 'options-page' ),
    		// 'admin_menu_hook' => 'network_admin_menu' // NOT WORKING,
    		'option_key'   => 'bot_conv',
    	);
    
    	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_conv', $key, $default );
    	}
    	// Fallback to get_option if CMB2 is not loaded yet.
    	$opts = get_option( 'bot_conv', $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 = get_option( 'bot_conv');
    	print_r($bla);
    	return $bla;
    }
    add_shortcode( 'foobar', 'foobar_func' );
    
    

    Network Multisite dont work!!
    How i can Make this?!?!

    • This reply was modified 6 years, 1 month ago by joediego.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Is it possible it’s getting saved to your network options table? Try with get_site_option()

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Get options in show in shortcode’ is closed to new replies.