| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Kits\Documents\Tabs; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Core\Base\Document; |
| 7 |
use Elementor\Core\Files\Uploads_Manager; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
class Settings_Site_Identity extends Tab_Base { |
| 14 |
|
| 15 |
public function get_id() { |
| 16 |
return 'settings-site-identity'; |
| 17 |
} |
| 18 |
|
| 19 |
public function get_title() { |
| 20 |
return esc_html__( 'Site Identity', 'elementor' ); |
| 21 |
} |
| 22 |
|
| 23 |
public function get_group() { |
| 24 |
return 'settings'; |
| 25 |
} |
| 26 |
|
| 27 |
public function get_icon() { |
| 28 |
return 'eicon-site-identity'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_help_url() { |
| 32 |
return 'https://go.elementor.com/global-site-identity/'; |
| 33 |
} |
| 34 |
|
| 35 |
protected function register_tab_controls() { |
| 36 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
| 37 |
$custom_logo_src = wp_get_attachment_image_src( $custom_logo_id, 'full' ); |
| 38 |
|
| 39 |
$site_icon_id = get_option( 'site_icon' ); |
| 40 |
$site_icon_src = wp_get_attachment_image_src( $site_icon_id, 'full' ); |
| 41 |
|
| 42 |
// If CANNOT upload svg normally, it will add a custom inline option to force svg upload if requested. (in logo and favicon) |
| 43 |
$should_include_svg_inline_option = ! Uploads_Manager::are_unfiltered_uploads_enabled(); |
| 44 |
|
| 45 |
$this->start_controls_section( |
| 46 |
'section_' . $this->get_id(), |
| 47 |
[ |
| 48 |
'label' => $this->get_title(), |
| 49 |
'tab' => $this->get_id(), |
| 50 |
] |
| 51 |
); |
| 52 |
|
| 53 |
$this->add_control( |
| 54 |
$this->get_id() . '_refresh_notice', |
| 55 |
[ |
| 56 |
'type' => Controls_Manager::RAW_HTML, |
| 57 |
'raw' => sprintf( |
| 58 |
/* translators: 1: Link open tag, 2: Link open tag, 3: Link close tag. */ |
| 59 |
esc_html__( 'Changes will be reflected only after %1$s saving %3$s and %2$s reloading %3$s preview.', 'elementor' ), |
| 60 |
'<a href="javascript: $e.run( \'document/save/default\' )">', |
| 61 |
'<a href="javascript: $e.run( \'preview/reload\' )">', |
| 62 |
'</a>' |
| 63 |
), |
| 64 |
'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', |
| 65 |
] |
| 66 |
); |
| 67 |
|
| 68 |
$this->add_control( |
| 69 |
'site_name', |
| 70 |
[ |
| 71 |
'label' => esc_html__( 'Site Name', 'elementor' ), |
| 72 |
'default' => get_option( 'blogname' ), |
| 73 |
'placeholder' => esc_html__( 'Choose name', 'elementor' ), |
| 74 |
'label_block' => true, |
| 75 |
'export' => false, |
| 76 |
] |
| 77 |
); |
| 78 |
|
| 79 |
$this->add_control( |
| 80 |
'site_description', |
| 81 |
[ |
| 82 |
'label' => esc_html__( 'Site Description', 'elementor' ), |
| 83 |
'default' => get_option( 'blogdescription' ), |
| 84 |
'placeholder' => esc_html__( 'Choose description', 'elementor' ), |
| 85 |
'label_block' => true, |
| 86 |
'export' => false, |
| 87 |
] |
| 88 |
); |
| 89 |
|
| 90 |
$this->add_control( |
| 91 |
'site_logo', |
| 92 |
[ |
| 93 |
'label' => esc_html__( 'Site Logo', 'elementor' ), |
| 94 |
'type' => Controls_Manager::MEDIA, |
| 95 |
'should_include_svg_inline_option' => $should_include_svg_inline_option, |
| 96 |
'default' => [ |
| 97 |
'id' => $custom_logo_id, |
| 98 |
'url' => $custom_logo_src ? $custom_logo_src[0] : '', |
| 99 |
], |
| 100 |
'description' => sprintf( |
| 101 |
/* translators: 1: Width number pixel, 2: Height number pixel. */ |
| 102 |
esc_html__( 'Suggested image dimensions: %1$s × %2$s pixels.', 'elementor' ), |
| 103 |
'350', |
| 104 |
'100' |
| 105 |
), |
| 106 |
'export' => false, |
| 107 |
] |
| 108 |
); |
| 109 |
|
| 110 |
$this->add_control( |
| 111 |
'site_favicon', |
| 112 |
[ |
| 113 |
'label' => esc_html__( 'Site Favicon', 'elementor' ), |
| 114 |
'type' => Controls_Manager::MEDIA, |
| 115 |
'should_include_svg_inline_option' => $should_include_svg_inline_option, |
| 116 |
'default' => [ |
| 117 |
'id' => $site_icon_id, |
| 118 |
'url' => $site_icon_src ? $site_icon_src[0] : '', |
| 119 |
], |
| 120 |
'description' => esc_html__( 'Suggested favicon dimensions: 512 × 512 pixels.', 'elementor' ), |
| 121 |
'export' => false, |
| 122 |
] |
| 123 |
); |
| 124 |
|
| 125 |
$this->end_controls_section(); |
| 126 |
} |
| 127 |
|
| 128 |
public function on_save( $data ) { |
| 129 |
if ( |
| 130 |
! isset( $data['settings']['post_status'] ) || |
| 131 |
Document::STATUS_PUBLISH !== $data['settings']['post_status'] || |
| 132 |
// Should check for the current action to avoid infinite loop |
| 133 |
// when updating options like: "blogname" and "blogdescription". |
| 134 |
strpos( current_action(), 'update_option_' ) === 0 |
| 135 |
) { |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
if ( isset( $data['settings']['site_name'] ) ) { |
| 140 |
update_option( 'blogname', $data['settings']['site_name'] ); |
| 141 |
} |
| 142 |
|
| 143 |
if ( isset( $data['settings']['site_description'] ) ) { |
| 144 |
update_option( 'blogdescription', $data['settings']['site_description'] ); |
| 145 |
} |
| 146 |
|
| 147 |
if ( isset( $data['settings']['site_logo'] ) ) { |
| 148 |
set_theme_mod( 'custom_logo', $data['settings']['site_logo']['id'] ); |
| 149 |
} |
| 150 |
|
| 151 |
if ( isset( $data['settings']['site_favicon'] ) ) { |
| 152 |
update_option( 'site_icon', $data['settings']['site_favicon']['id'] ); |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
|