Plugin Directory

Changeset 3357921


Ignore:
Timestamp:
09/08/2025 12:58:34 PM (5 months ago)
Author:
netscoretechnologies2011
Message:

initial commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • netscore-connector/tags/1.0.0/netscore-connector.php

    r3357846 r3357921  
    1111
    1212
    13 
    14 
    15 // Prevent direct access
    1613if ( ! defined( 'ABSPATH' ) ) {
    17     exit;
     14    exit; // Exit if accessed directly
    1815}
    1916
    20 // Add admin menu page
    21 add_action( 'admin_menu', function() {
    22     add_menu_page(
    23         __( 'NetScore Connector', 'netscore-connector' ),
    24         __( 'NetScore Connector', 'netscore-connector' ),
    25         'manage_options',
    26         'netscore-connector',
    27         'netscore_connector_admin_page'
    28     );
    29 } );
     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 */
    3023
    31 /**
    32  * Render admin page and handle form submission
    33  */
    34 function netscore_connector_admin_page() {
    35     // Form submission handling
    36     if ( isset( $_POST['netscore_connector_submit'] ) ) {
     24class Netscore_Connector {
    3725
    38         // Step 1: Safely retrieve and sanitize nonce
    39         $nonce = isset( $_POST['netscore_connector_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['netscore_connector_nonce'] ) ) : '';
     26    private $option_group = 'netscore_connector_group';
    4027
    41         // Step 2: Verify nonce immediately
    42         if ( ! wp_verify_nonce( $nonce, 'netscore_connector_action' ) ) {
    43             echo '<div class="notice notice-error"><p>' . esc_html__( 'Nonce verification failed.', 'netscore-connector' ) . '</p></div>';
    44             return; // Stop processing if nonce invalid
     28    public function __construct() {
     29        add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
     30        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_css' ) );
     31        add_action( 'admin_init', array( $this, 'register_settings' ) );
     32    }
     33
     34    public function add_admin_menu() {
     35        add_menu_page(
     36            __( 'Netscore Connector', 'netscore-connector' ),
     37            __( 'Netscore Connector', 'netscore-connector' ),
     38            'manage_options',
     39            'netscore-connector',
     40            array( $this, 'settings_page' ),
     41            'dashicons-networking',
     42            56
     43        );
     44    }
     45
     46    public function enqueue_admin_css( $hook ) {
     47        if ( $hook !== 'toplevel_page_netscore-connector' ) {
     48            return;
     49        }
     50        wp_enqueue_style(
     51            'netscore-connector-admin',
     52            plugin_dir_url( __FILE__ ) . 'css/cuf-styles.css',
     53            array(),
     54            '1.0.3'
     55        );
     56    }
     57
     58    public function register_settings() {
     59        register_setting( $this->option_group, 'netscore_api_key', array(
     60            'type' => 'string',
     61            'sanitize_callback' => 'sanitize_text_field',
     62            'default' => ''
     63        ) );
     64        register_setting( $this->option_group, 'netscore_api_email', array(
     65            'type' => 'string',
     66            'sanitize_callback' => 'sanitize_email',
     67            'default' => ''
     68        ) );
     69    }
     70
     71    public function settings_page() {
     72        if ( ! current_user_can( 'manage_options' ) ) {
     73            return;
    4574        }
    4675
    47         // Step 3: Sanitize all form inputs
    48         $name     = isset( $_POST['netscore_connector_name'] ) ? sanitize_text_field( wp_unslash( $_POST['netscore_connector_name'] ) ) : '';
    49         $email    = isset( $_POST['netscore_connector_email'] ) ? sanitize_email( wp_unslash( $_POST['netscore_connector_email'] ) ) : '';
    50         $comments = isset( $_POST['netscore_connector_comments'] ) ? sanitize_textarea_field( wp_unslash( $_POST['netscore_connector_comments'] ) ) : '';
     76        if ( isset( $_GET['settings-updated'] ) ) {
     77            add_settings_error( 'netscore_messages', 'netscore_message', __( 'Settings Saved', 'netscore-connector' ), 'updated' );
     78        }
     79        settings_errors( 'netscore_messages' );
    5180
    52         // Step 4: Validate email
    53         if ( ! is_email( $email ) ) {
    54             echo '<div class="notice notice-error"><p>' . esc_html__( 'Invalid email address.', 'netscore-connector' ) . '</p></div>';
    55         } else {
    56             // Step 5: Send email to admin
    57             wp_mail(
    58                 get_option( 'admin_email' ),
    59                 __( 'New NetScore Connector Submission', 'netscore-connector' ),
    60                 "Name: $name\nEmail: $email\nComments:\n$comments"
    61             );
     81        $api_key = get_option( 'netscore_api_key', '' );
     82        $api_email = get_option( 'netscore_api_email', '' );
     83        ?>
     84        <div class="wrap">
     85            <div class="netscore-header">
     86                <h1><?php esc_html_e( 'Netscore Connector Settings', 'netscore-connector' ); ?></h1>
     87            </div>
    6288
    63             echo '<div class="notice notice-success"><p>' . esc_html__( 'Form submitted successfully!', 'netscore-connector' ) . '</p></div>';
    64         }
     89            <form class="netscore-connector-form" method="post" action="options.php" novalidate>
     90                <?php
     91                settings_fields( $this->option_group );
     92                do_settings_sections( $this->option_group );
     93                ?>
     94
     95                <table class="form-table">
     96                    <tr>
     97                        <th scope="row"><label for="netscore_api_key"><?php esc_html_e( 'API Key', 'netscore-connector' ); ?></label></th>
     98                        <td>
     99                            <input name="netscore_api_key" type="text" id="netscore_api_key" value="<?php echo esc_attr( $api_key ); ?>" class="regular-text" />
     100                            <p class="description"><?php esc_html_e( 'Your NetSuite API key or token.', 'netscore-connector' ); ?></p>
     101                        </td>
     102                    </tr>
     103
     104                    <tr>
     105                        <th scope="row"><label for="netscore_api_email"><?php esc_html_e( 'Contact Email', 'netscore-connector' ); ?></label></th>
     106                        <td>
     107                            <input name="netscore_api_email" type="email" id="netscore_api_email" value="<?php echo esc_attr( $api_email ); ?>" class="regular-text" />
     108                            <p class="description"><?php esc_html_e( 'Email used for API account or license notifications.', 'netscore-connector' ); ?></p>
     109                        </td>
     110                    </tr>
     111                </table>
     112
     113                <?php submit_button( __( 'Save Settings', 'netscore-connector' ) ); ?>
     114            </form>
     115        </div>
     116        <?php
    65117    }
     118}
    66119
    67     // Step 6: Display the form
    68     ?>
    69     <div class="wrap">
    70         <h1><?php esc_html_e( 'NetScore Connector Form', 'netscore-connector' ); ?></h1>
    71         <form method="post" action="">
    72             <?php wp_nonce_field( 'netscore_connector_action', 'netscore_connector_nonce' ); ?>
    73             <table class="form-table">
    74                 <tr>
    75                     <th><label for="netscore_connector_name"><?php esc_html_e( 'Name', 'netscore-connector' ); ?></label></th>
    76                     <td><input type="text" id="netscore_connector_name" name="netscore_connector_name" class="regular-text" required></td>
    77                 </tr>
    78                 <tr>
    79                     <th><label for="netscore_connector_email"><?php esc_html_e( 'Email', 'netscore-connector' ); ?></label></th>
    80                     <td><input type="email" id="netscore_connector_email" name="netscore_connector_email" class="regular-text" required></td>
    81                 </tr>
    82                 <tr>
    83                     <th><label for="netscore_connector_comments"><?php esc_html_e( 'Comments', 'netscore-connector' ); ?></label></th>
    84                     <td><textarea id="netscore_connector_comments" name="netscore_connector_comments" class="large-text" rows="5"></textarea></td>
    85                 </tr>
    86             </table>
    87             <p>
    88                 <input type="submit" name="netscore_connector_submit" class="button button-primary" value="<?php esc_attr_e( 'Submit', 'netscore-connector' ); ?>">
    89             </p>
    90         </form>
    91     </div>
    92     <?php
    93 }
     120// Initialize plugin
     121new Netscore_Connector();
Note: See TracChangeset for help on using the changeset viewer.