woocommerce/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-channe...

164 lines
5.1 KiB
PHP
Raw Normal View History

2018-06-05 11:11:39 +00:00
<?php
/**
* Beta Tester plugin settings class
*
* @package WC_Beta_Tester
*/
defined( 'ABSPATH' ) || exit;
/**
* Settings Class.
*/
2023-08-09 00:20:34 +00:00
class WC_Beta_Tester_Channel {
2018-06-05 11:11:39 +00:00
/**
* Constructor
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'settings_init' ) );
add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
}
/**
* Initialise settings
*/
public function settings_init() {
register_setting( 'wc-beta-tester', 'wc_beta_tester_options' );
add_settings_section(
'wc-beta-tester-update',
2018-06-25 14:00:00 +00:00
__( 'Settings', 'woocommerce-beta-tester' ),
2018-06-05 11:11:39 +00:00
array( $this, 'update_section_html' ),
'wc-beta-tester'
);
add_settings_field(
2018-06-06 15:14:32 +00:00
'wc-beta-tester-channel',
2018-06-06 14:14:27 +00:00
__( 'Release Channel', 'woocommerce-beta-tester' ),
2018-06-05 11:11:39 +00:00
array( $this, 'version_select_html' ),
'wc-beta-tester',
'wc-beta-tester-update',
array(
2018-06-06 15:14:32 +00:00
'label_for' => 'channel',
)
);
add_settings_field(
'wc-beta-tester-auto-update',
__( 'Automatic Updates', 'woocommerce-beta-tester' ),
array( $this, 'automatic_update_checkbox_html' ),
'wc-beta-tester',
'wc-beta-tester-update',
array(
'label_for' => 'auto_update',
2018-06-05 11:11:39 +00:00
)
);
}
/**
* Update section HTML output.
*
* @param array $args Arguments.
*/
public function update_section_html( $args ) {
2023-08-09 00:20:34 +00:00
?>
2018-06-06 14:14:27 +00:00
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'The following settings allow you to choose which WooCommerce updates to receive on this site, including beta and RC versions not quite ready for production deployment.', 'woocommerce-beta-tester' ); ?></p>
2023-08-09 00:20:34 +00:00
<?php
2018-06-05 11:11:39 +00:00
}
/**
2018-06-06 15:14:32 +00:00
* Version select markup output.
2018-06-05 11:11:39 +00:00
*
* @param array $args Arguments.
*/
public function version_select_html( $args ) {
2018-06-06 15:14:32 +00:00
$settings = WC_Beta_Tester::get_settings();
2018-06-06 14:14:27 +00:00
$channels = array(
'beta' => array(
2018-06-06 14:14:27 +00:00
'name' => __( 'Beta Releases', 'woocommerce-beta-tester' ),
'description' => __( 'Beta releases contain experimental functionality for testing purposes only. This channel will also include RC and stable releases if more current.', 'woocommerce-beta-tester' ),
),
'rc' => array(
2018-06-06 14:14:27 +00:00
'name' => __( 'Release Candidates', 'woocommerce-beta-tester' ),
'description' => __( 'Release candidates are released to ensure any critical problems have not gone undetected. This channel will also include stable releases if more current.', 'woocommerce-beta-tester' ),
),
'stable' => array(
'name' => __( 'Stable Releases', 'woocommerce-beta-tester' ),
2018-06-07 11:11:40 +00:00
'description' => __( 'This is the default behavior in WordPress.', 'woocommerce-beta-tester' ),
2018-06-06 14:14:27 +00:00
),
);
echo '<fieldset><legend class="screen-reader-text"><span>' . esc_html__( 'Update Channel', 'woocommerce-beta-tester' ) . '</span></legend>';
foreach ( $channels as $channel_id => $channel ) {
?>
<label>
2018-06-06 15:14:32 +00:00
<input type="radio" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="wc_beta_tester_options[<?php echo esc_attr( $args['label_for'] ); ?>]" value="<?php echo esc_attr( $channel_id ); ?>" <?php checked( $settings->{ $args['label_for'] }, $channel_id ); ?> />
2018-06-06 14:14:27 +00:00
<?php echo esc_html( $channel['name'] ); ?>
<p class="description">
<?php echo esc_html( $channel['description'] ); ?>
</p>
</label>
<br>
<?php
}
echo '</fieldset>';
2018-06-05 11:11:39 +00:00
}
2018-06-06 15:14:32 +00:00
/**
* Auto updates checkbox markup output.
*
* @param array $args Arguments.
*/
public function automatic_update_checkbox_html( $args ) {
$settings = WC_Beta_Tester::get_settings();
?>
<label for="<?php echo esc_attr( $args['label_for'] ); ?>">
<input type="checkbox" id="<?php echo esc_attr( $args['label_for'] ); ?>" name="wc_beta_tester_options[<?php echo esc_attr( $args['label_for'] ); ?>]" value="1" <?php checked( $settings->{ $args['label_for'] }, true ); ?> />
<?php echo esc_html__( 'If enabled, WooCommerce will update to the latest release in the background. Use with caution; we do not recommend using this on production stores!', 'woocommerce-beta-tester' ); ?>
</label>
<?php
}
2018-06-05 11:11:39 +00:00
/**
* Add options page to menu
*/
public function add_to_menus() {
add_submenu_page( 'plugins.php', __( 'WooCommerce Beta Tester', 'woocommerce-beta-tester' ), __( 'WC Beta Tester', 'woocommerce-beta-tester' ), 'install_plugins', 'wc-beta-tester', array( $this, 'settings_page_html' ) );
2018-06-05 11:11:39 +00:00
}
/**
* Output settings HTML
*/
public function settings_page_html() {
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
2023-08-09 00:20:34 +00:00
// This is just for giving a message, the option form itself will have validated the nonce.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['settings-updated'] ) ) {
2018-06-05 11:11:39 +00:00
add_settings_error( 'wc-beta-tester-messages', 'wc-beta-tester-message', __( 'Settings Saved', 'woocommerce-beta-tester' ), 'updated' );
}
// show error/update messages.
settings_errors( 'wc-beta-tester-messages' );
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form action="options.php" method="post">
<?php
settings_fields( 'wc-beta-tester' );
do_settings_sections( 'wc-beta-tester' );
2018-06-06 14:14:27 +00:00
submit_button();
2018-06-05 11:11:39 +00:00
?>
</form>
</div>
<?php
}
}
2023-08-09 00:20:34 +00:00
new WC_Beta_Tester_Channel();