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

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

Open
MikeiLL opened this issue Apr 23, 2018 · 1 comment
Open

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

MikeiLL opened this issue Apr 23, 2018 · 1 comment

Comments

@MikeiLL
Copy link

MikeiLL commented Apr 23, 2018

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants