first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,283 @@
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor settings controls.
*
* Elementor settings controls handler class responsible for creating the final
* HTML for various input field types used in Elementor settings pages.
*
* @since 1.0.0
*/
class Settings_Controls {
/**
* Render settings control.
*
* Generates the final HTML on the frontend for any given field based on
* the field type (text, select, checkbox, raw HTML, etc.).
*
* @since 1.0.0
* @access public
* @static
*
* @param array $field Optional. Field data. Default is an empty array.
*/
public static function render( $field = [] ) {
if ( empty( $field ) || empty( $field['id'] ) ) {
return;
}
$defaults = [
'type' => '',
'attributes' => [],
'std' => '',
'desc' => '',
];
$field = array_merge( $defaults, $field );
$method_name = $field['type'];
if ( ! method_exists( __CLASS__, $method_name ) ) {
$method_name = 'text';
}
self::$method_name( $field );
}
/**
* Render text control.
*
* Generates the final HTML for text controls.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function text( array $field ) {
if ( empty( $field['attributes']['class'] ) ) {
$field['attributes']['class'] = 'regular-text';
}
$attributes = Utils::render_html_attributes( $field['attributes'] );
?>
<input type="<?php echo esc_attr( $field['type'] ); ?>" id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['id'] ); ?>" value="<?php echo esc_attr( get_option( $field['id'], $field['std'] ) ); ?>" <?php echo $attributes; ?>/>
<?php
if ( ! empty( $field['sub_desc'] ) ) :
echo $field['sub_desc'];
endif;
?>
<?php if ( ! empty( $field['desc'] ) ) : ?>
<p class="description"><?php echo $field['desc']; ?></p>
<?php
endif;
}
/**
* Render checkbox control.
*
* Generates the final HTML for checkbox controls.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function checkbox( array $field ) {
?>
<label>
<input type="<?php echo esc_attr( $field['type'] ); ?>" id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['id'] ); ?>" value="<?php echo $field['value']; ?>"<?php checked( $field['value'], get_option( $field['id'], $field['std'] ) ); ?> />
<?php
if ( ! empty( $field['sub_desc'] ) ) :
echo $field['sub_desc'];
endif;
?>
</label>
<?php if ( ! empty( $field['desc'] ) ) : ?>
<p class="description"><?php echo $field['desc']; ?></p>
<?php
endif;
}
/**
* Render checkbox list control.
*
* Generates the final HTML for checkbox list controls.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function checkbox_list( array $field ) {
$old_value = get_option( $field['id'], $field['std'] );
if ( ! is_array( $old_value ) ) {
$old_value = [];
}
foreach ( $field['options'] as $option_key => $option_value ) :
?>
<label>
<input type="checkbox" name="<?php echo esc_attr( $field['id'] ); ?>[]" value="<?php echo esc_attr( $option_key ); ?>"<?php checked( in_array( $option_key, $old_value ), true ); ?> />
<?php echo $option_value; ?>
</label><br />
<?php endforeach; ?>
<?php if ( ! empty( $field['desc'] ) ) : ?>
<p class="description"><?php echo $field['desc']; ?></p>
<?php
endif;
}
/**
* Render select control.
*
* Generates the final HTML for select controls.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function select( array $field ) {
$old_value = get_option( $field['id'], $field['std'] );
?>
<select name="<?php echo esc_attr( $field['id'] ); ?>">
<?php if ( ! empty( $field['show_select'] ) ) : ?>
<option value="">— <?php echo __( 'Select', 'elementor' ); ?> —</option>
<?php endif; ?>
<?php foreach ( $field['options'] as $value => $label ) : ?>
<option value="<?php echo esc_attr( $value ); ?>"<?php selected( $value, $old_value ); ?>><?php echo $label; ?></option>
<?php endforeach; ?>
</select>
<?php if ( ! empty( $field['desc'] ) ) : ?>
<p class="description"><?php echo $field['desc']; ?></p>
<?php
endif;
}
/**
* Render checkbox list control for CPT.
*
* Generates the final HTML for checkbox list controls populated with Custom Post Types.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function checkbox_list_cpt( array $field ) {
$defaults = [
'exclude' => [],
];
$field = array_merge( $defaults, $field );
$post_types_objects = get_post_types(
[
'public' => true,
], 'objects'
);
/**
* Filters the list of post type objects used by Elementor.
*
* @since 2.8.0
*
* @param array $post_types_objects List of post type objects used by Elementor.
*/
$post_types_objects = apply_filters( 'elementor/settings/controls/checkbox_list_cpt/post_type_objects', $post_types_objects );
$field['options'] = [];
foreach ( $post_types_objects as $cpt_slug => $post_type ) {
if ( in_array( $cpt_slug, $field['exclude'], true ) ) {
continue;
}
$field['options'][ $cpt_slug ] = $post_type->labels->name;
}
self::checkbox_list( $field );
}
/**
* Render checkbox list control for user roles.
*
* Generates the final HTML for checkbox list controls populated with user roles.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function checkbox_list_roles( array $field ) {
$defaults = [
'exclude' => [],
];
$field = array_merge( $defaults, $field );
$field['options'] = [];
$roles = get_editable_roles();
if ( is_multisite() ) {
$roles = [
'super_admin' => [
'name' => __( 'Super Admin', 'elementor' ),
],
] + $roles;
}
foreach ( $roles as $role_slug => $role_data ) {
if ( in_array( $role_slug, $field['exclude'] ) ) {
continue;
}
$field['options'][ $role_slug ] = $role_data['name'];
}
self::checkbox_list( $field );
}
/**
* Render raw HTML control.
*
* Generates the final HTML for raw HTML controls.
*
* @since 2.0.0
* @access private
* @static
*
* @param array $field Field data.
*/
private static function raw_html( array $field ) {
if ( empty( $field['html'] ) ) {
return;
}
?>
<div id="<?php echo $field['id']; ?>">
<div><?php echo $field['html']; ?></div>
<?php
if ( ! empty( $field['sub_desc'] ) ) :
echo $field['sub_desc'];
endif;
?>
<?php if ( ! empty( $field['desc'] ) ) : ?>
<p class="description"><?php echo $field['desc']; ?></p>
<?php endif; ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,402 @@
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor settings page.
*
* An abstract class that provides the needed properties and methods to handle
* WordPress dashboard settings pages in inheriting classes.
*
* @since 1.0.0
* @abstract
*/
abstract class Settings_Page {
/**
* Settings page ID.
*/
const PAGE_ID = '';
/**
* Tabs.
*
* Holds the settings page tabs, sections and fields.
*
* @access private
*
* @var array
*/
private $tabs;
/**
* Create tabs.
*
* Return the settings page tabs, sections and fields.
*
* @since 1.5.0
* @access protected
* @abstract
*/
abstract protected function create_tabs();
/**
* Get settings page title.
*
* Retrieve the title for the settings page.
*
* @since 1.5.0
* @access protected
* @abstract
*/
abstract protected function get_page_title();
/**
* Get settings page URL.
*
* Retrieve the URL of the settings page.
*
* @since 1.5.0
* @access public
* @static
*
* @return string Settings page URL.
*/
final public static function get_url() {
return admin_url( 'admin.php?page=' . static::PAGE_ID );
}
/**
* Settings page constructor.
*
* Initializing Elementor settings page.
*
* @since 1.5.0
* @access public
*/
public function __construct() {
if ( ! empty( $_POST['option_page'] ) && static::PAGE_ID === $_POST['option_page'] ) {
add_action( 'admin_init', [ $this, 'register_settings_fields' ] );
}
}
/**
* Get tabs.
*
* Retrieve the settings page tabs, sections and fields.
*
* @since 1.5.0
* @access public
*
* @return array Settings page tabs, sections and fields.
*/
final public function get_tabs() {
$this->ensure_tabs();
return $this->tabs;
}
/**
* Add tab.
*
* Register a new tab to a settings page.
*
* @since 1.5.0
* @access public
*
* @param string $tab_id Tab ID.
* @param array $tab_args Optional. Tab arguments. Default is an empty array.
*/
final public function add_tab( $tab_id, array $tab_args = [] ) {
$this->ensure_tabs();
if ( isset( $this->tabs[ $tab_id ] ) ) {
// Don't override an existing tab
return;
}
if ( ! isset( $tab_args['sections'] ) ) {
$tab_args['sections'] = [];
}
$this->tabs[ $tab_id ] = $tab_args;
}
/**
* Add section.
*
* Register a new section to a tab.
*
* @since 1.5.0
* @access public
*
* @param string $tab_id Tab ID.
* @param string $section_id Section ID.
* @param array $section_args Optional. Section arguments. Default is an
* empty array.
*/
final public function add_section( $tab_id, $section_id, array $section_args = [] ) {
$this->ensure_tabs();
if ( ! isset( $this->tabs[ $tab_id ] ) ) {
// If the requested tab doesn't exists, use the first tab
$tab_id = key( $this->tabs );
}
if ( isset( $this->tabs[ $tab_id ]['sections'][ $section_id ] ) ) {
// Don't override an existing section
return;
}
if ( ! isset( $section_args['fields'] ) ) {
$section_args['fields'] = [];
}
$this->tabs[ $tab_id ]['sections'][ $section_id ] = $section_args;
}
/**
* Add field.
*
* Register a new field to a section.
*
* @since 1.5.0
* @access public
*
* @param string $tab_id Tab ID.
* @param string $section_id Section ID.
* @param string $field_id Field ID.
* @param array $field_args Field arguments.
*/
final public function add_field( $tab_id, $section_id, $field_id, array $field_args ) {
$this->ensure_tabs();
if ( ! isset( $this->tabs[ $tab_id ] ) ) {
// If the requested tab doesn't exists, use the first tab
$tab_id = key( $this->tabs );
}
if ( ! isset( $this->tabs[ $tab_id ]['sections'][ $section_id ] ) ) {
// If the requested section doesn't exists, use the first section
$section_id = key( $this->tabs[ $tab_id ]['sections'] );
}
if ( isset( $this->tabs[ $tab_id ]['sections'][ $section_id ]['fields'][ $field_id ] ) ) {
// Don't override an existing field
return;
}
$this->tabs[ $tab_id ]['sections'][ $section_id ]['fields'][ $field_id ] = $field_args;
}
/**
* Add fields.
*
* Register multiple fields to a section.
*
* @since 1.5.0
* @access public
*
* @param string $tab_id Tab ID.
* @param string $section_id Section ID.
* @param array $fields {
* An array of fields.
*
* @type string $field_id Field ID.
* @type array $field_args Field arguments.
* }
*/
final public function add_fields( $tab_id, $section_id, array $fields ) {
foreach ( $fields as $field_id => $field_args ) {
$this->add_field( $tab_id, $section_id, $field_id, $field_args );
}
}
/**
* Register settings fields.
*
* In each tab register his inner sections, and in each section register his
* inner fields.
*
* @since 1.5.0
* @access public
*/
final public function register_settings_fields() {
$controls_class_name = __NAMESPACE__ . '\Settings_Controls';
$tabs = $this->get_tabs();
foreach ( $tabs as $tab_id => $tab ) {
foreach ( $tab['sections'] as $section_id => $section ) {
$full_section_id = 'elementor_' . $section_id . '_section';
$label = isset( $section['label'] ) ? $section['label'] : '';
$section_callback = isset( $section['callback'] ) ? $section['callback'] : '__return_empty_string';
add_settings_section( $full_section_id, $label, $section_callback, static::PAGE_ID );
foreach ( $section['fields'] as $field_id => $field ) {
$full_field_id = ! empty( $field['full_field_id'] ) ? $field['full_field_id'] : 'elementor_' . $field_id;
$field['field_args']['id'] = $full_field_id;
$field_classes = [ $full_field_id ];
if ( ! empty( $field['class'] ) ) {
$field_classes[] = $field['field_args']['class'];
}
$field['field_args']['class'] = implode( ' ', $field_classes );
if ( ! isset( $field['render'] ) ) {
$field['render'] = [ $controls_class_name, 'render' ];
}
add_settings_field(
$full_field_id,
isset( $field['label'] ) ? $field['label'] : '',
$field['render'],
static::PAGE_ID,
$full_section_id,
$field['field_args']
);
$setting_args = [];
if ( ! empty( $field['setting_args'] ) ) {
$setting_args = $field['setting_args'];
}
register_setting( static::PAGE_ID, $full_field_id, $setting_args );
}
}
}
}
/**
* Display settings page.
*
* Output the content for the settings page.
*
* @since 1.5.0
* @access public
*/
public function display_settings_page() {
$this->register_settings_fields();
$tabs = $this->get_tabs();
?>
<div class="wrap">
<h1><?php echo $this->get_page_title(); ?></h1>
<div id="elementor-settings-tabs-wrapper" class="nav-tab-wrapper">
<?php
foreach ( $tabs as $tab_id => $tab ) {
if ( empty( $tab['sections'] ) ) {
continue;
}
$active_class = '';
if ( 'general' === $tab_id ) {
$active_class = ' nav-tab-active';
}
echo "<a id='elementor-settings-tab-{$tab_id}' class='nav-tab{$active_class}' href='#tab-{$tab_id}'>{$tab['label']}</a>";
}
?>
</div>
<form id="elementor-settings-form" method="post" action="options.php">
<?php
settings_fields( static::PAGE_ID );
foreach ( $tabs as $tab_id => $tab ) {
if ( empty( $tab['sections'] ) ) {
continue;
}
$active_class = '';
if ( 'general' === $tab_id ) {
$active_class = ' elementor-active';
}
echo "<div id='tab-{$tab_id}' class='elementor-settings-form-page{$active_class}'>";
foreach ( $tab['sections'] as $section_id => $section ) {
$full_section_id = 'elementor_' . $section_id . '_section';
if ( ! empty( $section['label'] ) ) {
echo "<h2>{$section['label']}</h2>";
}
if ( ! empty( $section['callback'] ) ) {
$section['callback']();
}
echo '<table class="form-table">';
do_settings_fields( static::PAGE_ID, $full_section_id );
echo '</table>';
}
echo '</div>';
}
submit_button();
?>
</form>
</div><!-- /.wrap -->
<?php
}
public function get_usage_fields() {
return [
'allow_tracking' => [
'label' => __( 'Usage Data Sharing', 'elementor' ),
'field_args' => [
'type' => 'checkbox',
'value' => 'yes',
'default' => '',
'sub_desc' => __( 'Become a super contributor by opting in to share non-sensitive plugin data and to receive periodic email updates from us.', 'elementor' ) . sprintf( ' <a href="%1$s" target="_blank">%2$s</a>', 'https://go.elementor.com/usage-data-tracking/', __( 'Learn more.', 'elementor' ) ),
],
'setting_args' => [ __NAMESPACE__ . '\Tracker', 'check_for_settings_optin' ],
],
];
}
/**
* Ensure tabs.
*
* Make sure the settings page has tabs before inserting any new sections or
* fields.
*
* @since 1.5.0
* @access private
*/
private function ensure_tabs() {
if ( null === $this->tabs ) {
$this->tabs = $this->create_tabs();
$page_id = static::PAGE_ID;
/**
* After create settings.
*
* Fires after the settings are created in Elementor admin page.
*
* The dynamic portion of the hook name, `$page_id`, refers to the current page ID.
*
* @since 1.0.0
*
* @param Settings_Page $this The settings page.
*/
do_action( "elementor/admin/after_create_settings/{$page_id}", $this );
}
}
}

View File

@@ -0,0 +1,611 @@
<?php
namespace Elementor;
use Elementor\Core\Upgrade\Manager as Upgrades_Manager;
use Elementor\TemplateLibrary\Source_Local;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor "Settings" page in WordPress Dashboard.
*
* Elementor settings page handler class responsible for creating and displaying
* Elementor "Settings" page in WordPress dashboard.
*
* @since 1.0.0
*/
class Settings extends Settings_Page {
/**
* Settings page ID for Elementor settings.
*/
const PAGE_ID = 'elementor';
/**
* Go Pro menu priority.
*/
const MENU_PRIORITY_GO_PRO = 502;
/**
* Settings page field for update time.
*/
const UPDATE_TIME_FIELD = '_elementor_settings_update_time';
/**
* Settings page general tab slug.
*/
const TAB_GENERAL = 'general';
/**
* Settings page style tab slug.
*/
const TAB_STYLE = 'style';
/**
* Settings page integrations tab slug.
*/
const TAB_INTEGRATIONS = 'integrations';
/**
* Settings page advanced tab slug.
*/
const TAB_ADVANCED = 'advanced';
/**
* Register admin menu.
*
* Add new Elementor Settings admin menu.
*
* Fired by `admin_menu` action.
*
* @since 1.0.0
* @access public
*/
public function register_admin_menu() {
global $menu;
$menu[] = [ '', 'read', 'separator-elementor', '', 'wp-menu-separator elementor' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
add_menu_page(
__( 'Elementor', 'elementor' ),
__( 'Elementor', 'elementor' ),
'manage_options',
self::PAGE_ID,
[ $this, 'display_settings_page' ],
'',
'58.5'
);
}
/**
* Reorder the Elementor menu items in admin.
* Based on WC.
*
* @since 2.4.0
*
* @param array $menu_order Menu order.
* @return array
*/
public function menu_order( $menu_order ) {
// Initialize our custom order array.
$elementor_menu_order = [];
// Get the index of our custom separator.
$elementor_separator = array_search( 'separator-elementor', $menu_order, true );
// Get index of library menu.
$elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true );
// Loop through menu order and do some rearranging.
foreach ( $menu_order as $index => $item ) {
if ( 'elementor' === $item ) {
$elementor_menu_order[] = 'separator-elementor';
$elementor_menu_order[] = $item;
$elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG;
unset( $menu_order[ $elementor_separator ] );
unset( $menu_order[ $elementor_library ] );
} elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) {
$elementor_menu_order[] = $item;
}
}
// Return order.
return $elementor_menu_order;
}
/**
* Register Elementor Pro sub-menu.
*
* Add new Elementor Pro sub-menu under the main Elementor menu.
*
* Fired by `admin_menu` action.
*
* @since 1.0.0
* @access public
*/
public function register_pro_menu() {
add_submenu_page(
self::PAGE_ID,
__( 'Custom Fonts', 'elementor' ),
__( 'Custom Fonts', 'elementor' ),
'manage_options',
'elementor_custom_fonts',
[ $this, 'elementor_custom_fonts' ]
);
add_submenu_page(
self::PAGE_ID,
__( 'Custom Icons', 'elementor' ),
__( 'Custom Icons', 'elementor' ),
'manage_options',
'elementor_custom_icons',
[ $this, 'elementor_custom_icons' ]
);
add_submenu_page(
self::PAGE_ID,
'',
'<span class="dashicons dashicons-star-filled" style="font-size: 17px"></span> ' . __( 'Go Pro', 'elementor' ),
'manage_options',
'go_elementor_pro',
[ $this, 'handle_external_redirects' ]
);
add_submenu_page( Source_Local::ADMIN_MENU_SLUG, __( 'Popups', 'elementor' ), __( 'Popups', 'elementor' ), 'manage_options', 'popup_templates', [ $this, 'elementor_popups' ] );
}
/**
* Register Elementor knowledge base sub-menu.
*
* Add new Elementor knowledge base sub-menu under the main Elementor menu.
*
* Fired by `admin_menu` action.
*
* @since 2.0.3
* @access public
*/
public function register_knowledge_base_menu() {
add_submenu_page(
self::PAGE_ID,
'',
__( 'Getting Started', 'elementor' ),
'manage_options',
'elementor-getting-started',
[ $this, 'elementor_getting_started' ]
);
add_submenu_page(
self::PAGE_ID,
'',
__( 'Get Help', 'elementor' ),
'manage_options',
'go_knowledge_base_site',
[ $this, 'handle_external_redirects' ]
);
}
/**
* Go Elementor Pro.
*
* Redirect the Elementor Pro page the clicking the Elementor Pro menu link.
*
* Fired by `admin_init` action.
*
* @since 2.0.3
* @access public
*/
public function handle_external_redirects() {
if ( empty( $_GET['page'] ) ) {
return;
}
if ( 'go_elementor_pro' === $_GET['page'] ) {
wp_redirect( Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=wp-menu&utm_campaign=gopro&utm_medium=wp-dash' ) );
die;
}
if ( 'go_knowledge_base_site' === $_GET['page'] ) {
wp_redirect( 'https://go.elementor.com/docs-admin-menu/' );
die;
}
}
/**
* Display settings page.
*
* Output the content for the getting started page.
*
* @since 2.2.0
* @access public
*/
public function elementor_getting_started() {
if ( User::is_current_user_can_edit_post_type( 'page' ) ) {
$create_new_label = __( 'Create Your First Page', 'elementor' );
$create_new_cpt = 'page';
} elseif ( User::is_current_user_can_edit_post_type( 'post' ) ) {
$create_new_label = __( 'Create Your First Post', 'elementor' );
$create_new_cpt = 'post';
}
?>
<div class="wrap">
<div class="e-getting-started">
<div class="e-getting-started__box postbox">
<div class="e-getting-started__header">
<div class="e-getting-started__title">
<div class="e-logo-wrapper">
<i class="eicon-elementor"></i>
</div>
<?php echo __( 'Getting Started', 'elementor' ); ?>
</div>
<a class="e-getting-started__skip" href="<?php echo esc_url( admin_url() ); ?>">
<i class="eicon-close" aria-hidden="true" title="<?php esc_attr_e( 'Skip', 'elementor' ); ?>"></i>
<span class="elementor-screen-only"><?php echo __( 'Skip', 'elementor' ); ?></span>
</a>
</div>
<div class="e-getting-started__content">
<div class="e-getting-started__content--narrow">
<h2><?php echo __( 'Welcome to Elementor', 'elementor' ); ?></h2>
<p><?php echo __( 'Get introduced to Elementor by watching our "Getting Started" video series. It will guide you through the steps needed to create your website. Then click to create your first page.', 'elementor' ); ?></p>
</div>
<div class="e-getting-started__video">
<iframe width="620" height="350" src="https://www.youtube-nocookie.com/embed/videoseries?list=PLZyp9H25CboH8b_wsNyOmstckiOE8aUBg&amp;controls=1&amp;modestbranding=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="e-getting-started__actions e-getting-started__content--narrow">
<?php if ( ! empty( $create_new_cpt ) ) : ?>
<a href="<?php echo esc_url( Utils::get_create_new_post_url( $create_new_cpt ) ); ?>" class="button button-primary button-hero"><?php echo esc_html( $create_new_label ); ?></a>
<?php endif; ?>
<a href="https://go.elementor.com/getting-started/" target="_blank" class="button button-secondary button-hero"><?php echo __( 'Watch the Full Guide', 'elementor' ); ?></a>
</div>
</div>
</div>
</div>
</div><!-- /.wrap -->
<?php
}
/**
* Display settings page.
*
* Output the content for the custom fonts page.
*
* @since 2.0.0
* @access public
*/
public function elementor_custom_fonts() {
?>
<div class="wrap">
<div class="elementor-blank_state">
<img src="<?php echo ELEMENTOR_ASSETS_URL . 'images/go-pro-wp-dashboard.svg'; ?>" />
<h2><?php echo __( 'Add Your Custom Fonts', 'elementor' ); ?></h2>
<p><?php echo __( 'Custom Fonts allows you to add your self-hosted fonts and use them on your Elementor projects to create a unique brand language.', 'elementor' ); ?></p>
<a class="elementor-button elementor-button-default elementor-button-go-pro" target="_blank" href="<?php echo Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=wp-custom-fonts&utm_campaign=gopro&utm_medium=wp-dash' ); ?>"><?php echo __( 'Go Pro', 'elementor' ); ?></a>
</div>
</div><!-- /.wrap -->
<?php
}
/**
* Display settings page.
*
* Output the content for the custom icons page.
*
* @since 2.8.0
* @access public
*/
public function elementor_custom_icons() {
?>
<div class="wrap">
<div class="elementor-blank_state">
<img src="<?php echo ELEMENTOR_ASSETS_URL . 'images/go-pro-wp-dashboard.svg'; ?>" />
<h2><?php echo __( 'Add Your Custom Icons', 'elementor' ); ?></h2>
<p><?php echo __( 'Don\'t rely solely on the FontAwesome icons everyone else is using! Differentiate your website and your style with custom icons you can upload from your favorite icons source.', 'elementor' ); ?></p>
<a class="elementor-button elementor-button-default elementor-button-go-pro" target="_blank" href="<?php echo Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=wp-custom-icons&utm_campaign=gopro&utm_medium=wp-dash' ); ?>"><?php echo __( 'Go Pro', 'elementor' ); ?></a>
</div>
</div><!-- /.wrap -->
<?php
}
/**
* Display settings page.
*
* Output the content for the Popups page.
*
* @since 2.4.0
* @access public
*/
public function elementor_popups() {
?>
<div class="wrap">
<div class="elementor-blank_state">
<img src="<?php echo ELEMENTOR_ASSETS_URL . 'images/go-pro-wp-dashboard.svg'; ?>" />
<h2><?php echo __( 'Get Popup Builder', 'elementor' ); ?></h2>
<p><?php echo __( 'Popup Builder lets you take advantage of all the amazing features in Elementor, so you can build beautiful & highly converting popups. Go pro and start designing your popups today.', 'elementor' ); ?></p>
<a class="elementor-button elementor-button-default elementor-button-go-pro" target="_blank" href="<?php echo Utils::get_pro_link( 'https://elementor.com/popup-builder/?utm_source=popup-templates&utm_campaign=gopro&utm_medium=wp-dash' ); ?>"><?php echo __( 'Go Pro', 'elementor' ); ?></a>
</div>
</div><!-- /.wrap -->
<?php
}
/**
* On admin init.
*
* Preform actions on WordPress admin initialization.
*
* Fired by `admin_init` action.
*
* @since 2.0.0
* @access public
*/
public function on_admin_init() {
$this->handle_external_redirects();
$this->maybe_remove_all_admin_notices();
}
/**
* Change "Settings" menu name.
*
* Update the name of the Settings admin menu from "Elementor" to "Settings".
*
* Fired by `admin_menu` action.
*
* @since 1.0.0
* @access public
*/
public function admin_menu_change_name() {
Utils::change_submenu_first_item_label( 'elementor', __( 'Settings', 'elementor' ) );
}
/**
* Update CSS print method.
*
* Clear post CSS cache.
*
* Fired by `add_option_elementor_css_print_method` and
* `update_option_elementor_css_print_method` actions.
*
* @since 1.7.5
* @access public
* @deprecated 3.0.0
*/
public function update_css_print_method() {
Plugin::$instance->files_manager->clear_cache();
}
/**
* Create tabs.
*
* Return the settings page tabs, sections and fields.
*
* @since 1.5.0
* @access protected
*
* @return array An array with the settings page tabs, sections and fields.
*/
protected function create_tabs() {
$validations_class_name = __NAMESPACE__ . '\Settings_Validations';
return [
self::TAB_GENERAL => [
'label' => __( 'General', 'elementor' ),
'sections' => [
'general' => [
'fields' => [
self::UPDATE_TIME_FIELD => [
'full_field_id' => self::UPDATE_TIME_FIELD,
'field_args' => [
'type' => 'hidden',
],
'setting_args' => [ $validations_class_name, 'current_time' ],
],
'cpt_support' => [
'label' => __( 'Post Types', 'elementor' ),
'field_args' => [
'type' => 'checkbox_list_cpt',
'std' => [ 'page', 'post' ],
'exclude' => [ 'attachment', 'elementor_library' ],
],
'setting_args' => [ $validations_class_name, 'checkbox_list' ],
],
'disable_color_schemes' => [
'label' => __( 'Disable Default Colors', 'elementor' ),
'field_args' => [
'type' => 'checkbox',
'value' => 'yes',
'sub_desc' => __( 'Checking this box will disable Elementor\'s Default Colors, and make Elementor inherit the colors from your theme.', 'elementor' ),
],
],
'disable_typography_schemes' => [
'label' => __( 'Disable Default Fonts', 'elementor' ),
'field_args' => [
'type' => 'checkbox',
'value' => 'yes',
'sub_desc' => __( 'Checking this box will disable Elementor\'s Default Fonts, and make Elementor inherit the fonts from your theme.', 'elementor' ),
],
],
],
],
'usage' => [
'label' => __( 'Improve Elementor', 'elementor' ),
'fields' => $this->get_usage_fields(),
],
],
],
self::TAB_STYLE => [
'label' => __( 'Style', 'elementor' ),
'sections' => [
'style' => [
'fields' => [
'notice' => [
'label' => __( 'Looking for the Style settings?', 'elementor' ),
'field_args' => [
'type' => 'raw_html',
'html' => __( 'The Style settings changed its location and can now be found within Elementor Editor\'s <b>Panel > Hamburger Menu > Site Settings</b>.<br>You can use the Site Settings to make changes and see them live!', 'elementor' ) . sprintf( ' <a target="_blank" href="http://go.elementor.com/panel-layout-settings">%s</a>', __( 'Learn More', 'elementor' ) ),
],
],
],
],
],
],
self::TAB_INTEGRATIONS => [
'label' => __( 'Integrations', 'elementor' ),
'sections' => [
'google_maps' => [
'label' => __( 'Google Maps Embed API', 'elementor' ),
'callback' => function() {
printf( __( 'Google Maps Embed API is a free service by Google that allows embedding Google Maps in your site. For more details, visit Google Maps\' <a href="%s" target="_blank">Using API Keys</a> page.', 'elementor' ), esc_url( 'https://developers.google.com/maps/documentation/embed/get-api-key' ) );
},
'fields' => [
'google_maps_api_key' => [
'label' => __( 'API Key', 'elementor' ),
'field_args' => [
'class' => 'elementor_google_maps_api_key',
'type' => 'text',
],
],
],
],
],
],
self::TAB_ADVANCED => [
'label' => __( 'Advanced', 'elementor' ),
'sections' => [
'advanced' => [
'fields' => [
'css_print_method' => [
'label' => __( 'CSS Print Method', 'elementor' ),
'field_args' => [
'class' => 'elementor_css_print_method',
'type' => 'select',
'options' => [
'external' => __( 'External File', 'elementor' ),
'internal' => __( 'Internal Embedding', 'elementor' ),
],
'desc' => '<div class="elementor-css-print-method-description" data-value="external" style="display: none">' . __( 'Use external CSS files for all generated stylesheets. Choose this setting for better performance (recommended).', 'elementor' ) . '</div><div class="elementor-css-print-method-description" data-value="internal" style="display: none">' . __( 'Use internal CSS that is embedded in the head of the page. For troubleshooting server configuration conflicts and managing development environments.', 'elementor' ) . '</div>',
],
],
'editor_break_lines' => [
'label' => __( 'Switch Editor Loader Method', 'elementor' ),
'field_args' => [
'type' => 'select',
'options' => [
'' => __( 'Disable', 'elementor' ),
1 => __( 'Enable', 'elementor' ),
],
'desc' => __( 'For troubleshooting server configuration conflicts.', 'elementor' ),
],
],
'unfiltered_files_upload' => [
'label' => __( 'Enable Unfiltered File Uploads', 'elementor' ),
'field_args' => [
'type' => 'select',
'std' => '',
'options' => [
'' => __( 'Disable', 'elementor' ),
1 => __( 'Enable', 'elementor' ),
],
'desc' => __( 'Please note! Allowing uploads of any files (SVG & JSON included) is a potential security risk.', 'elementor' ) . '<br>' . __( 'Elementor will try to sanitize the unfiltered files, removing potential malicious code and scripts.', 'elementor' ) . '<br>' . __( 'We recommend you only enable this feature if you understand the security risks involved.', 'elementor' ),
],
],
'font_display' => [
'label' => __( 'Google Fonts Load', 'elementor' ),
'field_args' => [
'type' => 'select',
'std' => 'auto',
'options' => [
'auto' => __( 'Default', 'elementor' ),
'block' => __( 'Blocking', 'elementor' ),
'swap' => __( 'Swap', 'elementor' ),
'fallback' => __( 'Fallback', 'elementor' ),
'optional' => __( 'Optional', 'elementor' ),
],
'desc' => __( 'Font-display property defines how font files are loaded and displayed by the browser.', 'elementor' ) . '<br>' . __( 'Set the way Google Fonts are being loaded by selecting the font-display property (Default: Auto).', 'elementor' ),
],
],
],
],
],
],
];
}
/**
* Get settings page title.
*
* Retrieve the title for the settings page.
*
* @since 1.5.0
* @access protected
*
* @return string Settings page title.
*/
protected function get_page_title() {
return __( 'Elementor', 'elementor' );
}
/**
* @since 2.2.0
* @access private
*/
private function maybe_remove_all_admin_notices() {
$elementor_pages = [
'elementor-getting-started',
'elementor_custom_fonts',
'elementor_custom_icons',
'elementor-license',
'popup_templates',
];
if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
return;
}
remove_all_actions( 'admin_notices' );
}
/**
* Settings page constructor.
*
* Initializing Elementor "Settings" page.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
parent::__construct();
add_action( 'admin_init', [ $this, 'on_admin_init' ] );
add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 );
add_action( 'admin_menu', [ $this, 'register_pro_menu' ], self::MENU_PRIORITY_GO_PRO );
add_action( 'admin_menu', [ $this, 'register_knowledge_base_menu' ], 501 );
$clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
// Clear CSS Meta after change css related methods.
$css_settings = [
'elementor_disable_color_schemes',
'elementor_disable_typography_schemes',
'elementor_css_print_method',
];
foreach ( $css_settings as $option_name ) {
add_action( "add_option_{$option_name}", $clear_cache_callback );
add_action( "update_option_{$option_name}", $clear_cache_callback );
}
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', [ $this, 'menu_order' ] );
}
}

View File

@@ -0,0 +1,346 @@
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor "Tools" page in WordPress Dashboard.
*
* Elementor settings page handler class responsible for creating and displaying
* Elementor "Tools" page in WordPress dashboard.
*
* @since 1.0.0
*/
class Tools extends Settings_Page {
/**
* Settings page ID for Elementor tools.
*/
const PAGE_ID = 'elementor-tools';
/**
* Register admin menu.
*
* Add new Elementor Tools admin menu.
*
* Fired by `admin_menu` action.
*
* @since 1.0.0
* @access public
*/
public function register_admin_menu() {
add_submenu_page(
Settings::PAGE_ID,
__( 'Tools', 'elementor' ),
__( 'Tools', 'elementor' ),
'manage_options',
self::PAGE_ID,
[ $this, 'display_settings_page' ]
);
}
/**
* Clear cache.
*
* Delete post meta containing the post CSS file data. And delete the actual
* CSS files from the upload directory.
*
* Fired by `wp_ajax_elementor_clear_cache` action.
*
* @since 1.0.0
* @access public
*/
public function ajax_elementor_clear_cache() {
check_ajax_referer( 'elementor_clear_cache', '_nonce' );
Plugin::$instance->files_manager->clear_cache();
wp_send_json_success();
}
/**
* Replace URLs.
*
* Sends an ajax request to replace old URLs to new URLs. This method also
* updates all the Elementor data.
*
* Fired by `wp_ajax_elementor_replace_url` action.
*
* @since 1.1.0
* @access public
*/
public function ajax_elementor_replace_url() {
check_ajax_referer( 'elementor_replace_url', '_nonce' );
$from = ! empty( $_POST['from'] ) ? $_POST['from'] : '';
$to = ! empty( $_POST['to'] ) ? $_POST['to'] : '';
try {
$results = Utils::replace_urls( $from, $to );
wp_send_json_success( $results );
} catch ( \Exception $e ) {
wp_send_json_error( $e->getMessage() );
}
}
/**
* Elementor version rollback.
*
* Rollback to previous Elementor version.
*
* Fired by `admin_post_elementor_rollback` action.
*
* @since 1.5.0
* @access public
*/
public function post_elementor_rollback() {
check_admin_referer( 'elementor_rollback' );
$rollback_versions = $this->get_rollback_versions();
if ( empty( $_GET['version'] ) || ! in_array( $_GET['version'], $rollback_versions ) ) {
wp_die( __( 'Error occurred, The version selected is invalid. Try selecting different version.', 'elementor' ) );
}
$plugin_slug = basename( ELEMENTOR__FILE__, '.php' );
$rollback = new Rollback(
[
'version' => $_GET['version'],
'plugin_name' => ELEMENTOR_PLUGIN_BASE,
'plugin_slug' => $plugin_slug,
'package_url' => sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $_GET['version'] ),
]
);
$rollback->run();
wp_die(
'', __( 'Rollback to Previous Version', 'elementor' ), [
'response' => 200,
]
);
}
/**
* Tools page constructor.
*
* Initializing Elementor "Tools" page.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
parent::__construct();
add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 205 );
if ( ! empty( $_POST ) ) {
add_action( 'wp_ajax_elementor_clear_cache', [ $this, 'ajax_elementor_clear_cache' ] );
add_action( 'wp_ajax_elementor_replace_url', [ $this, 'ajax_elementor_replace_url' ] );
}
add_action( 'admin_post_elementor_rollback', [ $this, 'post_elementor_rollback' ] );
}
private function get_rollback_versions() {
$rollback_versions = get_transient( 'elementor_rollback_versions_' . ELEMENTOR_VERSION );
if ( false === $rollback_versions ) {
$max_versions = 30;
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugin_information = plugins_api(
'plugin_information', [
'slug' => 'elementor',
]
);
if ( empty( $plugin_information->versions ) || ! is_array( $plugin_information->versions ) ) {
return [];
}
krsort( $plugin_information->versions );
$rollback_versions = [];
$current_index = 0;
foreach ( $plugin_information->versions as $version => $download_link ) {
if ( $max_versions <= $current_index ) {
break;
}
$lowercase_version = strtolower( $version );
$is_valid_rollback_version = ! preg_match( '/(trunk|beta|rc|dev)/i', $lowercase_version );
$is_valid_rollback_version = apply_filters(
'elementor/settings/tools/rollback/is_valid_rollback_version',
$is_valid_rollback_version,
$lowercase_version
);
if ( ! $is_valid_rollback_version ) {
continue;
}
if ( version_compare( $version, ELEMENTOR_VERSION, '>=' ) ) {
continue;
}
$current_index++;
$rollback_versions[] = $version;
}
set_transient( 'elementor_rollback_versions_' . ELEMENTOR_VERSION, $rollback_versions, WEEK_IN_SECONDS );
}
return $rollback_versions;
}
/**
* Create tabs.
*
* Return the tools page tabs, sections and fields.
*
* @since 1.5.0
* @access protected
*
* @return array An array with the page tabs, sections and fields.
*/
protected function create_tabs() {
$rollback_html = '<select class="elementor-rollback-select">';
foreach ( $this->get_rollback_versions() as $version ) {
$rollback_html .= "<option value='{$version}'>$version</option>";
}
$rollback_html .= '</select>';
return [
'general' => [
'label' => __( 'General', 'elementor' ),
'sections' => [
'tools' => [
'fields' => [
'clear_cache' => [
'label' => __( 'Regenerate CSS', 'elementor' ),
'field_args' => [
'type' => 'raw_html',
'html' => sprintf( '<button data-nonce="%s" class="button elementor-button-spinner" id="elementor-clear-cache-button">%s</button>', wp_create_nonce( 'elementor_clear_cache' ), __( 'Regenerate Files', 'elementor' ) ),
'desc' => __( 'Styles set in Elementor are saved in CSS files in the uploads folder. Recreate those files, according to the most recent settings.', 'elementor' ),
],
],
'reset_api_data' => [
'label' => __( 'Sync Library', 'elementor' ),
'field_args' => [
'type' => 'raw_html',
'html' => sprintf( '<button data-nonce="%s" class="button elementor-button-spinner" id="elementor-library-sync-button">%s</button>', wp_create_nonce( 'elementor_reset_library' ), __( 'Sync Library', 'elementor' ) ),
'desc' => __( 'Elementor Library automatically updates on a daily basis. You can also manually update it by clicking on the sync button.', 'elementor' ),
],
],
],
],
],
],
'replace_url' => [
'label' => __( 'Replace URL', 'elementor' ),
'sections' => [
'replace_url' => [
'callback' => function() {
$intro_text = sprintf(
/* translators: %s: Codex URL */
__( '<strong>Important:</strong> It is strongly recommended that you <a target="_blank" href="%s">backup your database</a> before using Replace URL.', 'elementor' ),
'http://go.elementor.com/wordpress-backups/'
);
$intro_text = '<div>' . $intro_text . '</div>';
echo '<h2>' . esc_html__( 'Replace URL', 'elementor' ) . '</h2>';
echo $intro_text;
},
'fields' => [
'replace_url' => [
'label' => __( 'Update Site Address (URL)', 'elementor' ),
'field_args' => [
'type' => 'raw_html',
'html' => sprintf( '<input type="text" name="from" placeholder="http://old-url.com" class="medium-text"><input type="text" name="to" placeholder="http://new-url.com" class="medium-text"><button data-nonce="%s" class="button elementor-button-spinner" id="elementor-replace-url-button">%s</button>', wp_create_nonce( 'elementor_replace_url' ), __( 'Replace URL', 'elementor' ) ),
'desc' => __( 'Enter your old and new URLs for your WordPress installation, to update all Elementor data (Relevant for domain transfers or move to \'HTTPS\').', 'elementor' ),
],
],
],
],
],
],
'versions' => [
'label' => __( 'Version Control', 'elementor' ),
'sections' => [
'rollback' => [
'label' => __( 'Rollback to Previous Version', 'elementor' ),
'callback' => function() {
$intro_text = sprintf(
/* translators: %s: Elementor version */
__( 'Experiencing an issue with Elementor version %s? Rollback to a previous version before the issue appeared.', 'elementor' ),
ELEMENTOR_VERSION
);
$intro_text = '<p>' . $intro_text . '</p>';
echo $intro_text;
},
'fields' => [
'rollback' => [
'label' => __( 'Rollback Version', 'elementor' ),
'field_args' => [
'type' => 'raw_html',
'html' => sprintf(
$rollback_html . '<a data-placeholder-text="' . __( 'Reinstall', 'elementor' ) . ' v{VERSION}" href="#" data-placeholder-url="%s" class="button elementor-button-spinner elementor-rollback-button">%s</a>',
wp_nonce_url( admin_url( 'admin-post.php?action=elementor_rollback&version=VERSION' ), 'elementor_rollback' ),
__( 'Reinstall', 'elementor' )
),
'desc' => '<span style="color: red;">' . __( 'Warning: Please backup your database before making the rollback.', 'elementor' ) . '</span>',
],
],
],
],
'beta' => [
'label' => __( 'Become a Beta Tester', 'elementor' ),
'callback' => function() {
$intro_text = __( 'Turn-on Beta Tester, to get notified when a new beta version of Elementor or Elementor Pro is available. The Beta version will not install automatically. You always have the option to ignore it.', 'elementor' );
$intro_text = '<p>' . $intro_text . '</p>';
$newsletter_opt_in_text = sprintf( __( '<a id="beta-tester-first-to-know" href="%s">Click here</a> to join our first-to-know email updates.', 'elementor' ), '#' );
echo $intro_text;
echo $newsletter_opt_in_text;
},
'fields' => [
'beta' => [
'label' => __( 'Beta Tester', 'elementor' ),
'field_args' => [
'type' => 'select',
'default' => 'no',
'options' => [
'no' => __( 'Disable', 'elementor' ),
'yes' => __( 'Enable', 'elementor' ),
],
'desc' => '<span style="color: red;">' . __( 'Please Note: We do not recommend updating to a beta version on production sites.', 'elementor' ) . '</span>',
],
],
],
],
],
],
];
}
/**
* Get tools page title.
*
* Retrieve the title for the tools page.
*
* @since 1.5.0
* @access protected
*
* @return string Tools page title.
*/
protected function get_page_title() {
return __( 'Tools', 'elementor' );
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor settings validations.
*
* Elementor settings validations handler class is responsible for validating settings
* fields.
*
* @since 1.0.0
*/
class Settings_Validations {
/**
* Validate HTML field.
*
* Sanitize content for allowed HTML tags and remove backslashes before quotes.
*
* @since 1.0.0
* @access public
* @static
*
* @param string $input Input field.
*
* @return string Input field.
*/
public static function html( $input ) {
return stripslashes( wp_filter_post_kses( addslashes( $input ) ) );
}
/**
* Validate checkbox list.
*
* Make sure that an empty checkbox list field will return an array.
*
* @since 1.0.0
* @access public
* @static
*
* @param mixed $input Input field.
*
* @return mixed Input field.
*/
public static function checkbox_list( $input ) {
if ( empty( $input ) ) {
$input = [];
}
return $input;
}
/**
* Current Time
*
* Used to return current time
*
* @since 2.5.0
* @access public
* @static
*
* @param mixed $input Input field.
*
* @return int
*/
public static function current_time( $input ) {
return time();
}
/**
* Clear cache.
*
* Delete post meta containing the post CSS file data. And delete the actual
* CSS files from the upload directory.
*
* @since 1.4.8
* @access public
* @static
*
* @param mixed $input Input field.
*
* @return mixed Input field.
*/
public static function clear_cache( $input ) {
Plugin::$instance->files_manager->clear_cache();
return $input;
}
}