Changeset 3357912
- Timestamp:
- 09/08/2025 12:51:35 PM (7 months ago)
- File:
-
- 1 edited
-
netscore-connector/trunk/netscore-connector.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
netscore-connector/trunk/netscore-connector.php
r3357896 r3357912 15 15 } 16 16 17 /** 18 * Updated Netscore Connector main class - v1.0.3 19 * - Enqueues admin CSS from css/cuf-styles.css 20 * - Uses Settings API for saving options 21 * - Adds capability checks and nonce where relevant 22 */ 23 17 24 class Netscore_Connector { 18 25 26 private $option_group = 'netscore_connector_group'; 27 19 28 public function __construct() { 20 // Add admin menu21 29 add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); 22 // Enqueue admin CSS only on our page23 30 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_css' ) ); 24 // Register settings25 31 add_action( 'admin_init', array( $this, 'register_settings' ) ); 26 32 } 27 33 28 /**29 * Add top-level menu page30 */31 34 public function add_admin_menu() { 32 35 add_menu_page( … … 41 44 } 42 45 43 /**44 * Enqueue external CSS file for the settings page45 */46 46 public function enqueue_admin_css( $hook ) { 47 // Only load on our plugin settings page48 47 if ( $hook !== 'toplevel_page_netscore-connector' ) { 49 48 return; … … 53 52 plugin_dir_url( __FILE__ ) . 'css/cuf-styles.css', 54 53 array(), 55 '1.0. 2'54 '1.0.3' 56 55 ); 57 56 } 58 57 59 /**60 * Register settings using Settings API61 */62 58 public function register_settings() { 63 register_setting( 'netscore_connector_group', 'netscore_api_key', array(59 register_setting( $this->option_group, 'netscore_api_key', array( 64 60 'type' => 'string', 65 61 'sanitize_callback' => 'sanitize_text_field', 66 62 'default' => '' 67 63 ) ); 68 register_setting( 'netscore_connector_group', 'netscore_api_email', array(64 register_setting( $this->option_group, 'netscore_api_email', array( 69 65 'type' => 'string', 70 66 'sanitize_callback' => 'sanitize_email', … … 73 69 } 74 70 75 /**76 * Output the settings page HTML77 */78 71 public function settings_page() { 79 72 if ( ! current_user_can( 'manage_options' ) ) { … … 81 74 } 82 75 83 // Handle notices after saving84 76 if ( isset( $_GET['settings-updated'] ) ) { 85 77 add_settings_error( 'netscore_messages', 'netscore_message', __( 'Settings Saved', 'netscore-connector' ), 'updated' ); 86 78 } 87 79 settings_errors( 'netscore_messages' ); 80 81 $api_key = get_option( 'netscore_api_key', '' ); 82 $api_email = get_option( 'netscore_api_email', '' ); 88 83 ?> 89 84 <div class="wrap"> … … 92 87 </div> 93 88 94 <form class="netscore-connector-form" method="post" action="options.php" >89 <form class="netscore-connector-form" method="post" action="options.php" novalidate> 95 90 <?php 96 settings_fields( 'netscore_connector_group' ); 97 do_settings_sections( 'netscore_connector_group' ); 98 $api_key = get_option( 'netscore_api_key', '' ); 99 $api_email = get_option( 'netscore_api_email', '' ); 91 settings_fields( $this->option_group ); 92 do_settings_sections( $this->option_group ); 100 93 ?> 101 94
Note: See TracChangeset
for help on using the changeset viewer.