PHP code example of dark-kitt / wordpress-theme-vue

1. Go to this page and download the library: Download dark-kitt/wordpress-theme-vue 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/ */

    

dark-kitt / wordpress-theme-vue example snippets


/** debug */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

global $wpdb,
  $wp_rewrite,
  $pagenow;

$kitt_instance = KiTT\ThemeSetUp::get_instance();
$kitt_instance->set_up_theme(
  $wpdb,
  /** reqiured */
  $wp_rewrite,
  /** reqiured */
  $pagenow,
  /** reqiured */
  [
    'set_up' => [
      /** custom favicon, logos and login logo url */
      'favicon' => $kitt_instance->theme_url . '/src/assets/icons/vue-icon.png',
      'login_logo' => $kitt_instance->theme_url . '/src/assets/icons/vue-icon.svg',
      'login_logo_url' => WP_HOME,
      'admin_bar_logo' => $kitt_instance->theme_url . '/src/assets/icons/vue-icon.svg',
      'permalink_structure' => '/%postname%/',
      'default_user_role' => 'editor',
      /** add or remove company settings menu page */
      'company_settings' => false
    ]
  ]
);

$kitt_instance->post([
  /** removes completely the default post section */
  'remove_post' => true
]);

$kitt_instance->page([
  'page' => [
    /**
     * info:
     * https://developer.wordpress.org/reference/functions/remove_post_type_support/
     * 
     * NOTE:
     * Gutenberg editor is always disabled
     */
    'remove_support' => ['excerpt', 'comments', 'trackbacks', 'author'],
    /** inspect the label attribute for="" in the screen options panel */
    'remove_meta_box' => ['commentsdiv', 'slugdiv'],
    /** en- or disable the SEO meta box */
    'SEO' => true,
    /** to enable tag support */
    'tag' => true,
    /** to enable category support */
    'category' => false
  ]
]);

$kitt_instance->attachment([
  'attachment' => [
    /** to enable tag support */
    'tag' => false,
    /** to enable category support */
    'category' => false,
    /** enable search duplicates support */
    'search_duplicates' => true
  ],
  /** 
   * set custom upload mimes
   * 
   * extend_defaults = true|false
   * true = merges the default upload mimes
   * false = replaces the default upload mimes
   * 
   * list of defaulst:
   * https://developer.wordpress.org/reference/functions/get_allowed_mime_types/
   */
  'upload_mimes' => [
    'extend_defaults' => true,
    'jpg|jpeg|jpe' => 'image/jpeg',
    'gif' => 'image/gif',
    'png' => 'image/png',
    /**
     * NOTE:
     * the XML declaration is 

$kitt_instance->REST_API([
  'rest_api' => [
    /**
     * set the namespace for your routes
     * => api.example.com/wp-json/->namespace<-/endpoint
     */
    'namespace' => explode('.', parse_url(WP_HOME)['host'])[0],
    /** removes the default REST API */
    'remove_default' => true,
    /**
     * examples:
     * 'Access-Control-Allow-Origin: ' . WP_HOME
     * 'Access-Control-Allow-Methods: POST, GET'
     * 'Access-Control-Allow-Credentials: true'
     * 'Access-Control-Max-Age: 600'
     */
    'headers' => [
      'Access-Control-Allow-Headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type',
      'Access-Control-Allow-Origin: ' . WP_HOME,
      'Access-Control-Allow-Methods: POST, GET',
      'Access-Control-Allow-Credentials: true',
      'Access-Control-Max-Age: 600'
    ],
    /** JWT token arguments */
    'token' => [
      'expiration_time' => time() + (DAY_IN_SECONDS * 7),
      'header' => 'Access-Control-Allow-Headers, Access-Control-Allow-Origin, Content-Type, Authorization'
    ]
  ]
]);

/**
 * register the /token endpoint to retrieve
 * the token from JWT Authentication for WP REST API
 */
$kitt_instance->rest_routes['token'] = [
  /**
   * class WP_REST_Server {
   * ...
   *   const READABLE = 'GET';
   *   const CREATABLE = 'POST';
   * ...
   * }
   * 
   * \WP_REST_Server::READABLE === GET
   * 
   * documentation
   * https://developer.wordpress.org/reference/classes/wp_rest_server/
   */
  'methods'  => \WP_REST_Server::READABLE,
  'callback' => 'get_token',
  // set the permission to public
  'permission_callback' => '__return_true',
  // the args key is l_close($ch);
  } catch (Exception $e) {
    $response = $e->getMessage();
  }
  // return the data
  return new \WP_REST_Response(json_decode($response), 200);
};

