PHP code example of oblak / wp-plugin-installer

1. Go to this page and download the library: Download oblak/wp-plugin-installer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oblak / wp-plugin-installer example snippets



namespace Vendor\My_Plugin;

use Oblak\WP\Base_Plugin_Installer;

class My_Plugin_Installer extends Base_Plugin_Installer {

  /**
   * Singleton instance
   *
   * Since we're inheriting from a singleton class, we need to define this property.
   *
   * @var My_Plugin_Installer
   */
  protected static $instance;

  /**
   * Set the installer defaults.
   */
  protected function set_defaults() {
    $this->name          = 'My Plugin'; // Plugin name.
    $this->slug          = 'my-plugin'; // Plugin slug.
    $this->version       = '1.0.0';     // Plugin version (current).
    $this->db_version    = '1.0.0';     // Database schema version (current).
    $this->has_db_tables = true;        // Does the plugin have database tables?
  }

  /**
  * Get the database schema.
  *
  * @return string The database schema.
  */
  protected function get_schema() {
    global $wpdb;

      $collate = '';

      if ( $wpdb->has_cap( 'collation' ) ) {
          $collate = $wpdb->get_charset_collate();
      }

    return
    "
    CREATE TABLE `{$wpdb->prefix}my_plugin_table` (
      ID bigint(20) NOT NULL AUTO_INCREMENT,
      name varchar(255) NOT NULL,
      created_at datetime NOT NULL,
      PRIMARY KEY  (ID)
    ) {$collate}
    ";
  }

}







use Vendor\My_Plugin\My_Plugin_Installer;

My_Plugin_Installer::get_instance()->init();