Domanda Errore Widget wordpress

NoName00

Utente Electrum
27 Agosto 2010
162
24
4
115
Ciao ragazzi, come da titolo sono alle prese con un plugin per wordpress, mi manda in crash tutto il sito e non riesco a venirne a capo, ho il seguente errore "Parse error: syntax error, unexpected '$servizi' (T_VARIABLE), expecting ';' or ',' in /home/pyhmrkxg/public_html/wp-content/plugins/wp-test/widget-plugin.php on line 182".
Apparentemente sembra un errore stupido ma è mezza giornata che ci sto sopra e non riesco a trovare una soluzione.

Codice:
<?php

    /*
    Plugin Name: Calcolatore
    Plugin URI: https://pianoweb.eu
    Description: This plugin adds a custom widget.
    Version: 1.0
    Author: Dumi PianoWeb
    Author URI: https://pianoweb.eu
    License: GPL2
    */

    //the widget class

    class My_Custom_Widget extends WP_WIDGET{



        //Main constructor

        public function __construct(){

            /* .. */

            parent::__construct(

                'my_custom_widget',

                __('Calcolatore', 'text_domain'),

                array(

                    'customize_selective_refresh' =>true,

                )

            );

        }



        //Widget form (per backend)

        public function form($instance){

            /*Set widget defaults*/

            $defaults = array(

                'number' => '',

                'select' => ''

            );

            //pares current settings with defaults

            extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>

            <?php //Widget title ?>

            <section id="site_header">
                <h1>Calcola il tuo preventivo gratuito</h1>
            </section>

            <!-- Number field -->

            <section class="persons">
                <h4>Persone</h4>
                <label for=""> Quante persone vuoi seguire?</label>
                <input type="number" value="1">
            </section>


            <!-- Dropdown -->

            <section>

                <label for="<?php echo $this->get_field_id( 'select' ); ?>"><?php _e( 'Scegli uno o più servizi', 'text_domain' ); ?></label>

                <select name="<?php echo $this->get_field_name( 'select' ); ?>" id="<?php echo $this->get_field_id( 'select' ); ?>" class="widefat" multiple>

                <?php

                // Your options array
                
                $servizi = array (
                        'Stalking' => '50',
                        'Infedeltà coniugale' => '100',
                        'Affidamento minori' => '150',
                        'Sicurezza informatica' => '50',
                        'Antitaccheggio' => '20',

            );
                    
                // Loop through options and add each one to the select dropdown

                foreach ( $servizi as $option => $price ) {

                    echo '<option value="' . esc_attr( $price ) . '" id="' . esc_attr( $servizi ) . '" '. selected( $select, $option, false ) . '>'. $option . '</option>';



                } ?>

                </select>

            </section>
            
            <section>
                <div class="button_box mt-2">
                    <button onclick="calcolaPrezzo()">Calcola</button>
                </div>
                <div id="prezzo_finale"></div>   
            </section>

        <?php }

        



        //update widget settings

        public function update($new_instance, $old_instance){

            $instance = $old_instance;


            $instance['number'] = isset($new_instance['number']) ? wp_strip_all_tags($new_instance['number']) : '';

            $instance['select'] = isset($new_instance['select']) ? wp_strip_all_tags( $new_instance['select'])  : '';           



            return $instance;

        }

        //Display the widget

        public function widget($args, $instance){

            extract($args);

            

            //check the widget options

            

            $number   = isset( $instance['number'] ) ? $instance['number'] : '';

            $select   = isset( $instance['select'] ) ? $instance['select'] : '';

            //WordPress core before_widget hook (includi sempre)

            
            echo $before_widget;


            //mostra widget

            echo '<div class="widget-text wp_widget_plugin_box">
                <?php //Widget title ?>

                <section id="site_header">
                    <h1>Calcola il tuo preventivo gratuito</h1>
                </section>
    
                <!-- Number field -->
    
                <section class="persons">
                    <h4>Persone</h4>
                    <label for=""> Quante persone vuoi seguire?</label>
                    <input type="number" value="1">
                </section>
                <section>
                    <select id="servizi" multiple>'
                
                        $servizi = array (
                            'Stalking' => '50',
                            'Infedeltà coniugale' => '100',
                            'Affidamento minori' => '150',
                            'Sicurezza informatica' => '50',
                            'Antitaccheggio' => '20',

            );
                    
                // Loop through options and add each one to the select dropdown

                foreach ( $servizi as $option => $price ) {

                    echo '<option value="' . esc_attr( $price ) . '" id="' . esc_attr( $servizi ) . '" '. selected( $select, $option, false ) . '>'. $option . '</option>';



                }
                   ' </select>
                </section>'
                  
                
            </div>';

  

                echo '<p>' . $select . '</p>';


        }

    }

    //Register the widget

    function my_register_custom_widget(){

        register_widget('My_Custom_Widget');

    }

    add_action('widgets_init', 'my_register_custom_widget');
    
    
    
    //funzione che calcola il prezzo
   
   
?>

Sicuramente la funzione del calcolo è da rivedere perché prima ho creato il programma in js e ora sto cercando di integrarlo in un plugin di Wordpress ma prima d'arrivare a quello di problema procederei sequenzialmente coi problemi.
 
Infatti manca solo un punto e virgola a riga 180. Anche se poi ci sono altri problemi a colpo d'occhio: dopo il foreach ci sono </select></section></div> nel nulla senza echo e con apici sbagliati.
Codice:
   <section class="persons">
                    <h4>Persone</h4>
                    <label for=""> Quante persone vuoi seguire?</label>
                    <input type="number" value="1">
                </section>
                <section>
                    <select id="servizi" multiple>'
                        
                 ?>
                 <?php
                    // Your options array
                    
                    $servizi = array (
                            'Stalking' => '50',
                            'Infedeltà coniugale' => '100',
                            'Affidamento minori' => '150',
                            'Sicurezza informatica' => '50',
                            'Antitaccheggio' => '20',
    
                    );
Mancava la chiusura del tag php dopo select, dopo averlo aggiunto mi da unexpected end of file alla fine del file come errore.. comunque non trovo dove vada messo sto punto e virgola