Merge branch 'master' into add/version-picking
This commit is contained in:
commit
3e75307f33
|
@ -138,10 +138,8 @@ class WC_Beta_Tester_Admin_Menus {
|
||||||
'title' => __( 'WC Beta Tester', 'woocommerce-beta-tester' ),
|
'title' => __( 'WC Beta Tester', 'woocommerce-beta-tester' ),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$current_channel = __( 'Stable', 'woocommerce-beta-tester' );
|
$settings = WC_Beta_Tester::get_settings();
|
||||||
$options = get_option( 'wc_beta_tester_options' );
|
switch ( $settings->channel ) {
|
||||||
if ( isset( $options['wc-beta-tester-version'] ) ) {
|
|
||||||
switch ( $options['wc-beta-tester-version'] ) {
|
|
||||||
case 'beta':
|
case 'beta':
|
||||||
$current_channel = __( 'Beta', 'woocommerce-beta-tester' );
|
$current_channel = __( 'Beta', 'woocommerce-beta-tester' );
|
||||||
break;
|
break;
|
||||||
|
@ -152,7 +150,6 @@ class WC_Beta_Tester_Admin_Menus {
|
||||||
$current_channel = __( 'Stable', 'woocommerce-beta-tester' );
|
$current_channel = __( 'Stable', 'woocommerce-beta-tester' );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Implementation of each node.
|
// TODO: Implementation of each node.
|
||||||
$nodes = array(
|
$nodes = array(
|
||||||
|
|
|
@ -12,13 +12,6 @@ defined( 'ABSPATH' ) || exit;
|
||||||
*/
|
*/
|
||||||
class WC_Beta_Tester_Settings {
|
class WC_Beta_Tester_Settings {
|
||||||
|
|
||||||
/**
|
|
||||||
* Id for channel settings field.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public static $version_setting_id = 'wc-beta-tester-version';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -41,13 +34,24 @@ class WC_Beta_Tester_Settings {
|
||||||
);
|
);
|
||||||
|
|
||||||
add_settings_field(
|
add_settings_field(
|
||||||
self::$version_setting_id,
|
'wc-beta-tester-version',
|
||||||
__( 'Release Channel', 'woocommerce-beta-tester' ),
|
__( 'Release Channel', 'woocommerce-beta-tester' ),
|
||||||
array( $this, 'version_select_html' ),
|
array( $this, 'version_select_html' ),
|
||||||
'wc-beta-tester',
|
'wc-beta-tester',
|
||||||
'wc-beta-tester-update',
|
'wc-beta-tester-update',
|
||||||
array(
|
array(
|
||||||
'label_for' => self::$version_setting_id,
|
'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',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -64,13 +68,12 @@ class WC_Beta_Tester_Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version select markup output
|
* Version select markup output.
|
||||||
*
|
*
|
||||||
* @param array $args Arguments.
|
* @param array $args Arguments.
|
||||||
*/
|
*/
|
||||||
public function version_select_html( $args ) {
|
public function version_select_html( $args ) {
|
||||||
$options = get_option( 'wc_beta_tester_options' );
|
$settings = WC_Beta_Tester::get_settings();
|
||||||
$selected = isset( $options[ $args['label_for'] ] ) ? $options[ $args['label_for'] ] : 'stable';
|
|
||||||
$channels = array(
|
$channels = array(
|
||||||
'beta' => array(
|
'beta' => array(
|
||||||
'name' => __( 'Beta Releases', 'woocommerce-beta-tester' ),
|
'name' => __( 'Beta Releases', 'woocommerce-beta-tester' ),
|
||||||
|
@ -89,7 +92,7 @@ class WC_Beta_Tester_Settings {
|
||||||
foreach ( $channels as $channel_id => $channel ) {
|
foreach ( $channels as $channel_id => $channel ) {
|
||||||
?>
|
?>
|
||||||
<label>
|
<label>
|
||||||
<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( $selected, $channel_id ); ?> />
|
<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 ); ?> />
|
||||||
<?php echo esc_html( $channel['name'] ); ?>
|
<?php echo esc_html( $channel['name'] ); ?>
|
||||||
<p class="description">
|
<p class="description">
|
||||||
<?php echo esc_html( $channel['description'] ); ?>
|
<?php echo esc_html( $channel['description'] ); ?>
|
||||||
|
@ -101,6 +104,21 @@ class WC_Beta_Tester_Settings {
|
||||||
echo '</fieldset>';
|
echo '</fieldset>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add options page to menu
|
* Add options page to menu
|
||||||
*/
|
*/
|
||||||
|
@ -116,7 +134,7 @@ class WC_Beta_Tester_Settings {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $_GET['settings-updated'] ) ) {
|
if ( isset( $_GET['settings-updated'] ) ) { // WPCS: input var.
|
||||||
add_settings_error( 'wc-beta-tester-messages', 'wc-beta-tester-message', __( 'Settings Saved', 'woocommerce-beta-tester' ), 'updated' );
|
add_settings_error( 'wc-beta-tester-messages', 'wc-beta-tester-message', __( 'Settings Saved', 'woocommerce-beta-tester' ), 'updated' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,23 @@ class WC_Beta_Tester {
|
||||||
delete_site_transient( 'woocommerce_latest_tag' );
|
delete_site_transient( 'woocommerce_latest_tag' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get plugin settings.
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
public static function get_settings() {
|
||||||
|
$settings = (object) wp_parse_args(
|
||||||
|
get_option( 'wc_beta_tester_options', array() ),
|
||||||
|
array(
|
||||||
|
'channel' => 'stable',
|
||||||
|
'auto_update' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$settings->auto_update = (bool) $settings->auto_update;
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin url.
|
* Get the plugin url.
|
||||||
*
|
*
|
||||||
|
@ -69,6 +86,7 @@ class WC_Beta_Tester {
|
||||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'api_check' ) );
|
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'api_check' ) );
|
||||||
add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 );
|
add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 );
|
||||||
add_filter( 'upgrader_source_selection', array( $this, 'upgrader_source_selection' ), 10, 3 );
|
add_filter( 'upgrader_source_selection', array( $this, 'upgrader_source_selection' ), 10, 3 );
|
||||||
|
add_filter( 'auto_update_plugin', 'auto_update_woocommerce', 100, 2 );
|
||||||
|
|
||||||
$this->includes();
|
$this->includes();
|
||||||
}
|
}
|
||||||
|
@ -326,10 +344,25 @@ class WC_Beta_Tester {
|
||||||
return $source;
|
return $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable auto updates for WooCommerce.
|
||||||
|
*
|
||||||
|
* @param bool $update Should this autoupdate.
|
||||||
|
* @param object $plugin Plugin being checked.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function auto_update_woocommerce( $update, $plugin ) {
|
||||||
|
if ( true === $this->get_settings()->auto_update && 'woocommerce' === $item->slug ) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return $update;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets release information from GitHub.
|
* Gets release information from GitHub.
|
||||||
*
|
*
|
||||||
* @param string $version
|
* @param string $version Version number.
|
||||||
* @return bool|string False on error, description otherwise
|
* @return bool|string False on error, description otherwise
|
||||||
*/
|
*/
|
||||||
public function get_version_information( $version ) {
|
public function get_version_information( $version ) {
|
||||||
|
|
Loading…
Reference in New Issue