/**
 * update email route arguments
 * set server settings
 *
 * update values with WP constants
 * or set your custom settings
 */
$kitt_instance->rest_routes['email']['args']['host'] = ['default' => constant('SMTP_HOST')]; // 'smtp.gmail.com'
$kitt_instance->rest_routes['email']['args']['SMTP_auth'] = ['default' => constant('SMTP_AUTH')]; // boolean
$kitt_instance->rest_routes['email']['args']['username'] = ['default' => constant('SMTP_USERNAME')]; // '[email protected]'
/** 
 * use google app password:
 * https://support.google.com/accounts/answer/185833?hl=en
 */
$kitt_instance->rest_routes['email']['args']['password'] = ['default' => constant('SMTP_PASSWORD')]; // 'app-password'
$kitt_instance->rest_routes['email']['args']['SMTP_secure'] = ['default' => constant('SMTP_SECURE')]; // 'tls'
$kitt_instance->rest_routes['email']['args']['port'] = ['default' => constant('SMTP_PORT')]; // 587
/** PHPMailer debug */
$kitt_instance->rest_routes['email']['args']['debug'] = ['default' => false];
/**
 * test PHPMailer and send a mail to your own account via
 * http://api.example.com/wp-json/->namespace<-/email
 */
$kitt_instance->rest_routes['email']['args']['set_from'] = ['default' => [
  'address' => constant('SMTP_USERNAME'),
  'name' => 'Foo'
]];
$kitt_instance->rest_routes['email']['args']['add_address'] = ['default' => [[
  'address' => constant('SMTP_USERNAME'),
  'name' => 'Bar'
]]];

// enqueue scripts and styles
add_action('wp_enqueue_scripts', function () {
  if (file_exists('./www/assets-manifest.json')) {
    $manifest = json_decode(file_get_contents('./www/assets-manifest.json'));
    foreach ($manifest as $key => $value) {
      if ($key == 'entrypoints') {
        foreach ($value->main->assets->js as $js_file) {
          $js_file_info = pathinfo($js_file);
          // replace [hash].bundle.min for tag <script id="$id" ...
          $id = preg_replace('/(|\.\w+)\.bundle\.min/', '', $js_file_info['filename']);
          // enqueue the main.bundle.js file at the end of the DOM
          wp_enqueue_script($id, WP_HOME . '/www/' . $js_file, [], false, str_contains($js_file_info['filename'], 'main'));
        }

        foreach ($value->main->assets->css as $css_file) {
          $css_file_info = pathinfo($css_file);
          // replace [hash].bundle.min for tag <link id="$id" ...
          $id = preg_replace('/(|\.\w+)\.bundle\.min/', '', $css_file_info['filename']);
          wp_enqueue_style($id, WP_HOME . '/www/' . $css_file, [], false, 'screen');
        }
      }
    }
  }
});

<script>
const TOKEN_DATA = <?= json_encode($kitt_instance->get_token()->data, JSON_PRETTY_PRINT) 


// Load WordPress for access of internal functions
ipts', function () {
  if (file_exists('./www/assets-manifest.json')) {
    $manifest = json_decode(file_get_contents('./www/assets-manifest.json'));
    foreach ($manifest as $key => $value) {
      if ($key == 'entrypoints') {
        foreach ($value->main->assets->js as $js_file) {
          $js_file_info = pathinfo($js_file);
          // replace [hash].bundle.min for tag <script id="$id" ...
          $id = preg_replace('/(|\.\w+)\.bundle\.min/', '', $js_file_info['filename']);
          // enqueue the main.bundle.js file at the end of the DOM
          wp_enqueue_script($id, WP_HOME . '/www/' . $js_file, [], false, str_contains($js_file_info['filename'], 'main'));
        }

        foreach ($value->main->assets->css as $css_file) {
          $css_file_info = pathinfo($css_file);
          // replace [hash].bundle.min for tag <link id="$id" ...
          $id = preg_replace('/(|\.\w+)\.bundle\.min/', '', $css_file_info['filename']);
          wp_enqueue_style($id, WP_HOME . '/www/' . $css_file, [], false, 'screen');
        }
      }
    }
  }
});

get_header();
shell
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'%' WITH GRANT OPTION;