WP init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
use ElementsKit_Lite\Libs\Framework\Classes\Onboard_Status;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Activation_Actions {
|
||||
|
||||
private $key = 'elementskit-lite__plugin_activated';
|
||||
private $has_key = false;
|
||||
|
||||
public function init() {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->process_key();
|
||||
|
||||
if ( $this->has_key === false ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// call activation job classes or methods here.
|
||||
$this->flush_rewrite_rules();
|
||||
$this->redirect_to_onboard();
|
||||
}
|
||||
|
||||
private function process_key() {
|
||||
if ( ! empty( get_option( $this->key ) ) ) {
|
||||
$this->has_key = true;
|
||||
delete_option( $this->key );
|
||||
}
|
||||
}
|
||||
|
||||
private function flush_rewrite_rules() {
|
||||
// all CPTs must be declared completely before flushing rewrite rules. otherwise, it won't work as expected.
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
private function redirect_to_onboard() {
|
||||
// Onboard_Status::redirect_onboard();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Inline script registrar.
|
||||
*
|
||||
* Returns all necessary inline js & css.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
class Build_Inline_Scripts {
|
||||
|
||||
use \ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
function __construct() {
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_js' ) );
|
||||
add_action( 'admin_print_scripts', array( $this, 'admin_js' ) );
|
||||
}
|
||||
|
||||
|
||||
// scripts for common end, admin & frontend
|
||||
public function common_js() {
|
||||
ob_start(); ?>
|
||||
|
||||
var elementskit = {
|
||||
resturl: '<?php echo defined( 'ICL_SITEPRESS_VERSION' ) ? esc_url(home_url('/wp-json/elementskit/v1/')) : esc_url(get_rest_url() . 'elementskit/v1/'); ?>',
|
||||
}
|
||||
|
||||
<?php
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// scripts for frontend
|
||||
public function frontend_js() {
|
||||
$js = $this->common_js();
|
||||
wp_add_inline_script( 'elementskit-framework-js-frontend', $js );
|
||||
}
|
||||
|
||||
|
||||
// scripts for admin
|
||||
public function admin_js() {
|
||||
echo "<script type='text/javascript'>\n";
|
||||
echo \ElementsKit_Lite\Utils::render( $this->common_js() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Content already escaped in common_js() method
|
||||
echo "\n</script>";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
use ElementsKit_Lite\Libs\Framework\Attr;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Module registrar.
|
||||
*
|
||||
* Call assosiated classes of every modules.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
class Build_Modules {
|
||||
|
||||
private $modules;
|
||||
|
||||
use \ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
/**
|
||||
* Hold the module list.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
|
||||
public function __construct() {
|
||||
$this->modules = \ElementsKit_Lite\Config\Module_List::instance()->get_list( 'active' );
|
||||
|
||||
foreach ( $this->modules as $module_slug => $module ) {
|
||||
if ( isset( $module['path'] ) ) {
|
||||
include_once $module['path'] . 'init.php';
|
||||
}
|
||||
|
||||
// make the class name and call it.
|
||||
$class_name = (
|
||||
isset( $module['base_class_name'] )
|
||||
? $module['base_class_name']
|
||||
: '\ElementsKit_Lite\Modules\\' . \ElementsKit_Lite\Utils::make_classname( $module_slug ) . '\Init'
|
||||
);
|
||||
if ( class_exists( $class_name ) ) {
|
||||
new $class_name();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
use ElementsKit_Lite\Libs\Framework\Attr;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Build_Widgets {
|
||||
|
||||
/**
|
||||
* Collection of default widgets.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private $widgets;
|
||||
|
||||
use \ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
new \ElementsKit_Lite\Widgets\Init\Enqueue_Scripts();
|
||||
$this->widgets = \ElementsKit_Lite\Config\Widget_List::instance()->get_list( 'full' );
|
||||
|
||||
// check if the widget is exists
|
||||
foreach ( $this->widgets as $widget ) {
|
||||
$this->add_widget( $widget );
|
||||
}
|
||||
|
||||
add_action( 'elementor/widgets/register', array( $this, 'register_widget' ) );
|
||||
}
|
||||
|
||||
|
||||
public function add_widget( $widget_config ) {
|
||||
$widget_dir = (
|
||||
isset( $widget_config['path'] )
|
||||
? $widget_config['path']
|
||||
: \ElementsKit_Lite::widget_dir() . $widget_config['slug'] . '/'
|
||||
);
|
||||
|
||||
$widget_file_path = $widget_dir . $widget_config['slug'] . '.php';
|
||||
$widget_handler_file_path = $widget_dir . $widget_config['slug'] . '-handler.php';
|
||||
if (!file_exists($widget_file_path) && !file_exists($widget_handler_file_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
include $widget_file_path;
|
||||
include $widget_handler_file_path;
|
||||
|
||||
$base_class_name = (
|
||||
( isset( $widget_config['base_class_name'] ) )
|
||||
? $widget_config['base_class_name']
|
||||
: '\Elementor\ElementsKit_Widget_' . \ElementsKit_Lite\Utils::make_classname( $widget_config['slug'] )
|
||||
);
|
||||
|
||||
$handler = $base_class_name . '_Handler';
|
||||
$handler_class = new $handler();
|
||||
|
||||
if ( $handler_class->scripts() != false ) {
|
||||
add_action( 'wp_enqueue_scripts', array( $handler_class, 'scripts' ) );
|
||||
}
|
||||
|
||||
if ( $handler_class->styles() != false ) {
|
||||
add_action( 'wp_enqueue_scripts', array( $handler_class, 'styles' ) );
|
||||
}
|
||||
|
||||
if ( $handler_class->inline_css() != false ) {
|
||||
wp_add_inline_style( 'elementskit-init-css', $handler_class->inline_css() );
|
||||
}
|
||||
|
||||
if ( $handler_class->inline_js() != false ) {
|
||||
wp_add_inline_script( 'elementskit-init-js', $handler_class->inline_js() );
|
||||
}
|
||||
|
||||
if ( $handler_class->register_api() != false ) {
|
||||
if ( \file_exists( $handler_class->register_api() ) ) {
|
||||
include_once $handler_class->register_api();
|
||||
$api = $base_class_name . '_Api';
|
||||
new $api();
|
||||
}
|
||||
}
|
||||
|
||||
if ( $handler_class->wp_init() != false ) {
|
||||
add_action( 'init', array( $handler_class, 'wp_init' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function register_widget( $widgets_manager ) {
|
||||
foreach ( $this->widgets as $widget_slug => $widget ) {
|
||||
$class_name = '\Elementor\ElementsKit_Widget_' . \ElementsKit_Lite\Utils::make_classname( $widget_slug );
|
||||
if ( class_exists( $class_name ) ) {
|
||||
$widgets_manager->register( new $class_name() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
abstract class Config_List {
|
||||
|
||||
use \ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
private $full_list = array();
|
||||
private $active_list = array();
|
||||
|
||||
protected $optional_list = array();
|
||||
protected $required_list = array();
|
||||
|
||||
protected $type;
|
||||
|
||||
public function __construct() {
|
||||
$this->set_optional_list();
|
||||
$this->set_required_list();
|
||||
$this->set_full_list();
|
||||
$this->set_active_list();
|
||||
}
|
||||
|
||||
public function get_list( $data = 'full', $module = null ) {
|
||||
if ( $module != null ) {
|
||||
return ( $this->{$data . '_list'}[ $module ] ?? false );
|
||||
}
|
||||
|
||||
return $this->{$data . '_list'};
|
||||
}
|
||||
|
||||
public function is_active( $item ) {
|
||||
|
||||
$item = ( $this->active_list[ $item ] ?? array() );
|
||||
|
||||
return empty( $item['package'] ) ? false : ( ( $item['package'] == 'free' || $item['package'] == 'pro' ) );
|
||||
}
|
||||
|
||||
private function set_active_list() {
|
||||
$database_list = \ElementsKit_Lite\Libs\Framework\Attr::instance()->utils->get_option( $this->type . '_list', array() );
|
||||
|
||||
foreach ( $this->full_list as $key => $item ) {
|
||||
|
||||
if ( isset( $database_list[ $key ]['status'] ) && $database_list[ $key ]['status'] == 'inactive' && ! key_exists( $key, $this->required_list ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $item['package'] ) && $item['package'] == 'pro-disabled' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->active_list[ $key ] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
private function set_full_list() {
|
||||
$this->full_list = array_merge( $this->required_list, $this->optional_list );
|
||||
}
|
||||
|
||||
abstract protected function set_required_list();
|
||||
|
||||
abstract protected function set_optional_list();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
class Handler_Api {
|
||||
|
||||
public $prefix = '';
|
||||
public $param = '';
|
||||
public $request = null;
|
||||
|
||||
public function __construct() {
|
||||
$this->config();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function config() {
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action(
|
||||
'rest_api_init',
|
||||
function () {
|
||||
register_rest_route(
|
||||
untrailingslashit( 'elementskit/v1/' . $this->prefix ),
|
||||
'/(?P<action>\w+)/' . ltrim( $this->param, '/' ),
|
||||
array(
|
||||
'methods' => \WP_REST_Server::ALLMETHODS,
|
||||
'callback' => array( $this, 'callback' ),
|
||||
'permission_callback' => '__return_true',
|
||||
// all permissions are implimented inside the callback action
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function callback( $request ) {
|
||||
$this->request = $request;
|
||||
$action_class = strtolower( $this->request->get_method() ) . '_' . $this->request['action'];
|
||||
|
||||
if ( method_exists( $this, $action_class ) ) {
|
||||
return $this->{$action_class}();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Core;
|
||||
|
||||
class Handler_Widget {
|
||||
|
||||
public function wp_init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function get_name() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function get_title() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function get_icon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function get_categories() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function get_dir() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function get_url() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function register_api() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function inline_js() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function inline_css() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function sass() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function scripts() {
|
||||
return false;
|
||||
}
|
||||
public function styles() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user