PluginProbe ʕ •ᴥ•ʔ
Ultimate Addons for Elementor / 1.6.38
Ultimate Addons for Elementor v1.6.38
2.8.8 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 v1.1.3 v1.1.4 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.29 1.6.3 1.6.30 1.6.31 1.6.32 1.6.33 1.6.34 1.6.35 1.6.36 1.6.37 1.6.38 1.6.39 1.6.4 1.6.40 1.6.41 1.6.42 1.6.43 1.6.44 1.6.45 1.6.46 1.6.47 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.2 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2
header-footer-elementor / inc / class-hfe-update.php
header-footer-elementor / inc Last commit date
compatibility 1 year ago js 3 years ago lib 1 year ago widgets-css 2 years ago widgets-manager 1 year ago class-header-footer-elementor.php 1 year ago class-hfe-elementor-canvas-compat.php 1 year ago class-hfe-settings-page.php 1 year ago class-hfe-update.php 1 year ago hfe-functions.php 1 year ago
class-hfe-update.php
177 lines
1 <?php
2 /**
3 * Theme Update
4 *
5 * @package Header Footer Elementor
6 * @author Nikhil Chavan <email@nikhilchavan.com>
7 * @copyright Copyright (c) 2019, Header Footer Elementor
8 * @link https://github.com/Nikschavan/header-footer-elementor/
9 * @since HFE 1.1.4
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 if ( ! class_exists( 'HFE_Update' ) ) {
17
18 /**
19 * HFE_Update initial setup
20 *
21 * @since 1.1.4
22 */
23 class HFE_Update {
24
25 /**
26 * Option key for stored version number.
27 *
28 * @since 1.1.4
29 * @var string
30 */
31 // phpcs:ignore
32 private string $db_option_key = '_hfe_db_version';
33
34 /**
35 * Constructor
36 *
37 * @since 1.1.4
38 */
39 public function __construct() {
40
41 // Theme Updates.
42 if ( is_admin() ) {
43 add_action( 'admin_init', [ $this, 'init' ], 5 );
44 } else {
45 add_action( 'wp', [ $this, 'init' ], 5 );
46 }
47 }
48
49 /**
50 * Implement theme update logic.
51 *
52 * @since 1.1.4
53 * @return void
54 */
55 public function init() {
56 do_action( 'hfe_update_before' );
57
58 if ( ! $this->needs_db_update() ) {
59 return;
60 }
61
62 $db_version = get_option( $this->db_option_key, false );
63
64 if ( version_compare( $db_version, '1.2.0-beta.2', '<' ) ) {
65 $this->setup_default_terget_rules();
66 }
67
68 // flush rewrite rules on plugin update.
69 flush_rewrite_rules(); // PHPCS:Ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules
70
71 $this->update_db_version();
72
73 do_action( 'hfe_update_after' );
74 }
75
76 /**
77 * Set default target rules for header, footer, before footers being used before target rules were added to the plugin.
78 *
79 * @since 1.2.0-beta.1
80 * @return void
81 */
82 private function setup_default_terget_rules() {
83 $default_include_locations = [
84 'rule' => [ 0 => 'basic-global' ],
85 'specific' => [],
86 ];
87
88 $header_id = $this->get_legacy_template_id( 'type_header' );
89 $footer_id = $this->get_legacy_template_id( 'type_footer' );
90 $before_footer_id = $this->get_legacy_template_id( 'type_before_footer' );
91
92 // Header.
93 if ( ! empty( $header_id ) ) {
94 update_post_meta( $header_id, 'ehf_target_include_locations', $default_include_locations );
95 }
96
97 // Footer.
98 if ( ! empty( $footer_id ) ) {
99 update_post_meta( $footer_id, 'ehf_target_include_locations', $default_include_locations );
100 }
101
102 // Before Footer.
103 if ( ! empty( $before_footer_id ) ) {
104 update_post_meta( $before_footer_id, 'ehf_target_include_locations', $default_include_locations );
105 }
106 }
107
108 /**
109 * Get header or footer template id based on the meta query.
110 *
111 * @param string $type Type of the template header/footer.
112 *
113 * @return mixed Returns the header or footer template id if found, else returns string ''.
114 */
115 public function get_legacy_template_id( $type ) {
116 $args = [
117 'post_type' => 'elementor-hf',
118 'meta_key' => 'ehf_template_type',
119 'meta_value' => $type, // PHPCS:Ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
120 'meta_type' => 'post',
121 'meta_compare' => '>=',
122 'orderby' => 'meta_value',
123 'order' => 'ASC',
124 'meta_query' => [ // PHPCS:Ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
125 'relation' => 'OR',
126 [
127 'key' => 'ehf_template_type',
128 'value' => $type,
129 'compare' => '==',
130 'type' => 'post',
131 ],
132 ],
133 ];
134
135 $args = apply_filters( 'hfe_get_template_id_args', $args );
136 $template = new WP_Query(
137 $args
138 );
139
140 if ( $template->have_posts() ) {
141 $posts = wp_list_pluck( $template->posts, 'ID' );
142 return $posts[0];
143 }
144
145 return '';
146 }
147
148 /**
149 * Check if db upgrade is required.
150 *
151 * @since 1.1.4
152 * @return bool True if stored database version is lower than constant; false if otherwise.
153 */
154 private function needs_db_update() {
155 $db_version = get_option( $this->db_option_key, false );
156
157 if ( false === $db_version || version_compare( $db_version, HFE_VER ) ) {
158 return true;
159 }
160
161 return false;
162 }
163
164 /**
165 * Update DB version.
166 *
167 * @since 1.1.4
168 * @return void
169 */
170 private function update_db_version() {
171 update_option( $this->db_option_key, HFE_VER );
172 }
173 }
174 }
175
176 new HFE_Update();
177