Initial commit: Atomaste website
This commit is contained in:
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
/**
|
||||
* Astra Admin Ajax Base.
|
||||
*
|
||||
* @package Astra
|
||||
* @since 4.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Astra_Admin_Ajax.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Astra_Admin_Ajax {
|
||||
|
||||
/**
|
||||
* Ajax action prefix.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $prefix = 'astra';
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @var null $instance
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
/** @psalm-suppress InvalidPropertyAssignmentValue */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
self::$instance = new self();
|
||||
/** @psalm-suppress InvalidPropertyAssignmentValue */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Errors class instance.
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $errors = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action(
|
||||
'init',
|
||||
function() {
|
||||
$this->errors = array(
|
||||
'permission' => esc_html__( 'Sorry, you are not allowed to do this operation.', 'astra' ),
|
||||
'nonce' => esc_html__( 'Nonce validation failed', 'astra' ),
|
||||
'default' => esc_html__( 'Sorry, something went wrong.', 'astra' ),
|
||||
'invalid' => esc_html__( 'No post data found!', 'astra' ),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
add_action( 'wp_ajax_ast_disable_pro_notices', array( $this, 'disable_astra_pro_notices' ) );
|
||||
add_action( 'wp_ajax_astra_recommended_plugin_install', 'wp_ajax_install_plugin' );
|
||||
add_action( 'wp_ajax_ast_migrate_to_builder', array( $this, 'migrate_to_builder' ) );
|
||||
add_action( 'wp_ajax_astra_update_admin_setting', array( $this, 'astra_update_admin_setting' ) );
|
||||
add_action( 'wp_ajax_astra_recommended_plugin_activate', array( $this, 'required_plugin_activate' ) );
|
||||
add_action( 'wp_ajax_astra_recommended_plugin_deactivate', array( $this, 'required_plugin_deactivate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return boolean settings for admin dashboard app.
|
||||
*
|
||||
* @return array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function astra_admin_settings_typewise() {
|
||||
return apply_filters(
|
||||
'astra_admin_settings_datatypes',
|
||||
array(
|
||||
'self_hosted_gfonts' => 'bool',
|
||||
'preload_local_fonts' => 'bool',
|
||||
'use_old_header_footer' => 'bool',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable pro upgrade notice from all over in Astra.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function disable_astra_pro_notices() {
|
||||
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
if ( empty( $_POST ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonce verification.
|
||||
*/
|
||||
if ( ! check_ajax_referer( 'astra_update_admin_setting', 'security', false ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( esc_html__( 'You don\'t have the access', 'astra' ) );
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$migrate = isset( $_POST['status'] ) ? sanitize_key( $_POST['status'] ) : '';
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
|
||||
$migrate = ( 'true' === $migrate ) ? true : false;
|
||||
astra_update_option( 'ast-disable-upgrade-notices', $migrate );
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate to New Header Builder
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function migrate_to_builder() {
|
||||
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
if ( empty( $_POST ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonce verification.
|
||||
*/
|
||||
if ( ! check_ajax_referer( 'astra_update_admin_setting', 'security', false ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$migrate = isset( $_POST['status'] ) ? sanitize_key( $_POST['status'] ) : '';
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$migrate = ( 'true' === $migrate ) ? true : false;
|
||||
/** @psalm-suppress InvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$migration_flag = astra_get_option( 'v3-option-migration', false );
|
||||
astra_update_option( 'is-header-footer-builder', $migrate );
|
||||
|
||||
if ( $migrate && false === $migration_flag ) {
|
||||
require_once ASTRA_THEME_DIR . 'inc/theme-update/astra-builder-migration-updater.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
|
||||
astra_header_builder_migration();
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings.
|
||||
*
|
||||
* @return void
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function astra_update_admin_setting() {
|
||||
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
if ( empty( $_POST ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonce verification.
|
||||
*/
|
||||
if ( ! check_ajax_referer( 'astra_update_admin_setting', 'security', false ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
$get_bool_settings = $this->astra_admin_settings_typewise();
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$sub_option_key = isset( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : '';
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$sub_option_value = '';
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
if ( isset( $get_bool_settings[ $sub_option_key ] ) ) {
|
||||
if ( 'bool' === $get_bool_settings[ $sub_option_key ] ) {
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$val = isset( $_POST['value'] ) && 'true' === sanitize_text_field( $_POST['value'] ) ? true : false;
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$sub_option_value = $val;
|
||||
} else {
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$sub_option_value = $val;
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
Astra_API_Init::update_admin_settings_option( $sub_option_key, $sub_option_value );
|
||||
|
||||
$response_data = array(
|
||||
'message' => esc_html__( 'Successfully saved data!', 'astra' ),
|
||||
);
|
||||
|
||||
wp_send_json_success( $response_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ajax error message.
|
||||
*
|
||||
* @param string $type Message type.
|
||||
* @return string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function get_error_msg( $type ) {
|
||||
|
||||
if ( ! isset( $this->errors[ $type ] ) ) {
|
||||
$type = 'default';
|
||||
}
|
||||
|
||||
return $this->errors[ $type ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Required Plugin Activate
|
||||
*
|
||||
* @since 1.2.4
|
||||
*/
|
||||
public function required_plugin_activate() {
|
||||
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
if ( empty( $_POST ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonce verification.
|
||||
*/
|
||||
if ( ! check_ajax_referer( 'astra_plugin_manager_nonce', 'security', false ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! sanitize_text_field( wp_unslash( $_POST['init'] ) ) ) {
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => esc_html__( 'No plugin specified', 'astra' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$plugin_init = ( isset( $_POST['init'] ) ) ? sanitize_text_field( wp_unslash( $_POST['init'] ) ) : '';
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
|
||||
$activate = activate_plugin( $plugin_init );
|
||||
|
||||
if ( is_wp_error( $activate ) ) {
|
||||
/** @psalm-suppress PossiblyNullReference */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => $activate->get_error_message(),
|
||||
)
|
||||
);
|
||||
/** @psalm-suppress PossiblyNullReference */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
}
|
||||
|
||||
/**
|
||||
* Added this flag as tracker to track onboarding and funnel stats for SureCart owners.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*/
|
||||
if ( 'surecart/surecart.php' === $plugin_init ) {
|
||||
update_option( 'surecart_source', 'astra', false );
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'success' => true,
|
||||
'message' => esc_html__( 'Plugin Successfully Activated', 'astra' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required Plugin Activate
|
||||
*
|
||||
* @since 1.2.4
|
||||
*/
|
||||
public function required_plugin_deactivate() {
|
||||
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
if ( empty( $_POST ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonce verification.
|
||||
*/
|
||||
if ( ! check_ajax_referer( 'astra_plugin_manager_nonce', 'security', false ) ) {
|
||||
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
|
||||
wp_send_json_error( $response_data );
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! sanitize_text_field( wp_unslash( $_POST['init'] ) ) ) {
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => esc_html__( 'No plugin specified', 'astra' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$plugin_init = ( isset( $_POST['init'] ) ) ? sanitize_text_field( wp_unslash( $_POST['init'] ) ) : '';
|
||||
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
|
||||
$deactivate = deactivate_plugins( $plugin_init );
|
||||
|
||||
if ( is_wp_error( $deactivate ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => $deactivate->get_error_message(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'success' => true,
|
||||
'message' => esc_html__( 'Plugin Successfully Deactivated', 'astra' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Astra_Admin_Ajax::get_instance();
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Astra_API_Init.
|
||||
*
|
||||
* @package Astra
|
||||
* @since 4.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
// Bail if WP_REST_Controller class does not exist.
|
||||
if ( ! class_exists( 'WP_REST_Controller' ) ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Astra_API_Init.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
class Astra_API_Init extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @var null $instance
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'astra/v1';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = '/admin/settings/';
|
||||
|
||||
/**
|
||||
* Option name
|
||||
*
|
||||
* @var string $option_name DB option name.
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private static $option_name = 'astra_admin_settings';
|
||||
|
||||
/**
|
||||
* Admin settings dataset
|
||||
*
|
||||
* @var array $astra_admin_settings Settings array.
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private static $astra_admin_settings = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
self::$astra_admin_settings = get_option( self::$option_name, array() );
|
||||
|
||||
// REST API extensions init.
|
||||
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register API routes.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
$this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_admin_settings' ),
|
||||
'permission_callback' => array( $this, 'get_permissions_check' ),
|
||||
'args' => array(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get common settings.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return array $updated_option defaults + set DB option data.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function get_admin_settings( $request ) {
|
||||
$db_option = get_option( 'astra_admin_settings', array() );
|
||||
|
||||
$defaults = apply_filters(
|
||||
'astra_dashboard_rest_options',
|
||||
array(
|
||||
'self_hosted_gfonts' => self::get_admin_settings_option( 'self_hosted_gfonts', false ),
|
||||
'preload_local_fonts' => self::get_admin_settings_option( 'preload_local_fonts', false ),
|
||||
'use_old_header_footer' => astra_get_option( 'is-header-footer-builder', false ),
|
||||
'use_upgrade_notices' => astra_showcase_upgrade_notices(),
|
||||
)
|
||||
);
|
||||
|
||||
$updated_option = wp_parse_args( $db_option, $defaults );
|
||||
return $updated_option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given request has permission to read notes.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|boolean
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function get_permissions_check( $request ) {
|
||||
|
||||
if ( ! current_user_can( 'edit_theme_options' ) ) {
|
||||
return new WP_Error( 'astra_rest_cannot_view', esc_html__( 'Sorry, you cannot list resources.', 'astra' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an value,
|
||||
* based on the settings database option for the admin settings page.
|
||||
*
|
||||
* @param string $key The sub-option key.
|
||||
* @param mixed $default Option default value if option is not available.
|
||||
* @return mixed Return the option value based on provided key
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function get_admin_settings_option( $key, $default = false ) {
|
||||
$value = isset( self::$astra_admin_settings[ $key ] ) ? self::$astra_admin_settings[ $key ] : $default;
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an value of a key,
|
||||
* from the settings database option for the admin settings page.
|
||||
*
|
||||
* @param string $key The option key.
|
||||
* @param mixed $value The value to update.
|
||||
* @return mixed Return the option value based on provided key
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function update_admin_settings_option( $key, $value ) {
|
||||
$astra_admin_updated_settings = get_option( self::$option_name, array() );
|
||||
$astra_admin_updated_settings[ $key ] = $value;
|
||||
update_option( self::$option_name, $astra_admin_updated_settings );
|
||||
}
|
||||
}
|
||||
|
||||
Astra_API_Init::get_instance();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Site Builder Free Version Preview.
|
||||
*
|
||||
* @package Astra
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Astra_Theme_Builder_Free' ) ) {
|
||||
|
||||
define( 'ASTRA_THEME_BUILDER_FREE_DIR', ASTRA_THEME_DIR . 'admin/assets/theme-builder/' );
|
||||
define( 'ASTRA_THEME_BUILDER_FREE_URI', ASTRA_THEME_URI . 'admin/assets/theme-builder/' );
|
||||
|
||||
/**
|
||||
* Site Builder initial setup.
|
||||
*
|
||||
* @since 4.5.0
|
||||
*/
|
||||
class Astra_Theme_Builder_Free {
|
||||
|
||||
/**
|
||||
* Member Variable
|
||||
*
|
||||
* @var null $instance
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 4.5.0
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
/** @psalm-suppress InvalidPropertyAssignmentValue */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
self::$instance = new self();
|
||||
/** @psalm-suppress InvalidPropertyAssignmentValue */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$is_astra_addon_active = ( defined( 'ASTRA_EXT_VER' ) );
|
||||
if ( ! $is_astra_addon_active ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'theme_builder_admin_enqueue_scripts' ) );
|
||||
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
|
||||
add_action( 'admin_menu', array( $this, 'setup_menu' ) );
|
||||
add_action( 'admin_init', array( $this, 'astra_theme_builder_disable_notices' ) );
|
||||
}
|
||||
add_action( 'admin_page_access_denied', array( $this, 'astra_theme_builder_access_denied_redirect' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @return void
|
||||
*/
|
||||
public function theme_builder_admin_enqueue_scripts() {
|
||||
$file_prefix = '';
|
||||
if ( is_rtl() ) {
|
||||
$file_prefix .= '.rtl';
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'astra-theme-builder-style', ASTRA_THEME_BUILDER_FREE_URI . 'build/index' . $file_prefix . '.css', array(), ASTRA_THEME_VERSION );
|
||||
|
||||
wp_enqueue_script( 'astra-theme-builder-script', ASTRA_THEME_BUILDER_FREE_URI . 'build/index.js', array( 'wp-element' ), ASTRA_THEME_VERSION, true );
|
||||
|
||||
wp_enqueue_style( 'dashicons' );
|
||||
|
||||
$localized_data = array(
|
||||
'title' => esc_html__( 'Site Builder', 'astra' ),
|
||||
'rest_url' => '/wp-json/astra-addon/v1/custom-layouts/',
|
||||
'new_custom_layout_base_url' => admin_url( 'post-new.php?post_type=astra-advanced-hook' ),
|
||||
'astra_pricing_page_url' => ASTRA_PRO_UPGRADE_URL,
|
||||
'astra_docs_page_url' => 'https://wpastra.com/docs/custom-layouts-pro/',
|
||||
'admin_url' => admin_url(),
|
||||
);
|
||||
|
||||
wp_localize_script( 'astra-theme-builder-script', 'astra_theme_builder', $localized_data );
|
||||
wp_set_script_translations( 'astra-theme-builder-script', 'astra' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Body Classes
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @param string $classes Space separated class string.
|
||||
*/
|
||||
public function admin_body_class( $classes = '' ) {
|
||||
$theme_builder_class = isset( $_GET['page'] ) && 'theme-builder-free' === $_GET['page'] ? 'ast-theme-builder' : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching a $_GET value, no nonce available to validate.
|
||||
$classes .= ' ' . $theme_builder_class . ' ';
|
||||
|
||||
return $classes;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the admin settings.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @return void
|
||||
*/
|
||||
public function render_theme_builder() {
|
||||
?>
|
||||
<div class="ast-tb-menu-page-wrapper">
|
||||
<div id="ast-tb-menu-page">
|
||||
<div class="ast-tb-menu-page-content">
|
||||
<div id="ast-tb-app-root" class="ast-tb-app-root"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup menu.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @return void
|
||||
*/
|
||||
public function setup_menu() {
|
||||
add_submenu_page( // phpcs:ignore WPThemeReview.PluginTerritory.NoAddAdminPages.add_menu_pages_add_submenu_page -- Taken the menu on top level
|
||||
'astra',
|
||||
__( 'Site Builder', 'astra' ),
|
||||
__( 'Site Builder', 'astra' ),
|
||||
'manage_options',
|
||||
'theme-builder-free',
|
||||
array( $this, 'render_theme_builder' ),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable notices for Site Builder page.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @return void
|
||||
*/
|
||||
public function astra_theme_builder_disable_notices() {
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching a $_GET value, no nonce available to validate.
|
||||
if ( isset( $_GET['page'] ) && 'theme-builder-free' === $_GET['page'] ) {
|
||||
remove_all_actions( 'admin_notices' );
|
||||
remove_all_actions( 'all_admin_notices' ); // For older versions of WordPress
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to Site Builder pro from free preview if pro module is active.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @return void
|
||||
*/
|
||||
public function astra_theme_builder_access_denied_redirect() {
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching a $_GET value, no nonce available to validate.
|
||||
if ( isset( $_GET['page'] ) && 'theme-builder-free' === $_GET['page'] ) {
|
||||
/** @psalm-suppress UndefinedClass */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
$is_astra_addon_active = ( defined( 'ASTRA_EXT_VER' ) && Astra_Ext_Extension::is_active( 'advanced-hooks' ) );
|
||||
/** @psalm-suppress UndefinedClass */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
|
||||
if ( $is_astra_addon_active ) {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=theme-builder' ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Theme_Builder_Free::get_instance();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user