Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1120628
    cloverdalecanrc
    Participant

    I hope that my title is self descriptive.

    I want to write some of my own short codes for my site and I’d like to make use of the UI that Cornerstone provides. It’ll make life a whole lot easier for my authors, not to mention reduce the number of support calls I have to handle (ok, its mostly my niece, but its the principle of the thing).

    This is what I’ve figured out and since its really convoluted, I’m hoping that someone who knows mare than I will be able to either give me a less tortuous method or validate that this is best approach.

    1. In my plugin add an init action with a priority greater than that of Cornerstone_Plugin. Since its priority is -1000 I can use the default 10.
    2. Grab the plugin singleton from $cs = $GLOBALS['cornerstone_plugin']
    3. Grab the shortcode plugin from $shortcode = cs->component['Shortcode_Generator']
    4. Remove the AJAX action with remove_action( 'wp_ajax_csg_list_shortcodes', array( &$shortcode, 'modelEndpoint' ) );
    5. Create my own action for wp_ajax_csg_list_shortcodes which calls $shortcode->add($myShortcodeArgs); for all my shortcoes, ensuring they’re only added once (like Shortcode Generator). Then call $shortcode->modelEndpoint();

    Anyone see any great problems with this particular approach?

    #1120819
    Christian
    Moderator

    Hey there,

    Please see https://community.theme.co/kb/cornerstone-custom-elements/. If you need more detailed instruction or tutorial, You might want to contact our trusted partners who caters X setup and customization needs. Please see https://community.theme.co/custom-development/

    Thanks.

    #1121158
    cloverdalecanrc
    Participant

    So that’s great for adding elements to the page builder. However, I’m looking at adding them to the _other_ shortcode control, the one that’s populated using the shortcode generator class. I’m going to guess that there is no easy way to do it given this comment in the code:

    
    // These mappings will eventually be removed entirely, and the shortcode
    // generator will use the same controls registered for the page builder.
    
    #1121293
    Rue Nel
    Moderator

    Hello Again,

    Please follow the instructions and build your own custom Cornerstone addon. This is very highly recommended so that all your customizations and shortcode additions in a separate addon plugin so that when there are Cornerstone updates it will not be overwritten. You can always download the sample plugin and use it as your base framework. You can download it from here (http://community-themeco.s3.amazonaws.com/resources/my-extension.zip) and see further details here (https://community.theme.co/kb/cornerstone-custom-elements/)

    Hope this explains it.

    #1152770
    cloverdalecanrc
    Participant

    So I looked at both the sample extension and the documentation and they have nothing to do with what I’m trying to accomplish.

    You can use the following code to do what I’m looking for:

    
    <?php  
    add_action('init', 'myCS_test_init', 20);
    
    function myCS_test_init() {
    	$shortcode = CS()->component('Shortcode_Generator');
    	remove_action( 'wp_ajax_csg_list_shortcodes', array( &$shortcode, 'modelEndpoint' ));
    	add_action( 'wp_ajax_csg_list_shortcodes', 'myCS_modelEndpoint');
    }
    
    function myCS_modelEndpoint() {
    	$shortcode = CS()->component('Shortcode_Generator');
    	$shortcode->add(
    	array(
    		'id' => 'myCS_kitchen',
    		'title' => __( 'Kitchen Sink', 'myTextDomain' ),
    		'section' => __( 'Structure', 'myTextDomain' ),
    		'description' => __( 'All the field types you can create. Don\'t forget a URL to a demo', 'myTextDomain' ),
    		'demo' => 'http://dev.littlefyr.com/new-sample-shortcode/',
    		'params' => array(
    			array(
    				'param_name' => 'content',
    				'heading' => __( 'Content', 'myTextDomain' ),
    				'description' => __( 'Param with param_name of content will endup as the content of your tag, not an attribute', 'myTextDomain' ),
    				'type' => 'textarea_html',
    				'value' => 'type of textarea and textarea_html seem to be rendered the same'
    				),
    			array(
    				'param_name' => 'arg1',
    				'heading' => __( 'Text Argument', 'myTextDomain' ),
    				'description' => __( 'Basic text field', 'myTextDomain' ),
    				'type' => 'textfield',
    				'value' => 'Default value'
    				),
    			array(
    				'param_name' => 'arg2',
    				'heading' => __( 'Dropdown', 'myTextDomain' ),
    				'description' => __( 'Select select a value.', 'myTextDomain' ),
    				'type' => 'dropdown',
    				'value' => array(
    					'Option 1' => 'opt1',
    					'Oprion 2' => 'opt2',
    					'Option 3' => 'opt3'
    					)
    				),
    			array(
    				'param_name' => 'arg3',
    				'heading' => __( 'Checkbox', 'myTextDomain' ),
    				'description' => __( 'Toggle a checkbox.', 'myTextDomain' ),
    				'type' => 'checkbox',
    				'value' => 'true'
    				),
    			array(
    				'param_name' => 'arg4',
    				'heading' => __( 'Image Src', 'myTextDomain' ),
    				'description' => __( 'Enter your image.', 'myTextDomain' ),
    				'type' => 'attach_image',
    				), 
    			array(
    				'param_name' => 'arg5',
    				'heading' => __( 'Advanced Argument', 'myTextDomain' ),
    				'description' => __( 'Any field can be shown only when the advanced button is toggled', 'myTextDomain' ),
    				'type' => 'textfield',
    				'value' => 'Default value',
    				'advanced' => true
    
    				),
    				//the default ID, class and style fields are advanced by default, but you can can show them
    				//by default if desired
    				Cornerstone_Shortcode_Generator::map_default_id( array( 'advanced' => false)),
    				Cornerstone_Shortcode_Generator::map_default_class(),
    				Cornerstone_Shortcode_Generator::map_default_style()
    				)
    			)
    		);
    	//Add all your other shortcode definitions here. 
    	$shortcode->modelEndpoint();
    }
    
    // Add Shortcode
    function myCS_kitchensink_shortcode( $atts , $content = null ) {
    
    	// Attributes
    	$atts = shortcode_atts(
    		array(
    			'arg1' => 'def',
    			'arg2' => 'def',
    			'arg3' => 'def',
    			'arg4' => 'def',
    			'arg5' => 'def',
    		),
    		$atts
    	);
    	extract($atts);
    	return <<<EOT
    	<dl>
    		<dt>content</dt><dd>$content</dd>
    		<dt>arg1</dt><dd>$arg1</dd>
    		<dt>arg2</dt><dd>$arg2</dd>
    		<dt>arg3</dt><dd>$arg3</dd>
    		<dt>arg4</dt><dd>$arg4</dd>
    		<dt>arg5</dt><dd>$arg5</dd>
    	</dl>
    EOT;
    
    }
    add_shortcode( 'myCS_kitchen', 'myCS_kitchensink_shortcode' );
    

    You can see my shortcode in the attached image. The only catches are (a) all your shortcodes go before the others and (b) if you want to add new sections, you’ll have to do something do the same sort of thing but for the media_button action that will run before the shortcode generator

    #1152972
    Paul R
    Moderator

    Hi,

    Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

    Thank you for your understanding.

  • <script> jQuery(function($){ $("#no-reply-1120628 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>