BPro Light). * * Two things only, the same as the "Analytics" and "Danger Zone" sections of the full plugin's BPro > Settings: * * - "Show BPro Data at the WooCommerce Analytics": adds the BPro report to WooCommerce > Analytics. * Saved through the standard WP Settings API (register_setting() + options.php). * - Danger Zone > "Reset All": a plain admin-post.php form. Forgets everything BPro Light has calculated and * recorded and rebuilds it from WooCommerce (see Bpro_Data_Light_Data::reset_all()). * * @since 1.0.0 * @package Bpro_Data_Light * @subpackage Bpro_Data_Light/admin */ class Bpro_Data_Light_Settings { const PAGE_SLUG = 'bpro-data-light-settings'; const OPTION_GROUP = 'bpro_data_light_settings_group'; /** admin-post.php action + nonce of the "Reset All" button. */ const RESET_ACTION = 'bpro_data_light_reset_all'; const RESET_NONCE = 'bpro_data_light_reset_all_nonce'; /** * Adds the page under the WooCommerce menu. */ public function add_admin_menu() { add_submenu_page( 'woocommerce', __( 'BPro Light Settings', 'bpro-data-light' ), __( 'BPro Light', 'bpro-data-light' ), 'manage_woocommerce', self::PAGE_SLUG, array( $this, 'render_page' ) ); } /** * Registers the one option. An unchecked checkbox is simply absent from $_POST, so sanitize_checkbox() turns * "present" into '1' and "absent" into ''. */ public function register_settings() { register_setting( self::OPTION_GROUP, Bpro_Data_Light_Analytics::OPTION_ENABLED, array( 'type' => 'boolean', 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), 'default' => '', ) ); } /** * @param mixed $value * @return string '1' or ''. */ public function sanitize_checkbox( $value ) { return empty( $value ) ? '' : '1'; } /** * Adds a "Settings" link to the plugin's row on the Plugins screen. * * @param string[] $links * @return string[] */ public function add_action_link( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'bpro-data-light' ) . '' ); return $links; } /** * admin_post_{RESET_ACTION}: the "Reset All" button. */ public function handle_reset_all() { check_admin_referer( self::RESET_ACTION, self::RESET_NONCE ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'bpro-data-light' ) ); } $written = Bpro_Data_Light_Data::reset_all(); wp_safe_redirect( add_query_arg( array( 'page' => self::PAGE_SLUG, 'bpro_reset' => '1', 'bpro_reset_stock' => $written, ), admin_url( 'admin.php' ) ) ); exit; } /** * Styles of the page itself. * * @param string $hook */ public function enqueue_styles( $hook ) { if ( false === strpos( (string) $hook, self::PAGE_SLUG ) ) { return; } wp_enqueue_style( 'bpro-data-light-admin', BPRO_DATA_LIGHT_PLUGIN_URL . 'admin/css/bpro-data-light-admin.css', array(), BPRO_DATA_LIGHT_VERSION ); } public function render_page() { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $option = Bpro_Data_Light_Analytics::OPTION_ENABLED; ?>

Analytics > BPro).', 'bpro-data-light' ), (int) $stock_written ); ?>