Initial commit: Atomaste website

This commit is contained in:
2025-12-10 12:17:30 -05:00
commit 0b9e5d1605
19260 changed files with 5206382 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '6e12b4be15a57c232c38');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,76 @@
import { __ } from "@wordpress/i18n";
import apiFetch from "@wordpress/api-fetch";
import DOMPurify from "dompurify";
import { classNames, getAstraProTitle, getSpinner } from "@astra-utils/helpers";
const ProButton = ({
className,
isLink = false,
url = astra_admin.upgrade_url,
children = getAstraProTitle(),
disableSpinner = false,
}) => {
const onGetAstraPro = (e) => {
e.preventDefault();
e.stopPropagation();
if (!astra_admin.pro_installed_status) {
window.open(url, "_blank");
}
e.target.innerHTML = DOMPurify.sanitize(
(disableSpinner ? "" : getSpinner()) +
astra_admin.plugin_activating_text
);
e.target.disabled = true;
const formData = new window.FormData();
formData.append("action", "astra_recommended_plugin_activate");
formData.append("security", astra_admin.plugin_manager_nonce);
formData.append("init", "astra-addon/astra-addon.php");
apiFetch({
url: astra_admin.ajax_url,
method: "POST",
body: formData,
})
.then((data) => {
if (data.success) {
window.open(astra_admin.astra_base_url, "_self");
}
})
.catch((error) => {
e.target.innerText = __(
"Activation failed. Please try again.",
"astra"
);
e.target.disabled = false;
console.error("Error during API request:", error);
// Optionally, notify the user about the error or handle it appropriately.
});
};
const Tag = isLink ? "a" : "button";
const linkProps = isLink && {
role: "button",
href: url,
target: "_blank",
rel: "noreferrer",
};
return (
<Tag
className={classNames(
"inline-flex items-center disabled:pointer-events-none",
className
)}
onClick={onGetAstraPro}
{...linkProps}
>
{children}
</Tag>
);
};
export default ProButton;

View File

@@ -0,0 +1,60 @@
import { classNames } from "@astra-utils/helpers";
const PromoCard = ({
className = "",
id,
icon,
title,
description,
linkHRef,
linkText,
children,
}) => {
return (
<section aria-labelledby={`section-${id}-title`}>
<h2 className="sr-only" id={`section-${id}-title`}>
{title}
</h2>
<div
className={classNames(
"relative box-border rounded-md bg-white shadow-sm overflow-hidden transition hover:shadow-hover",
className
)}
>
<div className="p-6">
{/* Card Icon */}
{icon && <span className="inline-block mb-2">{icon}</span>}
{/* Card Title */}
<h3 className="relative flex items-center text-slate-800 text-base font-semibold pb-2">
<span className="flex-1">{title}</span>
</h3>
{/* Card Description */}
{!children && (
<p className="text-slate-500 text-sm pb-5">
{description}
</p>
)}
{/* Card Content */}
{children}
{/* Card Link */}
{linkText && (
<a
className="text-sm text-astra focus:text-astra focus-visible:text-astra-hover active:text-astra-hover hover:text-astra-hover no-underline"
href={linkHRef}
target="_blank"
rel="noreferrer"
>
{linkText}
</a>
)}
</div>
</div>
</section>
);
};
export default PromoCard;

View File

@@ -0,0 +1,26 @@
const Star = ({ width = 20, height = 20, fill = "#000", className = "" }) => {
return (
<svg
className={className}
width={width}
height={height}
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clipPath="url(#clip0_2358_55923)">
<path
d="M9.04894 2.92705C9.3483 2.00574 10.6517 2.00574 10.9511 2.92705L12.0206 6.21885C12.1545 6.63087 12.5385 6.90983 12.9717 6.90983H16.4329C17.4016 6.90983 17.8044 8.14945 17.0207 8.71885L14.2205 10.7533C13.87 11.0079 13.7234 11.4593 13.8572 11.8713L14.9268 15.1631C15.2261 16.0844 14.1717 16.8506 13.388 16.2812L10.5878 14.2467C10.2373 13.9921 9.7627 13.9921 9.41221 14.2467L6.61204 16.2812C5.82833 16.8506 4.77385 16.0844 5.0732 15.1631L6.14277 11.8713C6.27665 11.4593 6.12999 11.0079 5.7795 10.7533L2.97933 8.71885C2.19562 8.14945 2.59839 6.90983 3.56712 6.90983H7.02832C7.46154 6.90983 7.8455 6.63087 7.97937 6.21885L9.04894 2.92705Z"
fill={fill}
/>
</g>
<defs>
<clipPath id="clip0_2358_55923">
<rect width={width} height={height} fill="white" />
</clipPath>
</defs>
</svg>
);
};
export default Star;

View File

@@ -0,0 +1,3 @@
import Star from "./Star";
export { Star };

View File

@@ -0,0 +1,4 @@
import ProButton from "./ProButton";
import PromoCard from "./PromoCard";
export { ProButton, PromoCard };

View File

@@ -0,0 +1,3 @@
import useDebounceEffect from "./useDebounceEffect";
export { useDebounceEffect };

View File

