-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1a09742
commit 48ef288
Showing
8 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\Fonts\Admin; | ||
|
||
use WP_Rocket\Engine\Admin\Settings\Settings as AdminSettings; | ||
|
||
class Settings { | ||
/** | ||
* Adds the host fonts locally option to WP Rocket options array | ||
* | ||
* @param array $options WP Rocket options array. | ||
* | ||
* @return array | ||
*/ | ||
public function add_option( array $options ): array { | ||
$options['host_fonts_locally'] = 0; | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* Sanitizes the option value when saving from the settings page | ||
* | ||
* @param array $input Array of sanitized values after being submitted by the form. | ||
* @param AdminSettings $settings Settings class instance. | ||
* | ||
* @return array | ||
*/ | ||
public function sanitize_option_value( array $input, AdminSettings $settings ): array { | ||
$input['host_fonts_locally'] = $settings->sanitize_checkbox( $input, 'host_fonts_locally' ); | ||
|
||
return $input; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\Fonts\Admin; | ||
|
||
use WP_Rocket\Engine\Admin\Settings\Settings; | ||
use WP_Rocket\Engine\Media\Fonts\Admin\Settings as FontsSettings; | ||
use WP_Rocket\Event_Management\Subscriber_Interface; | ||
|
||
|
||
class Subscriber implements Subscriber_Interface { | ||
/** | ||
* Fonts Settings instance | ||
* | ||
* @var FontsSettings | ||
*/ | ||
private $settings; | ||
|
||
/** | ||
* Instantiate the class | ||
* | ||
* @param FontsSettings $settings Fonts Settings instance. | ||
*/ | ||
public function __construct( FontsSettings $settings ) { | ||
$this->settings = $settings; | ||
} | ||
|
||
/** | ||
* Returns an array of events this listens to | ||
* | ||
* @return array | ||
*/ | ||
public static function get_subscribed_events(): array { | ||
return [ | ||
'rocket_first_install_options' => [ 'add_option', 16 ], | ||
'rocket_input_sanitize' => [ 'sanitize_option', 10, 2 ], | ||
]; | ||
} | ||
|
||
/** | ||
* Add the images dimensions option to the WP Rocket options array | ||
* | ||
* @param array $options WP Rocket options array. | ||
* | ||
* @return array | ||
*/ | ||
public function add_option( array $options ): array { | ||
return $this->settings->add_option( $options ); | ||
} | ||
|
||
/** | ||
* Sanitizes the option value when saving from the settings page | ||
* | ||
* @param array $input Array of sanitized values after being submitted by the form. | ||
* @param Settings $settings Settings class instance. | ||
* | ||
* @return array | ||
*/ | ||
public function sanitize_option( array $input, Settings $settings ): array { | ||
return $this->settings->sanitize_option_value( $input, $settings ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WP_Rocket\Engine\Media\Fonts; | ||
|
||
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider; | ||
use WP_Rocket\Engine\Media\Fonts\Admin\Settings; | ||
use WP_Rocket\Engine\Media\Fonts\Admin\Subscriber as AdminSubscriber; | ||
|
||
class ServiceProvider extends AbstractServiceProvider { | ||
/** | ||
* The provides array is a way to let the container | ||
* know that a service is provided by this service | ||
* provider. Every service that is registered via | ||
* this service provider must have an alias added | ||
* to this array or it will be ignored. | ||
* | ||
* @var array | ||
*/ | ||
protected $provides = [ | ||
'media_fonts_settings', | ||
'media_fonts_admin_subscriber', | ||
]; | ||
|
||
/** | ||
* Check if the service provider provides a specific service. | ||
* | ||
* @param string $id The id of the service. | ||
* | ||
* @return bool | ||
*/ | ||
public function provides( string $id ): bool { | ||
return in_array( $id, $this->provides, true ); | ||
} | ||
|
||
/** | ||
* Registers the classes. | ||
* | ||
* @return void | ||
*/ | ||
public function register(): void { | ||
$this->getContainer()->add( 'media_fonts_settings', Settings::class ); | ||
$this->getContainer()->addShared( 'media_fonts_admin_subscriber', AdminSubscriber::class ) | ||
->addArgument( 'media_fonts_settings' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters