When using the Visual Code Editor you have the option to insert premade code items. You can add more items yourself using the filters snipr_code_items and snipr_code_hub.

premade_code_items_arrow

  • snipr_code_items Adds a new item to premade code items list.
  • snipr_code_hub Adds the code for the item

This example will add a new code item called “html_div” in the HTML category. It will add default HTML opening and closing div tags. And has the option for users to add custom ID and Class values.

<?php 
/**
 * 1. Add a new item to the code items array.
 * Using the "snipr_code_items" filter.
 *
 * $snipr_items (array) All available code items.
 * $args (array) The arguments.
 */
add_filter('snipr_code_items', 'my_code_items', 10, 2);
function my_code_items( $snipr_items, $args ){  
	
	global $snipr_main;
		
	/**
	 * $snipr_items array structure example:
	 *
	 * > categroy
	 *     - item
	 *     >> sub category
	 *         - sub item
	 * -----------------------------------------------------------------------
	 *
	 * > default
	 *     >> editor
	 *         - code_editor
     * > html
	 *     - html_head
     *     - html_body
     * > php
     *     - php_class
     *     - file_header
     *     - php_function
     *     >> wordpress
     *         - wp_plugin_header
     *         - wp_shortcode
     * > js
     *     - script_container
     *     >> jquery
	 *         - jquery_document_ready
     */
	 
     // Select the category and sub category for your item. Choose a default one or add a new one if needed.
	 $category = 'html';
	 $sub_category = '';
	 
	 $my_item = array(
	 	// Add your item name (slug). NOTE: Array key and item attribute have to be the same! (in this case: html_div)
		'html_div' => array(
			'item' => 'html_div',
			'id' => $snipr_main->snipr_id(),
			'allowed_parents' => array(),
			'category' => $category,
			'sub_category' => $sub_category,
			'title' => __('Div', 'snipr'),
			'info' => __('HTML opening and closing div.','snipr'),
			'icon' => '',
			'allow_childs' => 1,
			/**
			 * Edit arr. This creates the edit form for the user customizable values.
			 * You can leave this empty if no values are needed. "edit_arr => array()"
			 * 
			 * In this case we use 2 values: "id" and "class". both standard input fields.
			 */
			'edit_arr' => array(
				'id' => array(
                    'type' => 'input',
                    'args' => array(
                        'label' => __('Div ID','snipr'),
                        'desc' => __('ID that should be added to the HTML <div> tag.','snipr'),
                        'importance' => 'optional'
                    ),
                    'fields' => array(
                        'value' => sniprApi::get_value('id', $args)
                    )
                ),
				'class' => array(
					'type' => 'input',
					'args' => array(
						'label' => __('Div Class','snipr'),
						'desc' => __('Classes that should be added to the <div> tag.','snipr'),
						'importance' => 'optional'
					),
					'fields' => array(
						'value' => sniprApi::get_value('class', $args)
					)
				)
			),
			/**
			 * Content allows you to add child items.
			 */
			'content' => array()
		),
	 );
	 
     /** 
      * Add your new item to the main array.
      * $my_item (array) the array containing your new items.
      * $snipr_items (array) the array containing all snipr items.
      */
     $snipr_items = sniprApi::add_code_item($my_item, $snipr_items);
	 
	return $snipr_items;
}



/**
 * 2. Add the code for the new item.
 * Using the "snipr_code_hub" filter.
 *
 * $hub (array) The main array containing all code for every available item.
 * $args (array) The item arguments.
 */
add_filter('snipr_code_hub', 'my_code_hub', 10, 2);
function my_code_hub( $hub, $args ){
	
    $id = sniprApi::create_attr('id', $args);
	$class = sniprApi::create_attr('class', $args);
	
	$my_code = array(
    	// NOTE: Array key has to be the same as the item you want to link the code to! (in this case: html_div)
		'html_div' => array(
			'code' => '<div'.$id.$class.'>%split%</div>'
		)
	);
	
    // Add your new item to the main array.
	return sniprApi::add_to_array($my_code, $hub);
}