Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions includes/class-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,42 @@ public function add_element( $tag, $args = array() ) {

if ( isset( $element ) ) {
$this->elements[ $element->tag ] = $element;
$this->register_shortcode_if_not_exists( $tag );
}
}

/**
* Create shortcode if it doesn't exists, based on element tag.
*
* @access public
*
* @param string $tag
*
* @return array
*/
public function register_shortcode_if_not_exists( $tag ) {
global $shortcode_tags;

if ( ! array_key_exists( $tag, $shortcode_tags ) ) {
add_shortcode( $tag, array( $this, 'print_element_shortcode') );
}
}

/**
* Render the shortcode.
*
* @access public
*
* @param array $atts
* @param string $content
* @param string $tag
*
* @return array
*/
public function print_element_shortcode( $atts, $content = '', $tag ) {
return apply_filters( "tailor_render_element_shortcode_{$tag}", '', $atts, $content );
}

/**
* Returns the registered elements.
*
Expand Down
4 changes: 2 additions & 2 deletions includes/class-models.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ public function print_models() {
public function generate_element_regex() {
$element_types = array();
foreach ( tailor_elements()->get_elements() as $element ) {
$element_types[] = str_replace( 'tailor_', '', $element->tag );
$element_types[] = $element->tag;
}
$this->regex = sprintf(
"/<!--" .
Expand Down Expand Up @@ -935,7 +935,7 @@ public function generate_models_from_html( $html, $parent, $models ) {
$content = $matches[5][ $i ];
$model = array(
'id' => $id,
'tag' => 'tailor_' . $type,
'tag' => $type,
'atts' => array(),
'parent' => $parent,
'order' => $i,
Expand Down