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

Shortcode Always True in Widgets #1

Open
goxmedia opened this issue Mar 5, 2020 · 1 comment
Open

Shortcode Always True in Widgets #1

goxmedia opened this issue Mar 5, 2020 · 1 comment

Comments

@goxmedia
Copy link

goxmedia commented Mar 5, 2020

When placing a shortcode within a text widget, it always executed regardless of whether or not the configuration is set to false:

Shortcode.php

public function renderCallback($attributes, $content = null)
{
    if (is_admin()) {
        return null;
    }

    $this->attributes = shortcode_atts($this->config->defaults, $attributes, $this->config->shortcode);
    $this->content    = $this->config->doShortcodeWithinContent === true
        ? do_shortcode($content)
        : $content;

    return $this->render();
}

Custom Shortcode

return [
'autoload' => true,
'classname' => '',
'config'   => [
    'shortcode'        => 'section',
    'defaults'         => [
        'link'         => '#',
        'thumbnail'    => '#',
        'header_tag'   => 'h3',
        'title'        => '',
        'button_title' => 'Access Now',
    ],
    'doShortcodeWithinContent' => false,
    'view'                     => $rootPath . 'src/Shortcode/views/section.php',
],
];

SidebarRegister.php

protected function initEvents()
{
    add_action('init', [$this, 'run'], 20);
    //add_filter('widget_text', 'do_shortcode');
}

Is this behavior expected since WP 4.9?

https://make.wordpress.org/core/2017/10/24/widget-improvements-in-wordpress-4-9/

@goxmedia
Copy link
Author

goxmedia commented Mar 7, 2020

@hellofromtonya

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

1 participant