Zebios
Zebios

Reputation: 31

Fatal Error : Plugin tag "escape" already registered

I tried to install a One Page chechout plugin for prestashop, and immediately after that i got an error.

error 500

I deleted the module folder via FTP and activated DEBUG mode on prestashop and now i got this error:

Fatal error: Uncaught --> Smarty: Plugin tag "escape" already registered <-- thrown in /home/user/public_html/vendor/prestashop/smarty/sysplugins/smarty_internal_templatebase.php on line 449

Please help me i don't know what to do, this is my first time using prestashop and i already have 1000+ articles on my shop.

Code:

    $file_smarty_config = _PS_ROOT_DIR_.'/config/smarty.config.inc.php';
    if (is_file($file_smarty_config)) {
        if (is_writable($file_smarty_config)) {
            $content = Tools::file_get_contents($file_smarty_config);

            if (!strstr($content, 'escapePTS')) {
                $content .= '
                    //CODE MODULES PRESTEAMSHOP - PLEASE NOT REMOVE
                    //--------------------------------------------------------------------------------------------------------
                    smartyRegisterFunction($smarty, "modifier", "escape", "escapePTS");
                    function escapePTS($string, $esc_type = "html", $char_set = null, $double_encode = true, $as_html = false)
                    {
                        $smarty_escape = SMARTY_PLUGINS_DIR."modifier.escape.php";
                        include_once $smarty_escape;

                        if (!$as_html && is_callable("smarty_modifier_escape")) {
                            $string = call_user_func("smarty_modifier_escape", $string, $esc_type, $char_set, $double_encode);
                        }

                        return $string;
                    }
                    //--------------------------------------------------------------------------------------------------------
                ';
                file_put_contents($file_smarty_config, $content);
            }
        }
    }

    $file_uniform = _PS_THEME_DIR_.'js/autoload/15-jquery.uniform-modified.js';
    if (is_file($file_uniform)) {
        if (is_writable($file_uniform)) {
            $content_uniform = Tools::file_get_contents($file_uniform);

            if (!strstr($content_uniform, '.not(".not_unifrom, .not_uniform").uniform();')) {
                $content_uniform = preg_replace(
                    '/'.preg_quote('.uniform();').'/i',
                    '.not(".not_unifrom, .not_uniform").uniform();',
                    $content_uniform
                );

                file_put_contents($file_uniform, $content_uniform);

                rename($file_uniform, _PS_THEME_DIR_.'js/autoload/15-jquery.uniform-modified-pts.js');
            }
        }
    }

Upvotes: 3

Views: 2593

Answers (3)

TomanDesign
TomanDesign

Reputation: 1

I just removed

//CODE MODULES PRESTEAMSHOP - PLEASE NOT REMOVE
//--------------------------------------------------------------------------------------------------------
smartyRegisterFunction($smarty, "modifier", "escape", "escapePTS");
function escapePTS($string, $esc_type = "html", $char_set = null, $double_encode = true, $as_html = false)
{
    $smarty_escape = SMARTY_PLUGINS_DIR."modifier.escape.php";
    include_once $smarty_escape;

    if (!$as_html && is_callable("smarty_modifier_escape")) {
        $string = call_user_func("smarty_modifier_escape", $string, $esc_type, $char_set, $double_encode);
    }

    return $string;
}
//--------------------------------------------------------------------------------------------------------

From end of file /config/smarty.config.inc.php and now it's working. But for me, the module installation was not successful, the module was not installed.

Upvotes: 0

Sami Kerboute
Sami Kerboute

Reputation: 11

Change this:

smartyRegisterFunction($smarty, "modifier", "escape", "escapePTS");

to this:

if (!isset($smarty->registered_plugins['modifier']['escape'])) {
smartyRegisterFunction($smarty, "modifier", "escape", "escapePTS");
}

Upvotes: 1

idnovate
idnovate

Reputation: 1032

First of all, you should never delete modules from FTP. It can create tables, overrides, etc. that would remain if you remove it from FTP and don't uninstall it module correctly.

So as soon as you restore your backoffice, you should upload module again and uninstall it from backoffice.

To detect who's causing error

Fatal error: Uncaught --> Smarty: Plugin tag "escape" already registered <-- thrown in /home/user/public_html/vendor/prestashop/smarty/sysplugins/smarty_internal_templatebase.php on line 449

You can add this code in this file:

public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
{
    if (isset($this->smarty->registered_plugins[$type][$tag])) {
        //This code will throw the caller function
        $e = new Exception;
        var_dump($e->getTraceAsString());
        throw new SmartyException("Plugin tag \"{$tag}\" already registered");
    } elseif (!is_callable($callback)) {
        throw new SmartyException("Plugin \"{$tag}\" not callable");
    } else {
        $this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
    }

    return $this;
}

Once you know who's causing the error, you have to verify if plugin is already registered before registering it:

if (!isset($this->context->smarty->registered_plugins['function']['escape'])) {
    $this->context->smarty->registerPlugin('function', 'escape', array($lazyRegister, 'escape'));
}

EDIT:

If the error comes from plugin tag escapePTS from module onepagecheckoutps, replace the following line:

smartyRegisterFunction($smarty, "modifier", "escape", "escapePTS");

from file /classes/OnePageCheckoutPSCore.php

with:

if (!isset($this->context->smarty->registered_plugins['modifier'}['escape'])) {
    smartyRegisterFunction($smarty, "modifier", "escape", "escapePTS");
}

Upvotes: 2

Related Questions