-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathTheme.php
More file actions
125 lines (110 loc) · 2.87 KB
/
Theme.php
File metadata and controls
125 lines (110 loc) · 2.87 KB
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
<?php
namespace BEA\Theme\Framework\Services;
use BEA\Theme\Framework\Framework;
use BEA\Theme\Framework\Service;
use BEA\Theme\Framework\Service_Container;
class Theme implements Service {
/**
* @var Service|bool
*/
protected $asset;
/**
* @param Service_Container $container
*/
public function register( Service_Container $container ): void {}
/**
* @param Service_Container $container
*/
public function boot( Service_Container $container ): void {
$this->asset = $container->get_service( 'assets' );
$this->after_setup_theme();
/**
* @psalm-suppress PossiblyInvalidMethodCall
* @psalm-suppress UndefinedInterfaceMethod
*/
if ( $this->asset->is_minified() ) {
add_filter( 'ari_responsive_image_default_img_path', [ $this, 'set_ari_responsive_image_default_img_path' ] );
add_filter( 'ari_responsive_image_default_img_name', [ $this, 'set_ari_responsive_image_default_img_name' ] );
}
}
/**
* @return string
*/
public function get_service_name(): string {
return 'theme';
}
/**
* After setup theme
*/
public function after_setup_theme(): void {
/**
* Init the supports.
*/
$this->add_theme_supports();
$this->remove_theme_supports();
/**
* Load translations.
*/
$this->i18n();
}
/**
* Set theme supports
*/
private function add_theme_supports(): void {
// Add the theme support basic elements
add_theme_support( 'align-wide' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'html5', [ 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'script', 'style' ] );
add_theme_support( 'title-tag' );
add_theme_support( 'async-js' );
add_theme_support( 'yoast-seo-breadcrumbs' );
}
/**
* Remove theme supports
*/
private function remove_theme_supports(): void {
// remove the theme support basic elements
remove_theme_support( 'core-block-patterns' );
}
/**
* i18n
*/
private function i18n(): void {
// Load theme texdomain
load_theme_textdomain( 'framework-textdomain', \get_theme_file_path( '/languages' ) );
}
/**
* Set default path for ARI for minified files
*
* @return string
*/
public function set_ari_responsive_image_default_img_path(): string {
return '/dist/';
}
/**
* Set ari default image name for minified files
*
* @param string $default_img
*
* @return string
*
*/
public function set_ari_responsive_image_default_img_name( string $default_img ): string {
return $this->get_min_default_image( $default_img );
}
/**
* Get minified default_image
*
* @param string $original_image
*
* @return string
*
* @author Léonard Phoumpakka
*/
public function get_min_default_image( string $original_image ): string {
return $this->asset->get_min_file( 'assets/' . $original_image );
}
}