Inpsyde\MultilingualPress\Database\WPDBTableInstaller::install PHP Метод

install() публичный Метод

Installs the given table.
С версии: 3.0.0
public install ( Inpsyde\MultilingualPress\Database\Table $table = null ) : boolean
$table Inpsyde\MultilingualPress\Database\Table Optional. Table object. Defaults to null.
Результат boolean Whether or not the table was installed successfully.
    public function install(Table $table = null)
    {
        $table = $table ?: $this->table;
        if (!$table) {
            throw InvalidTableException::for_action('install');
        }
        $table_name = $table->name();
        $schema = $table->schema();
        $columns = $this->get_columns($schema);
        $keys = $this->get_keys($table);
        $options = $this->get_options();
        /**
         * WordPress file with the dbDelta() function.
         */
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta("CREATE TABLE {$table_name} ({$columns}{$keys}) {$options}");
        if (!$this->table_exists($table_name)) {
            return false;
        }
        $this->insert_default_content($table);
        return true;
    }

Usage Example

 /**
  * @return void
  */
 public function reset_table()
 {
     \Inpsyde\MultilingualPress\check_admin_referer($this->nonce);
     $table_prefix = $this->wpdb->base_prefix;
     $table = new LanguagesTable($table_prefix);
     $installer = new WPDBTableInstaller($table);
     $installer->uninstall();
     $installer->install();
     /**
      * Runs after having reset the database table.
      *
      * @param Table $table Languages table object.
      */
     do_action('mlp_reset_table_done', $table);
     $url = add_query_arg('msg', 'resettable', $_REQUEST['_wp_http_referer']);
     wp_safe_redirect($url);
     \Inpsyde\MultilingualPress\call_exit();
 }