WordPress.org

Ready to get started?Download WordPress

Forums

Database tables are not being created (3 posts)

  1. rbfabbri
    Member
    Posted 4 years ago #

    Hi, i just develop my first plugin for WordPress but he isn't worlink in WPMU. The database tables are not being created. What i'm doing wrong?

    <?php
    require_once(ABSPATH.'wp-includes/pluggable.php');
    
    global $table_prefix, $wpdb;
    $wpdb->concursos = $wpdb->prefix.'concursos';
    $wpdb->criterios = $wpdb->prefix.'criterios';
    $wpdb->notas = $wpdb->prefix.'notas';
    
    $wp_concursos_table = $table_prefix . "concursos";
    $wp_criterios_table = $table_prefix . "criterios";
    $wp_notas_table = $table_prefix . "notas";
    
    if($wpdb->get_var("show tables like '$wp_concursos'") != $wp_concursos_table) {
    
    $sql_concursos = "CREATE TABLE ". $wp_concurso_table . " ( ";
    $sql_concursos .= " concurso_id int(11) NOT NULL auto_increment, ";
    $sql_concursos .= " concurso_titulo varchar(255) NOT NULL , ";
    $sql_concursos .= " concurso_desc text NOT NULL , ";
    $sql_concursos .= " concurso_inicio date NOT NULL , ";
    $sql_concursos .= " concurso_fim date NOT NULL , ";
    $sql_concursos .= " UNIQUE KEY concurso_id (concurso_id) ";
    $sql_concursos .= ") ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ";
    
    require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    dbDelta($sql_concursos);
    }
    
    if($wpdb->get_var("show tables like '$wp_criterios'") != $wp_criterios_table) {
    
    $sql_criterios = "CREATE TABLE ". $wp_criterios_table . " ( ";
    $sql_criterios .= " criterio_id int(11) NOT NULL auto_increment, ";
    $sql_criterios .= " criterio_descricao varchar(255) NOT NULL , ";
    $sql_criterios .= " criterio_peso int(2) NOT NULL , ";
    $sql_criterios .= " concurso_id int(11)NOT NULL , ";
    $sql_criterios .= ") ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ";
    
    require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    dbDelta($sql_criterios);
    }
    
    if($wpdb->get_var("show tables like '$wp_notas'") != $wp_notas_table) {
    
    $sql_notas = "CREATE TABLE ". $wp_notas_table . " ( ";
    $sql_notas .= " nota_id int(11) NOT NULL auto_increment, ";
    $sql_notas .= " concurso_id int(11) NOT NULL , ";
    $sql_notas .= " criterio_id int(11) NOT NULL auto_increment, ";
    $sql_notas .= " trabalho_id int(11) NOT NULL , ";
    $sql_notas .= " user_id int(11) NOT NULL auto_increment, ";
    $sql_notas .= " nota int(2) NOT NULL , ";
    $sql_notas .= ") ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ";
    
    require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    dbDelta($sql_notas);
    }
    
    function concurso_menu()
    {
    	if( function_exists('add_menu_page') ):
    
    		add_menu_page('Concurso','Concurso', 7, 'concurso/concurso-manager.php');
    	endif;
    	if ( function_exists('add_submenu_page') ) :
    
    		add_submenu_page('concurso/concurso-manager.php', 'Gerenciar', 	'Gerenciar',7, 'concurso/concurso-manager.php');
    		add_submenu_page('concurso/concurso-manager.php', 'Novo Concurso','Novo Concurso',7, 'concurso/concurso-add.php');
    		add_submenu_page('', 'Editar','Editar',7, 'concurso/concurso-edit.php');
    		add_submenu_page('', 'Visualizar','Visualizar',7, 'concurso/concurso-view.php');
    	endif;
    
    }
    
    add_action('admin_menu','concurso_menu');
    ?>

    Thanks!

  2. Are you activating this as a regular plugin?

  3. rbfabbri
    Member
    Posted 4 years ago #

    Hi Andrea_r

    I tried "Network activate" and only "Activate.

    In WPMU i had to include:

    require_once(ABSPATH.'wp-includes/pluggable.php');

    Because the following error occurred:

    Fatal error: Call to undefined function wp_get_current_user() in C:\xampp\xampp\htdocs\merchandising\wp-includes\capabilities.php on line 1059

    This is the only diference.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.