@@ -0,0 +1,25 @@
import { useEffect } from 'react';
import { debounce } from '@astra-utils/helpers';
/**
* A hook that wraps a callback function with a debounce effect.
*
* This hook is designed to delay the execution of a function until after a specified delay.
* It's particularly useful for handling events that occur rapidly, such as typing in a text input.
*
* @param {Function} callback - The function to debounce.
* @param {number} delay - The delay in milliseconds before the function is executed.
* @param {Array} dependencies - An array of dependencies that trigger the effect.
*/
function useDebounceEffect( callback, delay, dependencies ) {
useEffect( () => {
const debouncedCallback = debounce( callback, delay );
debouncedCallback();
// Cleanup on unmount or when dependencies change.
return () => debouncedCallback.cancel && debouncedCallback.cancel();
}, [ callback, delay, ...dependencies ] );
}
export default useDebounceEffect;

View File

@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-i18n'), 'version' => '18bae9fc371e45eda5f8');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,120 @@
import { __ } from "@wordpress/i18n";
import apiFetch from '@wordpress/api-fetch';
/**
* Returns the class names.
*
* @param {...string} classes The class names.
*
* @return {string} Returns the class names.
*/
const classNames = (...classes) => classes.filter(Boolean).join(" ");
/**
* Creates a debounced function that delays its execution until after the specified delay.
*
* The debounce() function can also be used from lodash.debounce package in future.
*
* @param {Function} func - The function to debounce.
* @param {number} delay - The delay in milliseconds before the function is executed.
*
* @returns {Function} A debounced function.
*/
const debounce = ( func, delay ) => {
let timer;
function debounced( ...args ) {
clearTimeout( timer );
timer = setTimeout( () => func( ...args ), delay );
};
// Attach a `cancel` method to clear the timeout.
debounced.cancel = () => {
clearTimeout( timer );
};
return debounced;
};
/**
* Returns the Astra Pro title.
*
* @return {string} Returns the Astra Pro title.
*/
const getAstraProTitle = () => {
return astra_admin.pro_installed_status
? __("Activate Now", "astra")
: __("Upgrade Now", "astra");
};
/**
* Returns the spinner SVG text.
*
* @return {string} Returns the spinner SVG text..
*/
const getSpinner = () => {
return `
<svg class="animate-spin installer-spinner" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
`;
};
/**
* A function to save astra admin settings.
*
* @function
*
* @param {string} key - Settings key.
* @param {string} value - The data to send.
* @param {Function} dispatch - The dispatch function.
* @param {Object} abortControllerRef - The ref object with to hold abort controller.
*
* @return {Promise} Returns a promise representing the processed request.
*/
const saveSetting = debounce(
(key, value, dispatch, abortControllerRef = { current: {} }) => {
// Abort any previous request.
if (abortControllerRef.current[key]) {
abortControllerRef.current[key]?.abort();
}
// Create a new AbortController.
const abortController = new AbortController();
abortControllerRef.current[key] = abortController;
const formData = new window.FormData();
formData.append("action", "astra_update_admin_setting");
formData.append("security", astra_admin.update_nonce);
formData.append("key", key);
formData.append("value", value);
return apiFetch({
url: astra_admin.ajax_url,
method: "POST",
body: formData,
signal: abortControllerRef.current[key]?.signal, // Pass the signal to the fetch request.
})
.then(() => {
dispatch({
type: "UPDATE_SETTINGS_SAVED_NOTIFICATION",
payload: __("Successfully saved!", "astra"),
});
})
.catch((error) => {
// Ignore if it is intentionally aborted.
if (error.name === "AbortError") {
return;
}
console.error("Error during API request:", error);
dispatch({
type: "UPDATE_SETTINGS_SAVED_NOTIFICATION",
payload: __("An error occurred while saving.", "astra"),
});
});
},
300
);
export { classNames, debounce, getAstraProTitle, getSpinner, saveSetting };

View File

@@ -0,0 +1,73 @@
<?php
/**
* Astra Admin Loader
*
* @package Astra
* @since 4.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'Astra_Admin_Loader' ) ) :
/**
* Astra_Admin_Loader
*
* @since 4.0.0
*/
class Astra_Admin_Loader {
/**
* 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;
}
/**
* Constructor
*
* @since 4.0.0
*/
public function __construct() {
define( 'ASTRA_THEME_ADMIN_DIR', ASTRA_THEME_DIR . 'admin/' );
define( 'ASTRA_THEME_ADMIN_URL', ASTRA_THEME_URI . 'admin/' );
$this->includes();
}
/**
* Include required classes.
*
* @since 4.0.0
*/
public function includes() {
/* Ajax init */
require_once ASTRA_THEME_ADMIN_DIR . 'includes/class-astra-admin-ajax.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound -- Not a template file so loading in a normal way.
/* Setup Menu */
require_once ASTRA_THEME_ADMIN_DIR . 'includes/class-astra-menu.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound -- Not a template file so loading in a normal way.
require_once ASTRA_THEME_ADMIN_DIR . 'includes/class-astra-theme-builder-free.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound -- Not a template file so loading in a normal way.
}
}
endif;
Astra_Admin_Loader::get_instance();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -0,0 +1,17 @@
{
"compilerOptions": {
"baseUrl": ".", // This makes the root directory of your project the base for relative paths
"paths": {
"@astra-hooks": [ "assets/hooks/index.js" ],
"@astra-hooks/*": [ "assets/hooks/*" ],
"@astra-components": [ "assets/components/index.js" ],
"@astra-components/*": [ "assets/components/*" ],
"@astra-utils/*": [ "assets/utils/*" ],
"@DashboardApp/*": [ "assets/src/dashboard-app/*" ],
"@Admin/*": [ "assets/src/*" ],
"@Utils/*": [ "assets/src/utils/*" ],
"@Skeleton/*": [ "assets/src/common/skeleton/*" ],
"@Common/*": [ "assets/src/common/*" ]
}
}
}