Suporte » Plugins e hacks » Função de desinstalação do plugin não é executado

  • Resolvido willwalker

    (@willwalker)


    Há algo de errado com esse início de plugin:

    <?php
    /*
    Plugin Name: buscaAWS
    Plugin URI: http://www.agenciawebsul.com/
    Description: Plugin de busca customizável, para usar em qualuer tipo de busca.
    Version: 1.0
    Author: Walker Sousa
    Author URI: http://www.walkersousa.com.br/
    License: GPLv2
    */

    /*
    * Copyright 2012 Walker Sousa <contato@walkersousa.com.br>
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    * MA 02110-1301, USA.
    */
    ?>

    <?php
    define(‘WP_DEBUG’, TRUE);

    require_once(ABSPATH.’wp-load.php’);

    //Cria o banco de dados
    function buscaAWS_createdb(){
    global $wpdb;

    $sql = “
    DROP TABLE IF EXISTS wp_buscaaws_campos;
    CREATE TABLE wp_buscaaws_campos (
    id int(11) NOT NULL AUTO_INCREMENT,
    name text,
    tipo text,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    DROP TABLE IF EXISTS wp_buscaaws_configuracoes;
    CREATE TABLE wp_buscaaws_configuracoes (
    id int(11) NOT NULL AUTO_INCREMENT,
    action text,
    method text,
    name text,
    template text,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    DROP TABLE IF EXISTS wp_buscaaws_valores;
    CREATE TABLE wp_buscaaws_valores (
    id int(11) NOT NULL AUTO_INCREMENT,
    valor text,
    id_campo int(11) DEFAULT NULL,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    “;

    require_once(ABSPATH.’wp-admin/includes/upgrade.php’);
    dbDelta($sql);
    }
    register_activation_hook(__FILE__, ‘buscaAWS_createdb’);

    //Deleta o banco de dados
    function buscaAWS_dropdb(){
    global $wpdb;

    $aql = “
    DROP TABLE IF EXISTS wp_buscaaws_campos;

    DROP TABLE IF EXISTS wp_buscaaws_configuracoes;

    DROP TABLE IF EXISTS wp_buscaaws_valores;
    “;

    require_once(ABSPATH.’wp-admin/includes/upgrade.php’);
    dbDelta($sql);
    }
    register_deactivation_hook(__FILE__, ‘buscaAWS_dropdb’);
    ?>

    Acontece dois erros, um é que a função buscaAWS_dropdb, não é executada. E dois é um erro que aparece no debug dizendo a seguinte mensagem: O plugin gerou 1 caracteres de resultados inesperados durante a activação. Se notar mensagens de “headers already sent”, problemas com feeds ou outros problemas, tente desactivar ou remover este plugin.

    Podem me ajudar?

A visualizar 5 respostas - de 1 a 5 (de um total de 5)
  • Aparentemente o ficheiro tem um caracter espaço ou nova linha no fim e por isso dá esse erro.

    Comenta o último ?> e tenta novamente.

    Thread Starter willwalker

    (@willwalker)

    Mas a função register_deactivation_hook tambem não funciona.

    Sobre o headers already sent, tirar o último ?> resolveu?

    Quanto ao outro erro, tens $aql em vez de $sql. Se a função no original está exactamente assim é natural que não funcione. É o chamado “síndrome do dedo gordo”, eheh 🙂

    Thread Starter willwalker

    (@willwalker)

    headers already, não resolveu. E o aql passou despercebido. Mas a query de drop table não funciona. Eu ativei o plugin, ele criou as tabelas, depois fui no banco, deletei as tabelas e mudei a query para ele criar de novo as tabelas caso desinstalasse o plugin. E ele chamou a função, sabe me dizer porque o DROP não funcionou se no console do mysql funciona?

    Thread Starter willwalker

    (@willwalker)

    Resolvi o headers already sent, tinha um espaço entre tags PHP. E fiz uma mudança para usar a global $wpdb. Mas não está executando as querys.

    function buscaAWS_createdb(){
    global $wpdb;

    $wpdb->query(
    $wpdb->prepare(“
    DROP TABLE IF EXISTS wp_buscaaws_campos;
    CREATE TABLE wp_buscaaws_campos (
    id int(11) NOT NULL AUTO_INCREMENT,
    name text,
    tipo text,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    DROP TABLE IF EXISTS wp_buscaaws_configuracoes;
    CREATE TABLE wp_buscaaws_configuracoes (
    id int(11) NOT NULL AUTO_INCREMENT,
    action text,
    method text,
    name text,
    template text,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    DROP TABLE IF EXISTS wp_buscaaws_valores;
    CREATE TABLE wp_buscaaws_valores (
    id int(11) NOT NULL AUTO_INCREMENT,
    valor text,
    id_campo int(11) DEFAULT NULL,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    “)
    );

    $wpdb->show_errors();
    }
    register_activation_hook(__FILE__, ‘buscaAWS_createdb’);

    Não acontece nada na base de dados ao ativar o plugin.

A visualizar 5 respostas - de 1 a 5 (de um total de 5)
  • O tópico ‘Função de desinstalação do plugin não é executado’ está fechado a novas respostas.