Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghost shortcode #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions includes/class-elements.php
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
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