-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.php
More file actions
72 lines (64 loc) · 2.2 KB
/
settings.php
File metadata and controls
72 lines (64 loc) · 2.2 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
<?php
// Защита от прямого доступа к файлу
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class WebP_Converter_Admin_Page {
/**
* Инициализация страницы настроек
*/
public function init() {
add_action( 'admin_menu', array( $this, 'add_admin_page' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
}
/**
* Добавление страницы настроек в админ-панель
*/
public function add_admin_page() {
add_submenu_page(
'woocommerce',
__( 'WebP Converter Settings', 'webp-converter' ),
__( 'WebP Converter', 'webp-converter' ),
'manage_options',
'webp-converter',
array( $this, 'settings_page' )
);
}
/**
* Отображение страницы настроек
*/
public function settings_page() {
?>
<div class="wrap">
<h1><?php esc_html_e( 'WebP Converter Settings', 'webp-converter' ); ?></h1>
<form action="options.php" method="post">
<?php settings_fields( 'webp_converter_settings' ); ?>
<?php do_settings_sections( 'webp_converter_settings' ); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="webp_converter_enabled"><?php esc_html_e( 'Enable WebP Conversion', 'webp-converter' ); ?></label>
</th>
<td>
<input type="checkbox" id="webp_converter_enabled" name="webp_converter_enabled" value="1" <?php checked( get_option( 'webp_converter_enabled' ), 1 ); ?>>
<label for="webp_converter_enabled"><?php esc_html_e( 'Enable WebP conversion for product images', 'webp-converter' ); ?></label>
</td>
</tr>
</tbody>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
/**
* Регистрация настроек
*/
public function register_settings() {
register_setting( 'webp_converter_settings', 'webp_converter_enabled' );
}
}
// Инициализация страницы настроек
$webp_converter_admin_page = new WebP_Converter_Admin_Page();
$webp_converter_admin_page->init();