New project structure init
This commit is contained in:
0
backend/app/plugins/.gitkeep
Normal file
0
backend/app/plugins/.gitkeep
Normal file
36
backend/app/plugins/wiaas/includes/class-wiaas-cli.php
Normal file
36
backend/app/plugins/wiaas/includes/class-wiaas-cli.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Enables running wiaas with wp cli commands
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* CLI class.
|
||||
*/
|
||||
class Wiaas_CLI {
|
||||
/**
|
||||
* Load required files and hooks to make the CLI work.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->includes();
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load command files.
|
||||
*/
|
||||
private function includes() {
|
||||
require_once dirname( __FILE__ ) . '/cli/class-wiaas-update-db-command.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up and hooks WP CLI to our CLI code.
|
||||
*/
|
||||
private function hooks() {
|
||||
WP_CLI::add_hook( 'after_wp_load', 'Wiaas_CLI_Update_DB_Command::register_commands' );
|
||||
}
|
||||
}
|
||||
|
||||
new Wiaas_CLI();
|
||||
27
backend/app/plugins/wiaas/includes/class-wiaas-db-update.php
Normal file
27
backend/app/plugins/wiaas/includes/class-wiaas-db-update.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Wiaas_DB_Update {
|
||||
|
||||
private static $db_updates = array(
|
||||
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role'
|
||||
);
|
||||
|
||||
public static function get_pending_db_updates() {
|
||||
$active_db_version = get_option( 'wiaas_db_version', '0' );
|
||||
$pending_db_updates = array();
|
||||
foreach (self::$db_updates as $version => $update_callback) {
|
||||
if ($active_db_version < $version) {
|
||||
$pending_db_updates[] = $update_callback;
|
||||
}
|
||||
}
|
||||
return $pending_db_updates;
|
||||
}
|
||||
|
||||
public static function execute_update($update_callback) {
|
||||
call_user_func($update_callback);
|
||||
$version = array_search($update_callback, self::$db_updates);
|
||||
update_option('wiaas_db_version', $version);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_CLI_Update_Command class file.
|
||||
*
|
||||
* @package Wiaas\CLI
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows updates via CLI.
|
||||
*
|
||||
* @version 3.0.0
|
||||
* @package WooCommerce
|
||||
*/
|
||||
class Wiaas_CLI_Update_DB_Command {
|
||||
|
||||
/**
|
||||
* Registers the setup command.
|
||||
*/
|
||||
public static function register_commands() {
|
||||
WP_CLI::add_command( 'wiaas update-db', array( 'Wiaas_CLI_Update_DB_Command', 'update' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all pending Wiaas db updates
|
||||
*/
|
||||
public static function update() {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->hide_errors();
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-db-update.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-functions.php';
|
||||
|
||||
$pending_db_updates = Wiaas_DB_Update::get_pending_db_updates();
|
||||
|
||||
foreach ( $pending_db_updates as $update_callback ) {
|
||||
/* translators: %s: DB update callback key */
|
||||
WP_CLI::log( sprintf( __( 'Executing update: %s', 'wiaas' ), $update_callback ) );
|
||||
Wiaas_DB_Update::execute_update($update_callback);
|
||||
}
|
||||
WP_CLI::success('DB update complete.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Wiaas DB updates
|
||||
*
|
||||
* Functions for updating database to latest version
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Enable restricting visibility by user roles for products
|
||||
*/
|
||||
function wiaas_db_update_enable_product_by_user_role() {
|
||||
update_option('wcj_product_by_user_role_enabled', 'yes');
|
||||
}
|
||||
23
backend/app/plugins/wiaas/wiaas.php
Normal file
23
backend/app/plugins/wiaas/wiaas.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Wiaas
|
||||
* Plugin URI: http://saburly.com
|
||||
* Description: Wiaas contains custom code for wiaas market place
|
||||
* Version: 1.0.0
|
||||
* Author: Saburly
|
||||
* Author URI: http://saburly.com
|
||||
* Text Domain: wiaas
|
||||
*/
|
||||
|
||||
if ( !defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
define( 'WIAAS_FILE', __FILE__ );
|
||||
define( 'WIAAS_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
|
||||
|
||||
|
||||
# CLI
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-cli.php';
|
||||
}
|
||||
Reference in New Issue
Block a user