Enclavely / tailor

Build beautiful page layouts quickly and easily using your favourite WordPress theme.
https://www.tailorwp.com
GNU General Public License v3.0
1.05k stars 102 forks source link

Extending: New $atts not found in php using Sample Extension #165

Open MikeiLL opened 6 years ago

MikeiLL commented 6 years ago

php version PHP 7.1.16 Tailor version 1.8.2

Using the Sample Extension format, when I create or update controls, it seems I need to change the name of the shortcode and class in order for the changes to register with php.

Otherwise, $atts are updated in javascript, but in php, the old ones persist. Not sure what I'm doing wrong.

Add new element with setting and control:

class Tailor_New_Cool_Element extends Tailor_Element {

    /**
     * Registers element settings, sections and controls.
     *
     * @since 1.0.0
     * @access protected
     */
    protected function register_controls()
    {

        $priority = 20;

        $this->add_section('main', array(
            'title' => __('Main', 'tailor'),
            'priority' => $priority = 10,
        ));

        // Add as many custom settings as you like..
        $this->add_setting('title', array(
            'sanitize_callback' => 'tailor_sanitize_text',
            'default' => 'Main title',
        ));
        $this->add_control('title', array(
            'label' => __('Title'),
            'type' => 'text',
            'section' => 'main',
            'priority' => $priority += 10,
        ));

        $card_front_control_types = array(
            'text'
        );
        $card_front_control_arguments = array();
        tailor_control_presets($this, $card_front_control_types, $card_front_control_arguments, $priority);

    }
}

And the shortcode:

if ( ! function_exists( 'tailor_shortcode_new_cool_element' ) ) {

    function tailor_shortcode_new_cool_element( $atts, $content = null, $tag ) {

        /**
         * some other code...
         */

        ob_start();

        print_r( $atts );
        $outer_html = "<div {$html_atts}>%s</div>";

        $content = ob_get_clean();
        $inner_html = '<div class="tailor-new-cool__content">%s</div>';

        $html = sprintf( $outer_html, sprintf( $inner_html, $content ) );

        return $html;
    }

    add_shortcode( 'tailor_new_cool', 'tailor_shortcode_new_cool_element' );
}

And register:

// Within Tailor_Extension class
 function register_elements( $element_manager ) {
            $element_manager->add_element( 'tailor_new_cool', array(
                'label'             =>  __( 'New Cool' ),
                'description'       =>  __( 'Add a cool thing' ),
                'badge'             =>  __( 'Intensity' ),
                'type'              =>  'wrapper',
                'child_container'   =>  '.tailor-new-cool__content',
            ) );
}

If I update the title control to say, heading, $atts still hold title. I imagine it's something obvious.

conwaydev commented 5 years ago

Don't know if you ever got the answer to this, but in our experience we've had to clear our transients after adding an attribute.