| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Admin; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Settings |
| 7 |
* |
| 8 |
* @package SpringDevs\Subscription\Admin |
| 9 |
*/ |
| 10 |
class Settings { |
| 11 |
|
| 12 |
/** |
| 13 |
* Initialize the class. |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
add_action( 'admin_menu', array( $this, 'admin_menu' ), 30 ); |
| 17 |
add_action( 'admin_init', array( $this, 'register_settings' ) ); |
| 18 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_wc_admin_styles' ) ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Register submenu on `Subscriptions` menu. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function admin_menu() { |
| 27 |
$post_type_link = 'edit.php?post_type=subscrpt_order'; |
| 28 |
|
| 29 |
add_submenu_page( |
| 30 |
$post_type_link, |
| 31 |
__( 'WP Subscription Settings', 'wp_subscription' ), |
| 32 |
__( 'Settings', 'wp_subscription' ), |
| 33 |
'manage_options', |
| 34 |
'edit.php?post_type=wp_subscription_settings', |
| 35 |
array( $this, 'settings_content' ), |
| 36 |
40 |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Register settings options. |
| 42 |
**/ |
| 43 |
public function register_settings() { |
| 44 |
register_setting( 'wp_subscription_settings', 'wp_subscription_renewal_process' ); |
| 45 |
register_setting( 'wp_subscription_settings', 'wp_subscription_manual_renew_cart_notice' ); |
| 46 |
register_setting( 'wp_subscription_settings', 'wp_subscription_active_role' ); |
| 47 |
register_setting( 'wp_subscription_settings', 'wp_subscription_unactive_role' ); |
| 48 |
register_setting( 'wp_subscription_settings', 'wp_subscription_stripe_auto_renew' ); |
| 49 |
register_setting( 'wp_subscription_settings', 'wp_subscription_auto_renewal_toggle' ); |
| 50 |
|
| 51 |
do_action( 'subscrpt_register_settings', 'subscrpt_settings' ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Settings HTML. |
| 56 |
*/ |
| 57 |
public function settings_content() { |
| 58 |
include 'views/settings.php'; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Enqueue WooCommerce admin styles for settings page. |
| 63 |
*/ |
| 64 |
public function enqueue_wc_admin_styles( $hook ) { |
| 65 |
// Only load on our settings page |
| 66 |
if ( isset( $_GET['post_type'] ) && strpos( $_GET['post_type'], 'subscrpt_order' ) !== false ) { |
| 67 |
// WooCommerce admin styles |
| 68 |
wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); |
| 69 |
// Optional: WooCommerce enhanced select2 |
| 70 |
wp_enqueue_style( 'woocommerce_admin_select2', WC()->plugin_url() . '/assets/css/select2.css', array(), WC_VERSION ); |
| 71 |
wp_enqueue_script( 'select2' ); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|