Добавление заявления обратной связи после сохранения пользовательских параметров темы WordPress - PullRequest
0 голосов
/ 03 августа 2020

У меня есть некая кастомная страница в WP. На этой странице должно отображаться определенное значение, которое я получаю от созданной мной настраиваемой опции темы. Обновляю почти каждую неделю. Теперь я хочу знать, что настройка была успешно записана после изменения значения, как показано на изображении ниже изображение, показывающее раздел обратной связи, который я хочу иметь

Вот мой код для добавления страницы

<?php if ( ! class_exists( 'My_paGe_settings' ) ) {
class My_paGe_settings {
public function __construct() {
    if ( is_admin() ) {
        add_action( 'admin_menu', array( 'My_paGe_settings', 'add_admin_menu' ) );
        add_action( 'admin_init', array( 'My_paGe_settings', 'register_settings' ) );
    }
}

public static function get_theme_options() {
    return get_option( 'theme_options' );
}

public static function get_theme_option( $id ) {
    $options = self::get_theme_options();
    if ( isset( $options[$id] ) ) {
        return $options[$id];
    }
}
public static function add_admin_menu() {
    add_menu_page(
    esc_html__( 'My paGe settings', 'text-domain' ),
    esc_html__( 'My paGe settings', 'text-domain' ),
    'manage_options',
    'my-page-settings',
    array( 'My_paGe_settings', 'create_admin_page' )
    );
}
public static function register_settings() {
    register_setting( 'theme_options', 'theme_options', array( 'My_paGe_settings', 'sanitize' ) );
}
public static function sanitize( $options ) {
    // sanitise input.
    if ( $options ) {
        if ( ! empty( $options['zesaBand1'] ) ) {
            $options['zesaBand1'] = sanitize_text_field( $options['zesaBand1'] );
        } else {
            unset( $options['zesaBand1'] ); // Remove from options if empty.
        }
    }
    return $options;
}

public static function create_admin_page() { ?>
<div class="wrap">
    <h1>
        <?php esc_html_e( 'Custom Settings', 'text-domain' ); ?>
    </h1>
    <form method="post" action="options.php">
        <?php settings_fields( 'theme_options' ); ?>
        <table class="form-table wpex-custom-admin-login-table">
            <?php // Text input example. ?>
            <tr valign="top">
                <th scope="row">
                    <?php esc_html_e( 'Band 1 Charge', 'text-domain' ); ?>
                </th>
                <td>
                    <?php $value = self::get_theme_option( 'zesaBand1' ); ?>
                    <input type="number" step="0.01" min="0.01" id="zesaBand1Input" name="theme_options[zesaBand1]" style="width:40%;" placeholder="Band 1 Charge" value="<?php echo esc_attr( $value ); ?>">
                </td>
            </tr>
        </table>
        <?php submit_button(); ?>
    </form>
</div><!-- .wrap -->
<?php
        }
    }
}
new My_paGe_settings();

function custom_option_get_zesa_band1() {
    return My_paGe_settings::get_theme_option( 'zesaBand1' );
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...