summaryrefslogtreecommitdiff
path: root/inc/core/builder/class-astra-builder-admin.php
blob: 94df3e4c8409c8a3fa73da8bebe4f7ad3d2e2e15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
 * Astra Builder Admin Loader.
 *
 * @package astra-builder
 */

// No direct access, please.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Astra_Builder_Admin.
 */
final class Astra_Builder_Admin {

	/**
	 * Member Variable
	 *
	 * @var instance
	 */
	private static $instance = null;

	/**
	 *  Initiator
	 */
	public static function get_instance() {

		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Constructor
	 */
	public function __construct() {
		add_action( 'wp_ajax_ast-migrate-to-builder', array( $this, 'migrate_to_builder' ) );
		add_action( 'astra_welcome_page_content', array( $this, 'migrate_to_builder_box' ), 5 );
	}

	/**
	 * Migrate to New Header Builder
	 *
	 * @since 3.0.0
	 * @return void
	 */
	public function migrate_to_builder_box() {
		if ( Astra_Builder_Helper::is_new_user() ) {
			add_filter( 'astra_quick_settings', array( $this, 'update_customizer_header_footer_link' ) );
			return;
		}

		$status            = astra_get_option( 'is-header-footer-builder', false );
		$astra_theme_title = Astra_Admin_Settings::$page_title;

		$label = ( false !== $status ) ? __( 'Use Old Header/Footer', 'astra' ) : __( 'Use New Header/Footer Builder', 'astra' );

		?>
		<div class="postbox">
			<h2 class="hndle ast-normal-cursor ast-addon-heading ast-flex">
				<span>
					<?php
						printf(
							/* translators: %1$s: Theme name. */
							esc_html__( '%1$s Header/Footer Builder', 'astra' ),
							esc_html( $astra_theme_title )
						);
					?>
				</span>
			</h2>
			<div class="inside">
				<div>
					<p>
						<?php
							printf(
								/* translators: %1$s: Theme name. */
								esc_html__( '%1$s Header/Footer Builder is a new and powerful way to design header and footer for your website. With this, you can give a creative look to your header/footer with less effort.', 'astra' ),
								esc_html( $astra_theme_title )
							);
						?>
					</p>
					<p>
						<?php
							printf(
								/* translators: %1$s: Theme name. */
								esc_html__( 'Activating this feature will add advanced options to %1$s customizer where you can create awesome new designs.', 'astra' ),
								esc_html( $astra_theme_title )
							);
						?>
					</p>
					<p><?php esc_html_e( 'Note: The header/footer builder will replace the existing header/footer settings in the customizer. This might make your header/footer look a bit different. You can configure header/footer builder settings from customizer to give it a nice look. You can always come back here and switch to your old header/footer.', 'astra' ); ?></p>
					<div class="ast-actions-wrap" style="justify-content: space-between;display: flex;align-items: center;" >
						<a href="<?php echo esc_url( admin_url( '/customize.php' ) ); ?>" class="ast-go-to-customizer"><?php esc_html_e( 'Go to Customizer', 'astra' ); ?></a>
						<div class="ast-actions" style="display: inline-flex;">
							<button href="#" class="button button-primary ast-builder-migrate" style="margin-right:10px;" data-value="<?php echo ( $status ) ? 0 : 1; ?>"><?php echo esc_html( $label ); ?></button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php
		if ( $status ) {
			add_filter( 'astra_quick_settings', array( $this, 'update_customizer_header_footer_link' ) );
		}
	}

	/**
	 * Update Customizer Header Footer quick links from options page.
	 *
	 * @since 3.0.0
	 * @param array $args default Header Footer quick links.
	 * @return array updated Header Footer quick links.
	 */
	public function update_customizer_header_footer_link( $args ) {
		if ( isset( $args['header']['quick_url'] ) ) {
			$args['header']['quick_url'] = admin_url( 'customize.php?autofocus[panel]=panel-header-builder-group' );
		}
		if ( isset( $args['footer']['quick_url'] ) ) {
			$args['footer']['quick_url'] = admin_url( 'customize.php?autofocus[panel]=panel-footer-builder-group' );
		}
		return $args;
	}

	/**
	 * Migrate to New Header Builder
	 */
	public function migrate_to_builder() {

		check_ajax_referer( 'astra-builder-module-nonce', 'nonce' );

		if ( ! current_user_can( 'manage_options' ) ) {
			wp_send_json_error( __( 'You don\'t have the access', 'astra' ) );
		}

		$migrate        = isset( $_POST['value'] ) ? sanitize_key( $_POST['value'] ) : '';
		$migrate        = ( $migrate ) ? true : false;
		$migration_flag = astra_get_option( 'v3-option-migration', false );
		astra_update_option( 'is-header-footer-builder', $migrate );
		if ( $migrate && false === $migration_flag ) {
			astra_header_builder_migration();
		}
		wp_send_json_success();
	}

}

/**
 *  Prepare if class 'Astra_Builder_Admin' exist.
 *  Kicking this off by calling 'get_instance()' method
 */
Astra_Builder_Admin::get_instance();