Поддержка Проблемы и решения Написание плагина. Не создаётся БД.

  • Пишу плагин под сапу, с БД&API имею дело первый раз. Объясните почему данный код не создаёт в БД таблицу с префиксом wp_madsape.

    <?php
    /*
    Plugin Name: Mad_Sape
    Plugin URI: http://страница_с_описанием_плагина_и_его_обновлений
    Description: Установка кода Sape.
    Version: 1.0
    Author: Yuriy 'Mad_Man' Lagodich
    Author URI: http://d-o-b.ru/
    */
    /*  Copyright 2010 Lagodich Yuriy Vladimirovich (email: admin@m7team.ru)
    
        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 2 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 St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    global $jal_db_version;
    $jal_db_version = "1.0";
    register_activation_hook(__FILE__,'jal_install');
    
    function jal_install () {
       global $wpdb;
       global $jal_db_version;
    
       $table_name = $wpdb->prefix . "madsape";
       if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
    
          $sql = "CREATE TABLE " . $table_name . " (
    	  id mediumint(9) NOT NULL AUTO_INCREMENT,
    	  time bigint(11) DEFAULT '0' NOT NULL,
    	  name tinytext NOT NULL,
    	  text text NOT NULL,
    	  url VARCHAR(55) NOT NULL,
    	  UNIQUE KEY id (id)
    	);";
    	     require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
          dbDelta($sql);
    
          $rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'name' => $welcome_name, 'text' => $welcome_text ) );
    
          add_option("jal_db_version", $jal_db_version);
    }
    }
    
    add_action('admin_menu', 'sape_menu');
    
    function sape_menu() {
        add_submenu_page('options-general.php'
                         , 'Mad_Sape'
                         , 'Mad_Sape'
                         , 'edit_plugins'
                         , __FILE__
                         , 'callme');
    add_action('admin_menu', 'callme');
    }
    function callme() {
    include 'wp_area.php';
    add_action('admin_menu', 'footer');
    }
    function footer() {
    add_action('wp_footer', 'sape_code');
    }
    function sape_code() {
    include 'sape.php';
    }
    ?>

Просмотр 1 ответа (всего 1)
  • во первых — прогнать SQL в phpMyAdmin дабы убедится что он работает.
    Cледующий шаг это отдельно отладить function jal_install, и когда она заработает можно навесить ее на register_activation_hook
    кароче вот так поэтапно

Просмотр 1 ответа (всего 1)
  • Тема «Написание плагина. Не создаётся БД.» закрыта для новых ответов.