WP init
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
use ElementsKit_Lite\Config\Module_List;
|
||||
use ElementsKit_Lite\Config\Widget_List;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Ajax {
|
||||
private $utils;
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_ekit_admin_action', array( $this, 'elementskit_admin_action' ) );
|
||||
add_action( 'wp_ajax_ekit_onboard_plugins', array( $this, 'elementskit_onboard_plugins' ) );
|
||||
$this->utils = Utils::instance();
|
||||
}
|
||||
|
||||
public function elementskit_admin_action() {
|
||||
// Check for nonce security
|
||||
if (!isset($_POST['nonce']) || ! wp_verify_nonce( sanitize_key(wp_unslash($_POST['nonce'])), 'ajax-nonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_POST['widget_list'] ) ) {
|
||||
$widget_list = Widget_List::instance()->get_list();
|
||||
$widget_list_input = ! is_array( $_POST['widget_list'] ) ? array() : map_deep( wp_unslash( $_POST['widget_list'] ) , 'sanitize_text_field' );
|
||||
$widget_prepared_list = array();
|
||||
|
||||
foreach ( $widget_list as $widget_slug => $widget ) {
|
||||
if ( isset( $widget['package'] ) && $widget['package'] == 'pro-disabled' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$widget['status'] = ( in_array( $widget_slug, $widget_list_input ) ? 'active' : 'inactive' );
|
||||
|
||||
$widget_prepared_list[ $widget_slug ] = $widget;
|
||||
}
|
||||
|
||||
// Allow to filter widget status
|
||||
apply_filters( 'elementskit/widgets/status/update', $widget_prepared_list );
|
||||
|
||||
$this->utils->save_option( 'widget_list', $widget_prepared_list );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['module_list'] ) ) {
|
||||
$module_list = Module_List::instance()->get_list( 'optional' );
|
||||
$module_list_input = ! is_array( $_POST['module_list'] ) ? array() : map_deep( wp_unslash( $_POST['module_list'] ) , 'sanitize_text_field' );
|
||||
$module_prepared_list = array();
|
||||
|
||||
foreach ( $module_list as $module_slug => $module ) {
|
||||
if ( isset( $module['package'] ) && $module['package'] == 'pro-disabled' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$module['status'] = ( in_array( $module_slug, $module_list_input ) ? 'active' : 'inactive' );
|
||||
|
||||
$module_prepared_list[ $module_slug ] = $module;
|
||||
}
|
||||
|
||||
$this->utils->save_option( 'module_list', $module_prepared_list );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['user_data'] ) ) {
|
||||
$this->utils->save_option( 'user_data', empty( $_POST['user_data'] ) ? array() : map_deep( wp_unslash( $_POST['user_data'] ) , 'wp_filter_nohtml_kses' ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- It will sanitize by wp_filter_nohtml_kses function
|
||||
}
|
||||
|
||||
if ( isset( $_POST['settings'] ) ) {
|
||||
$this->utils->save_settings( empty( $_POST['settings'] ) ? array() : map_deep( wp_unslash( $_POST['settings'] ) , 'sanitize_text_field' ) );
|
||||
}
|
||||
|
||||
do_action( 'elementskit/admin/after_save' );
|
||||
|
||||
$response = array(
|
||||
'message' => self::plugin_activate_message( 'setup_configurations' )
|
||||
);
|
||||
|
||||
$plugins = !empty($_POST['our_plugins']) && is_array($_POST['our_plugins']) ? $_POST['our_plugins'] : [];
|
||||
if($plugins) {
|
||||
$total_plugins = count($plugins);
|
||||
$total_steps = 1 + $total_plugins;
|
||||
$percentage = ($total_steps > 0) ? (1 / $total_steps) * 100 : 100;
|
||||
$percentage = round($percentage);
|
||||
|
||||
$response['progress'] = $percentage;
|
||||
$response['plugins'] = $plugins;
|
||||
}
|
||||
|
||||
wp_send_json($response);
|
||||
|
||||
wp_die(); // this is required to terminate immediately and return a proper response
|
||||
}
|
||||
|
||||
public function elementskit_onboard_plugins() {
|
||||
// Check for nonce security
|
||||
if (!isset($_POST['nonce']) || ! wp_verify_nonce( sanitize_key(wp_unslash($_POST['nonce'])), 'ajax-nonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_slug'] ) ) : '';
|
||||
if ( isset( $plugin_slug ) && current_user_can('install_plugins') ) {
|
||||
$status = \ElementsKit_Lite\Libs\Framework\Classes\Plugin_Installer::single_install_and_activate( $plugin_slug );
|
||||
if ( is_wp_error( $status ) ) {
|
||||
wp_send_json_error( array( 'status' => false ) );
|
||||
} else {
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => self::plugin_activate_message( $plugin_slug )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function plugin_activate_message($plugin_slug) {
|
||||
$plugins_message = [
|
||||
'setup_configurations' => esc_html__('Setup Configurations', 'elementskit-lite'),
|
||||
'elementskit-lite/elementskit-lite.php' => esc_html__('Page Builder Elements Activated', 'elementskit-lite'),
|
||||
'getgenie/getgenie.php' => esc_html__('AI Content & SEO Tool Activated', 'elementskit-lite'),
|
||||
'shopengine/shopengine.php' => esc_html__('WooCommerce Builder Activated', 'elementskit-lite'),
|
||||
'metform/metform.php' => esc_html__('Form Builder Activated', 'elementskit-lite'),
|
||||
'emailkit/EmailKit.php' => esc_html__('Email Customizer Activated', 'elementskit-lite'),
|
||||
'wp-social/wp-social.php' => esc_html__('Social Integration Activated', 'elementskit-lite'),
|
||||
'wp-ultimate-review/wp-ultimate-review.php' => esc_html__('Review Management Activated', 'elementskit-lite'),
|
||||
'wp-fundraising-donation/wp-fundraising.php' => esc_html__('Fundraising & Donations', 'elementskit-lite'),
|
||||
'gutenkit-blocks-addon/gutenkit-blocks-addon.php' => esc_html__('Page Builder Blocks Activated', 'elementskit-lite'),
|
||||
'popup-builder-block/popup-builder-block.php' => esc_html__('Popup Builder Activated', 'elementskit-lite'),
|
||||
'table-builder-block/table-builder-block.php' => esc_html__('Table Builder Activated', 'elementskit-lite'),
|
||||
];
|
||||
|
||||
if ( array_key_exists( $plugin_slug, $plugins_message ) ) {
|
||||
return esc_html( $plugins_message[$plugin_slug] );
|
||||
} else {
|
||||
return esc_html__( 'Plugin Activated', 'elementskit-lite' );
|
||||
}
|
||||
}
|
||||
|
||||
public function return_json( $data ) {
|
||||
if ( is_array( $data ) || is_object( $data ) ) {
|
||||
return wp_json_encode( $data );
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
use ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Onboard_Status {
|
||||
|
||||
use Singleton;
|
||||
protected $optionKey = 'elements_kit_onboard_status';
|
||||
protected $optionValue = 'onboarded';
|
||||
|
||||
public function onboard() {
|
||||
|
||||
add_action( 'elementskit/admin/after_save', array( $this, 'ajax_action' ) );
|
||||
|
||||
if ( get_option( $this->optionKey ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* We are checking if the user current page is elementskit and if the user is not completing onboarding,
|
||||
* We are redirecting to the onboarding page.
|
||||
*/
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checking current page type. The page only can access admin. So nonce verification is not required.
|
||||
$param = isset( $_GET['ekit-onboard-steps'] ) ? sanitize_text_field( wp_unslash( $_GET['ekit-onboard-steps'] ) ) : null;
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checking current page post_type. The page only can access admin. So nonce verification is not required.
|
||||
$requestUri = ( isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : '' ) . ( isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '' );
|
||||
|
||||
if ( strpos( $requestUri, 'elementskit' ) !== false && is_admin() ) {
|
||||
if ( $param !== 'loaded' && ! get_option( $this->optionKey ) ) {
|
||||
wp_safe_redirect( $this->get_onboard_url() );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function ajax_action() {
|
||||
|
||||
if( empty( $_POST['nonce'] ) || !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'ajax-nonce' ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
// finish on-boarding
|
||||
$this->finish_onboard();
|
||||
|
||||
if ( ! empty( $_POST['settings']['newsletter_email'] ) && is_email( $_POST['settings']['newsletter_email'] ) ) {
|
||||
$data = array(
|
||||
'email' => sanitize_email( wp_unslash( $_POST['settings']['newsletter_email'] ) ),
|
||||
'slug' => 'elementskit-lite',
|
||||
);
|
||||
|
||||
$response = Plugin_Data_Sender::instance()->sendEmailSubscribeData( 'plugin-subscribe', $data );
|
||||
}
|
||||
}
|
||||
|
||||
private function get_onboard_url() {
|
||||
return add_query_arg(
|
||||
array(
|
||||
'page' => 'elementskit',
|
||||
'ekit-onboard-steps' => 'loaded',
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
}
|
||||
|
||||
public function redirect_onboard() {
|
||||
if ( ! get_option( $this->optionKey ) ) {
|
||||
wp_safe_redirect( $this->get_onboard_url() );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function exit_from_onboard() {
|
||||
if ( get_option( $this->optionKey ) ) {
|
||||
wp_safe_redirect( $this->get_plugin_url() );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private static function get_plugin_url() {
|
||||
return add_query_arg(
|
||||
array(
|
||||
'page' => 'elementskit',
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
}
|
||||
|
||||
public function finish_onboard() {
|
||||
if ( ! get_option( $this->optionKey ) ) {
|
||||
add_option( $this->optionKey, $this->optionValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
use ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Plugin_Data_Sender {
|
||||
use Singleton;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
private function getUrl( $route ) {
|
||||
return trailingslashit(\ElementsKit_Lite::api_url() . $route);
|
||||
}
|
||||
|
||||
public function sendEmailSubscribeData( $route, $data ) {
|
||||
return wp_remote_post(
|
||||
$this->getUrl( $route ),
|
||||
array(
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'Accept' => '*/*',
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'body' => wp_json_encode( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Plugin_Installer {
|
||||
|
||||
private $plugin_file;
|
||||
private $plugin_slug;
|
||||
|
||||
public function __construct( $plugin_file ) {
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->plugin_slug = dirname( $plugin_file );
|
||||
$this->initialize_filesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install and activate a plugin.
|
||||
*/
|
||||
public function install_and_activate() {
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
if ( is_plugin_active( $this->plugin_file ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->is_plugin_installed() ) {
|
||||
$ignore_silent_activation = ['popup-builder-block/popup-builder-block.php'];
|
||||
$silent = in_array( $this->plugin_file, $ignore_silent_activation ) ? false : true;
|
||||
|
||||
$activate = activate_plugin( $this->plugin_file, '', false, $silent );
|
||||
if ( ! is_wp_error( $activate ) ) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$this->install_plugin();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the plugin using WP_Upgrader.
|
||||
*/
|
||||
private function install_plugin() {
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
$plugin_info = $this->get_plugin_information( $this->plugin_slug );
|
||||
|
||||
if ( is_wp_error( $plugin_info ) || ! $plugin_info || empty( $plugin_info->download_link ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$skin = new \ElementsKit_Lite\Libs\Framework\Classes\Plugin_Skin();
|
||||
|
||||
$upgrader = new \Plugin_Upgrader( $skin );
|
||||
$upgrader->install( $plugin_info->download_link );
|
||||
|
||||
if ( $this->is_plugin_installed() ) {
|
||||
$ignore_silent_activation = ['popup-builder-block/popup-builder-block.php'];
|
||||
$silent = in_array( $this->plugin_file, $ignore_silent_activation ) ? false : true;
|
||||
|
||||
$activate = activate_plugin( $this->plugin_file, '', false, $silent );
|
||||
if ( ! is_wp_error( $activate ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin info from WordPress.org.
|
||||
*/
|
||||
private function get_plugin_information( $plugin_slug ) {
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
||||
|
||||
$api = plugins_api( 'plugin_information', [
|
||||
'slug' => $plugin_slug,
|
||||
'fields' => [
|
||||
'download_link' => true,
|
||||
],
|
||||
] );
|
||||
|
||||
return $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if plugin is installed.
|
||||
*/
|
||||
private function is_plugin_installed() {
|
||||
global $wp_filesystem;
|
||||
return $wp_filesystem->exists( WP_PLUGIN_DIR . '/' . $this->plugin_file );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init WordPress Filesystem API.
|
||||
*/
|
||||
private function initialize_filesystem() {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( ! function_exists( 'WP_Filesystem' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
}
|
||||
|
||||
WP_Filesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method to bulk install/activate multiple plugins.
|
||||
*/
|
||||
public static function single_install_and_activate( string $plugin_file ) {
|
||||
$installer = new self( $plugin_file );
|
||||
$installer->install_and_activate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method to bulk install/activate multiple plugins.
|
||||
*/
|
||||
public static function bulk_install_and_activate( array $plugin_files ) {
|
||||
foreach ( $plugin_files as $plugin_file ) {
|
||||
$installer = new self( $plugin_file );
|
||||
$installer->install_and_activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Silent skin to suppress all output during installation
|
||||
*/
|
||||
class Plugin_Skin extends \WP_Upgrader_Skin {
|
||||
public function header() {}
|
||||
public function footer() {}
|
||||
public function error($errors) {}
|
||||
public function feedback($string, ...$args) {}
|
||||
public function before() {}
|
||||
public function after() {}
|
||||
public function bulk_header() {}
|
||||
public function bulk_footer() {}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Plugin_Status {
|
||||
private static $instance;
|
||||
private $installedPlugins = array();
|
||||
private $activatedPlugins = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->collect_installed_plugins();
|
||||
$this->collect_activated_plugins();
|
||||
}
|
||||
|
||||
private function collect_installed_plugins() {
|
||||
foreach ( get_plugins() as $key => $plugin ) {
|
||||
array_push( $this->installedPlugins, $key );
|
||||
}
|
||||
}
|
||||
|
||||
private function collect_activated_plugins() {
|
||||
foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) {
|
||||
array_push( $this->activatedPlugins, $plugin );
|
||||
}
|
||||
}
|
||||
|
||||
public static function instance() {
|
||||
if ( ! static::$instance ) {
|
||||
static::$instance = new static();
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
public function get_installed_plugins() {
|
||||
return $this->installedPlugins;
|
||||
}
|
||||
|
||||
public function get_activated_plugins() {
|
||||
return $this->activatedPlugins;
|
||||
}
|
||||
|
||||
public function get_status( $name ) {
|
||||
$data = array(
|
||||
'url' => '',
|
||||
'activation_url' => '',
|
||||
'installation_url' => '',
|
||||
'title' => '',
|
||||
'status' => '',
|
||||
);
|
||||
|
||||
if ( $this->check_installed_plugin( $name ) ) {
|
||||
if ( $this->check_activated_plugin( $name ) ) {
|
||||
$data['title'] = __( 'Activated', 'elementskit-lite' );
|
||||
$data['status'] = 'activated';
|
||||
} else {
|
||||
$data['title'] = __( 'Activate Now', 'elementskit-lite' );
|
||||
$data['status'] = 'installed';
|
||||
$data['activation_url'] = $this->activation_url( $name );
|
||||
}
|
||||
} else {
|
||||
$data['title'] = __( 'Install Now', 'elementskit-lite' );
|
||||
$data['status'] = 'not_installed';
|
||||
$data['installation_url'] = $this->installation_url( $name );
|
||||
$data['activation_url'] = $this->activation_url( $name );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function check_installed_plugin( $name ) {
|
||||
return in_array( $name, $this->installedPlugins );
|
||||
}
|
||||
|
||||
public function check_activated_plugin( $name ) {
|
||||
return in_array( $name, $this->activatedPlugins );
|
||||
}
|
||||
|
||||
public function activation_url( $pluginName ) {
|
||||
|
||||
return wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'plugin' => $pluginName,
|
||||
'plugin_status' => 'all',
|
||||
'paged' => '1&s',
|
||||
),
|
||||
admin_url( 'plugins.php' )
|
||||
),
|
||||
'activate-plugin_' . $pluginName
|
||||
);
|
||||
}
|
||||
|
||||
public function installation_url( $pluginName ) {
|
||||
$action = 'install-plugin';
|
||||
$pluginSlug = $this->get_plugin_slug( $pluginName );
|
||||
|
||||
return wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => $action,
|
||||
'plugin' => $pluginSlug,
|
||||
),
|
||||
admin_url( 'update.php' )
|
||||
),
|
||||
$action . '_' . $pluginSlug
|
||||
);
|
||||
}
|
||||
|
||||
public function get_plugin_slug( $name ) {
|
||||
$split = explode( '/', $name );
|
||||
|
||||
return isset( $split[0] ) ? $split[0] : null;
|
||||
}
|
||||
|
||||
public function activated_url( $pluginName ) {
|
||||
return add_query_arg(
|
||||
array(
|
||||
'page' => $this->get_plugin_slug( $pluginName ),
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Libs\Framework\Classes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Utils {
|
||||
|
||||
public static $instance = null;
|
||||
private static $key = 'elementskit_options';
|
||||
|
||||
public static function get_dir() {
|
||||
return \ElementsKit_Lite::lib_dir() . 'framework/';
|
||||
}
|
||||
|
||||
public static function get_url() {
|
||||
return \ElementsKit_Lite::lib_url() . 'framework/';
|
||||
}
|
||||
|
||||
public function get_option( $key, $default = '' ) {
|
||||
$data_all = get_option( self::$key );
|
||||
return ( isset( $data_all[ $key ] ) && $data_all[ $key ] != '' ) ? $data_all[ $key ] : $default;
|
||||
}
|
||||
|
||||
public function save_option( $key, $value = '' ) {
|
||||
$data_all = get_option( self::$key, array() );
|
||||
$data_all[ $key ] = $value;
|
||||
update_option( 'elementskit_options', $data_all );
|
||||
}
|
||||
|
||||
public function get_settings( $key, $default = '' ) {
|
||||
$data_all = $this->get_option( 'settings', array() );
|
||||
return ( isset( $data_all[ $key ] ) && $data_all[ $key ] != '' ) ? $data_all[ $key ] : $default;
|
||||
}
|
||||
|
||||
public function save_settings( $new_data = '' ) {
|
||||
$data_old = $this->get_option( 'settings', array() );
|
||||
$data = array_merge( $data_old, $new_data );
|
||||
$this->save_option( 'settings', $data );
|
||||
}
|
||||
|
||||
/*
|
||||
-> this method used to check weather the widget active/deactive
|
||||
-> this method takes two paramitter 1. widget name 2. Active/deactive hook
|
||||
*/
|
||||
public function is_widget_active_class( $widget_name, $pro_active ) {
|
||||
if ( $pro_active ) {
|
||||
return 'label-' . $widget_name . ' attr-panel-heading';
|
||||
} else {
|
||||
return 'label-' . $widget_name . ' attr-panel-heading pro-disabled';
|
||||
}
|
||||
}
|
||||
|
||||
public function input( $input_options ) {
|
||||
$defaults = array(
|
||||
'type' => null,
|
||||
'name' => '',
|
||||
'value' => '',
|
||||
'class' => '',
|
||||
'label' => '',
|
||||
'info' => '',
|
||||
'disabled' => '',
|
||||
'options' => array(),
|
||||
);
|
||||
$input_options = array_merge( $defaults, $input_options );
|
||||
|
||||
if ( file_exists( self::get_dir() . 'controls/settings/' . $input_options['type'] . '.php' ) ) {
|
||||
extract( $input_options );
|
||||
include self::get_dir() . 'controls/settings/' . $input_options['type'] . '.php';
|
||||
}
|
||||
}
|
||||
|
||||
public static function strify( $str ) {
|
||||
return strtolower( preg_replace( '/[^A-Za-z0-9]/', '__', $str ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
|
||||
// Fire the class instance
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user