Skip to content

Commit a5fbad1

Browse files
committed
Hook in icns and fonts auto-updates to settings
1 parent 7ade260 commit a5fbad1

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

plugin/php/admin/class-admin-updates.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,8 @@ public function run_updates() {
7171
* @throws \Exception Exception.
7272
*/
7373
public function update_fonts( $write_response = true ) {
74-
75-
$expired = get_transient( Update_Fonts::TRANSIENT );
76-
if ( false !== $expired ) {
77-
return false;
78-
}
79-
8074
$fonts = new Update_Fonts( false );
81-
$fonts->get_fonts( $write_response );
75+
$fonts->update( $write_response );
8276

8377
return true;
8478
}
@@ -91,14 +85,8 @@ public function update_fonts( $write_response = true ) {
9185
* @return bool
9286
*/
9387
public function update_icons( $write_response = true ) {
94-
95-
$expired = get_transient( Update_Icons::TRANSIENT );
96-
if ( false !== $expired ) {
97-
return false;
98-
}
99-
10088
$icons = new Update_Icons( false );
101-
$icons->get_icons( $write_response );
89+
$icons->update( $write_response );
10290

10391
return true;
10492
}

plugin/php/api/class-update-fonts.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ public function get_http_response() {
197197
return ! empty( $json ) ? $json : false;
198198
}
199199

200+
/**
201+
* Update fonts from Google Font API.
202+
*
203+
* @param boolean $write_response Shoud write the reponse to file.
204+
* @return mixed
205+
*/
206+
public function update( $write_response = false ) {
207+
if ( $this->should_check_for_updates() ) {
208+
return $this->get_fonts( $write_response );
209+
}
210+
211+
return false;
212+
}
213+
200214
/**
201215
* Returns error message
202216
*

plugin/php/api/class-update-icons.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ public function get_http_response( $write_response = true ) {
170170
return $codepoints;
171171
}
172172

173+
/**
174+
* Update icons from source.
175+
*
176+
* @param boolean $write_response Shoud write the reponse to file.
177+
* @return mixed
178+
*/
179+
public function update( $write_response = false ) {
180+
if ( $this->should_check_for_updates() ) {
181+
return $this->get_icons( $write_response );
182+
}
183+
184+
return false;
185+
}
186+
173187
/**
174188
* Get last updated timestamp
175189
*

plugin/php/api/class-updates-api-base.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public function __construct() {
6161
*/
6262
abstract public function get_http_response();
6363

64+
/**
65+
* Child class must provide this method
66+
*
67+
* @param boolean $write_response Shoud write the reponse to file.
68+
* @return mixed
69+
*/
70+
abstract public function update( $write_response );
71+
6472
/**
6573
* Wrapper function to accommodate tests.
6674
*
@@ -75,4 +83,29 @@ abstract public function get_http_response();
7583
public function file_get_contents( $filename, $use_include_path = false, $context = null, $offset = 0, $length = null ) {
7684
return apply_filters( 'material_design_file_get_contents', file_get_contents( $filename, $use_include_path, $context, $offset, $length ) ); //phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
7785
}
86+
87+
/**
88+
* Determine if check for auto-updates should happen.
89+
*
90+
* @return boolean
91+
*/
92+
public function should_check_for_updates() {
93+
$expired = get_transient( static::TRANSIENT );
94+
95+
if ( false !== $expired ) {
96+
return false;
97+
}
98+
99+
// Check if auto-update is enabled.
100+
return static::is_auto_update_enabled();
101+
}
102+
103+
/**
104+
* Determine if auto-update is enabled.
105+
*
106+
* @return boolean
107+
*/
108+
public function is_auto_update_enabled() {
109+
return ! empty( get_option( static::AUTO_UPDATE_SLUG, false ) );
110+
}
78111
}

0 commit comments

Comments
 (0)