WP 4.4, plugins et shortcodes (Créer un compte)

  • Statut : non résolu
3 sujets de 1 à 3 (sur un total de 3)
  • Auteur
    Messages
  • #557208
    alexisj
    Participant
    Initié WordPress
    7 contributions

    Bonjour,

    Les changements dans WP 4.4 font que certains plugins peuvent désormais ne plus fonctionner s’ils ne sont pas correctement codés.

    C’est le cas de SpeakUp! (https://wordpress.org/plugins/speakup-email-petitions/) ou de SpeakOut! (https://wordpress.org/plugins/speakout/). Le second est un fork du premier (plus maintenu depuis un bout de temps)…

    Cela étant, je gère plusieurs sites qui utilisent SpeakUp, avec des listes de signataires de centaines de personnes… J’aimerais bien pouvoir mettre à jour vers 4.4, mais le plugin n’est pas adapté : le shortcode ne fonctionne plus…

    Est-ce que quelqu’un à un petit workaround, un conseil, ou envie de mettre les mains dans le cambouis?

    https://plugins.svn.wordpress.org/speakup-email-petitions/trunk/includes/emailpetition.php
    https://plugins.svn.wordpress.org/speakup-email-petitions/trunk/includes/signaturelist.php

    Merci d’avance 🙂

    PS: j’ai posé la même question sur les forums liés à ces plugins :
    https://wordpress.org/support/topic/shortcode-dont-works-with-wp-44?replies=1
    https://wordpress.org/support/topic/shortcode-dont-works-with-wp-44-45?replies=1

    #1031513
    luciole135
    Participant
    Maître WordPress
    13743 contributions

    Bonjour,
    J’ai installé le plugin Speakout sur un site de test local et il semble que le seul problème de ce plugin est l’appel déprécié des widget depuis WP 4.3.
    Ce plugin apparait dans la liste des plugins qui construisent les widget avec la façon de PHP 4.

    D’après cette ressource donnée dans le CODEX Notice: The Called Constructor Method For WP_Widget Is Deprecated Since Version 4.3.0! Use __construct() il suffit de modifier une seule ligne dans le fichier includes/widget.php du plugin.
    la ligne 17 de ce fichier

    $this->WP_Widget( ‘dk_speakout_petition_widget’, ‘SpeakOut! Email Petitions’, $widget_ops );

    doit être remplacée par

    parent::__construct( ‘dk_speakout_petition_widget’, ‘SpeakOut! Email Petitions’, $widget_ops );

    Et d’après le CODEX lui même Deprecating PHP4 style constructors in WordPress 4.3
    la ligne 11 de ce même fichier

    function dk_speakout_petition_widget() {

    doit être remplacée par

    function __construct() {

    ce qui donne au final le fichier includes/widget.php (de 311 lignes) suivant :

     ‘dk_speakout_widget’,
    			‘description’ => __( ‘Display a petition form.’, ‘dk_speakout’ )
    		);
    		parent::__construct( ‘dk_speakout_petition_widget’, ‘SpeakOut! Email Petitions’, $widget_ops );
    
    		// load widget scripts
    		if ( ! is_admin() && is_active_widget( false, false, $this->id_base, true ) ) {
    
    			// load the JavaScript
    			wp_enqueue_script( ‘dk_speakout_widget_js’, plugins_url( ‘speakout/js/widget.js’ ), array( ‘jquery’ ) );
    
    			// load the CSS theme
    			$options = get_option( ‘dk_speakout_options’ );
    			$theme   = $options[‘widget_theme’];
    
    			 // load default theme
    			if ( $theme === ‘default’ ) {
    				wp_enqueue_style( ‘dk_speakout_widget_css’, plugins_url( ‘speakout/css/widget.css’ ) );
    			}
    			// attempt to load cusom theme (petition-widget.css)
    			else {
    				$parent_dir       = get_template_directory_uri();
    				$parent_theme_url = $parent_dir . ‘/petition-widget.css’;
    
    				// if a child theme is in use
    				// try to load style from child theme folder
    				if ( is_child_theme() ) {
    					$child_dir        = get_stylesheet_directory_uri();
    					$child_theme_url  = $child_dir . ‘/petition-widget.css’;
    					$child_theme_path = STYLESHEETPATH . ‘/petition-widget.css’;
    
    					// use child theme if it exists
    					if ( file_exists( $child_theme_path ) ) {
    						wp_enqueue_style( ‘dk_speakout_widget_css’, $child_theme_url );
    					}
    					// else try to load style from parent theme folder
    					else {
    						wp_enqueue_style( ‘dk_speakout_widget_css’, $parent_theme_url );
    					}
    				}
    				// if not using a child theme, just try to load style from active theme folder
    				else {
    					wp_enqueue_style( ‘dk_speakout_widget_css’, $parent_theme_url );
    				}
    			}
    
    			// set up AJAX callback script
    			$protocol = isset( $_SERVER[‘HTTPS’] ) ? ‘https://’ : ‘http://’;
    			$params   = array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’, $protocol ) );
    			wp_localize_script( ‘dk_speakout_widget_js’, ‘dk_speakout_widget_js’, $params );
    		}
    	}
    
    	// create widget form (admin)
    	function form( $instance ) {
    		include_once( ‘class.petition.php’ );
    		$the_petition   = new dk_speakout_Petition();
    		$options        = get_option( ‘dk_speakout_options’ );
    		$defaults       = array( ‘title’ => __( ‘Sign the Petition’, ‘dk_speakout’ ), ‘call_to_action’ => ”, ‘sharing_url’ => ”, ‘petition_id’ => 1 );
    		$instance       = wp_parse_args( ( array ) $instance, $defaults );
    		$title          = $instance[‘title’];
    		$call_to_action = $instance[‘call_to_action’];
    		$sharing_url    = $instance[‘sharing_url’];
    		$petition_id    = $instance[‘petition_id’];
    
    		// get petitions list to fill out select box
    		$petitions = $the_petition->quicklist();
    
    		// display the form (admin)
    		echo ‘<p><label>‘ . __( ‘Title’, ‘dk_speakout’ ) . ‘:</label><br />get_field_name( ‘title’ ) . ‘” value=”‘ . stripslashes( $instance[‘title’] ) . ‘”></p>‘;
    		echo ‘<p><label>‘ . __( ‘Sharing URL’, ‘dk_speakout’ ) . ‘:</label><br />get_field_name( ‘sharing_url’ ) . ‘” value=”‘ . stripslashes( $instance[‘sharing_url’] ) . ‘”></p>‘;
    		echo ‘<p><label>‘ . __( ‘Call to Action’, ‘dk_speakout’ ) . ‘:</label><br /><textarea class="widefat">get_field_name( ‘call_to_action’ ) . ‘”>’ . $instance[‘call_to_action’] . ‘</textarea></p>‘;
    		echo ‘<p><label>‘ . __( ‘Petition’, ‘dk_speakout’ ) . ‘:</label><br />get_field_name( ‘petition_id’ ) . ‘”>’;
    		foreach ( $petitions as $petition ) {
    			$selected = ( $petition_id == $petition->id ) ? ‘ selected=”selected”‘ : ”;
    			echo ‘id . ‘” ‘ . $selected . ‘>’ . stripslashes( esc_html( $petition->title ) ) . ”;
    		}
    		echo ‘</p>‘;
    	}
    
    	// save the widget settings (admin)
    	function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    		$instance[‘title’]          = strip_tags( $new_instance[‘title’] );
    		$instance[‘sharing_url’]    = strip_tags( $new_instance[‘sharing_url’] );
    		$instance[‘call_to_action’] = strip_tags( $new_instance[‘call_to_action’] );
    		$instance[‘petition_id’]    = $new_instance[‘petition_id’];
    
    		// register widget strings in WPML
    		include_once( ‘class.wpml.php’ );
    		$wpml = new dk_speakout_WPML();
    		$wpml->register_widget( $instance );
    
    		return $instance;
    	}
    
    	// display widget (public)
    	function widget( $args, $instance ) {
    
    		global $dk_speakout_version;
    
    		include_once( ‘class.speakout.php’ );
    		include_once( ‘class.petition.php’ );
    		include_once( ‘class.wpml.php’ );
    		$options  = get_option( ‘dk_speakout_options’ );
    		$petition = new dk_speakout_Petition();
    		$wpml     = new dk_speakout_WPML();
    		extract( $args );
    
    		// get widget data
    		$instance       = $wpml->translate_widget( $instance );
    		$title          = apply_filters( ‘widget_title’, $instance[‘title’] );
    		$call_to_action = empty( $instance[‘call_to_action’] ) ? ‘ ‘ : $instance[‘call_to_action’];
    		$petition->id   = empty( $instance[‘petition_id’] ) ? 1 : absint( $instance[‘petition_id’] );
    		$get_petition   = $petition->retrieve( $petition->id );
    		$wpml->translate_petition( $petition );
    		$options = $wpml->translate_options( $options );
    
    		// set up variables for widget display
    		$userdata      = dk_speakout_SpeakOut::userinfo();
    		$expired       = ( $petition->expires == ‘1’ && current_time( ‘timestamp’ ) >= strtotime( $petition->expiration_date ) ) ? 1 : 0;
    		$greeting      = ( $petition->greeting != ” && $petition->sends_email == 1 ) ? ‘<p><span class="dk-speakout-widget-greeting">‘ . $petition->greeting . ‘</span></p>‘ : ”;
    		$optin_default = ( $options[‘optin_default’] == ‘checked’ ) ? ‘checked’ : ”;
    
    		// get language value from URL if available (for WPML)
    		$wpml_lang = ”;
    		if ( defined( ‘ICL_LANGUAGE_CODE’ ) ) {
    			$wpml_lang = ICL_LANGUAGE_CODE;
    		}
    
    		// check if petition exists…
    		// if a petition has been deleted, but its widget still exists, don’t try to display the form
    		if ( $get_petition ) {
    
    			// compose the petition widget and pop-up form
    			$petition_widget = ‘
    				<!-- SpeakOut! Email Petitions ' . $dk_speakout_version . ' -->
    				<div class="dk-speakout-widget-wrap">
    					<h3>‘ . stripslashes( esc_html( $title ) ) . ‘</h3>
    					<p>‘ . stripslashes( esc_html( $call_to_action ) ) . ‘</p>
    					<div class="dk-speakout-widget-button-wrap">
    						<a>id . ‘” class=”dk-speakout-widget-button”><span>‘ . $options[‘button_text’] . ‘</span></a>
    					</div>‘;
    			if ( $options[‘display_count’] == 1 ) {
    				$petition_widget .= ‘
    					<div class="dk-speakout-widget-progress-wrap">
    						<div class="dk-speakout-widget-signature-count">
    							<span>‘ . number_format( $petition->signatures ) . ‘</span> ‘ . _n( ‘signature’, ‘signatures’, $petition->signatures, ‘dk_speakout’ ) . ‘
    						</div>
    						‘ . dk_speakout_SpeakOut::progress_bar( $petition->goal, $petition->signatures, 150 ) . ‘
    					</div>‘;
    			}
    			$petition_widget .= ‘
    				</div>
    
    				<div id="dk-speakout-widget-windowshade"></div>
    				<div>id . ‘” class=”dk-speakout-widget-popup-wrap”>
    					<h3>‘ . stripslashes( esc_html( $petition->title ) ) . ‘</h3>
    					<div class="dk-speakout-widget-close"></div>‘;
    			if ( $petition->is_editable == 1 ) {
    				$petition_widget .= ‘
    					<div class="dk-speakout-widget-message-wrap">
    						<p class="dk-speakout-greeting">‘ . $petition->greeting . ‘</p>
    						<textarea name="dk-speakout-widget-message">id . ‘” class=”dk-speakout-widget-message”>’ . stripslashes( esc_textarea( $petition->petition_message ) ) . ‘</textarea>
    						<p class="dk-speakout-caps">[‘ . __( ‘signature’, ‘dk-speakout’ ) . ‘]</p>
    					</div>‘;
    			}
    			else {
    				$petition_widget .= ‘
    					<div class="dk-speakout-widget-message-wrap">
    						<div class="dk-speakout-widget-message">
    							<p class="dk-speakout-greeting">‘ . $petition->greeting . ‘</p>
    							‘ . stripslashes( wpautop( $petition->petition_message ) ) . ‘
    							<p class="dk-speakout-caps">[‘ . __( ‘signature’, ‘dk-speakout’ ) . ‘]</p>
    						</div>
    					</div>‘;
    			}
    			$petition_widget .= ‘
    					<div class="dk-speakout-widget-form-wrap">
    						<div class="dk-speakout-widget-response"></div>
    						<form class="dk-speakout-widget-form">
    							id . ‘” value=”‘ . esc_attr( urlencode( stripslashes( $petition->title ) ) ) .'” />
    							id . ‘” value=”‘ . esc_attr( urlencode( stripslashes( $instance[‘sharing_url’] ) ) ) .'” />
    							id . ‘” value=”‘ . dk_speakout_SpeakOut::twitter_encode( $petition->twitter_message ) .'” />
    							id . ‘” value=”‘ . $wpml_lang .'” />’;
    
    			if ( $expired ) {
    				$petition_widget .= ‘
    							<p><strong>‘ . $options[‘expiration_message’] . ‘</strong></p>
    							<p>‘ . __( ‘End date’, ‘dk_speakout’ ) . ‘: ‘ . date( ‘M d, Y’, strtotime( $petition->expiration_date ) ) . ‘</p>
    							<p>‘ . __( ‘Signatures collected’, ‘dk_speakout’ ) . ‘: ‘ . $petition->signatures . ‘</p>‘;
    				if ( $petition->goal != 0 ) {
    					$petition_widget .= ‘
    							<p><div class="dk-speakout-expired-goal"><span>‘ . __( ‘Signature goal’, ‘dk_speakout’ ) . ‘:</span> ‘ . $petition->goal . ‘</div></p>‘;
    				}
    			}
    			else {
    				$petition_widget .= ‘
    							<div class="dk-speakout-widget-full">
    								<label>id . ‘” class=”required”>’ . __( ‘First Name’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” value=”‘ . $userdata[‘firstname’] . ‘” type=”text” />
    							</div>
    							<div class="dk-speakout-widget-full">
    								<label>id . ‘” class=”required”>’ . __( ‘Last Name’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” value=”‘ . $userdata[‘lastname’] . ‘” type=”text” />
    							</div>
    							<div class="dk-speakout-widget-full">
    								<label>id . ‘” class=”required”>’ . __( ‘Email’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” value=”‘ . $userdata[’email’] . ‘” type=”text” />
    							</div>‘;
    				if ( $petition->requires_confirmation ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-full">
    								<label>id . ‘” class=”required”>’ . __( ‘Confirm Email’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” value=”” type=”text” />
    							</div>‘;
    				}
    				if ( in_array( ‘street’, $petition->address_fields ) ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-full">
    								<label>id . ‘”>’ . __( ‘Street’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” maxlength=”200″ type=”text” />
    							</div>‘;
    				}
    				if ( in_array( ‘city’, $petition->address_fields ) ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-half">
    								<label>id . ‘”>’ . __( ‘City’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” maxlength=”200″ type=”text”>
    							</div>‘;
    				}
    				if ( in_array( ‘state’, $petition->address_fields ) ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-half">
    								<label>id . ‘”>’ . __( ‘State / Province’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” maxlength=”200″ type=”text” list=”dk-speakout-states” />
    								
    									
    								
    							</div>‘;
    				}
    				if ( in_array( ‘postcode’, $petition->address_fields ) ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-half">
    								<label>id . ‘”>’ . __( ‘Post Code’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” maxlength=”200″ type=”text”>
    							</div>‘;
    				}
    				if ( in_array( ‘country’, $petition->address_fields ) ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-half">
    								<label>id . ‘”>’ . __( ‘Country’, ‘dk_speakout’ ) . ‘</label>
    								id . ‘” maxlength=”200″ type=”text” list=”dk-speakout-widget-countries” />
    								
    									
    								
    							</div>‘;
    				}
    				if( $petition->displays_custom_field == 1 ) {
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-full">
    								<label>id . ‘”>’ . stripslashes( esc_html( $petition->custom_field_label ) ) . ‘</label>
    								id . ‘” maxlength=”400″ type=”text”>
    							</div>‘;
    				}
    				if( $petition->displays_optin == 1 ) {
    					$optin_default = ( $options[‘optin_default’] == ‘checked’ ) ? ‘ checked=”checked”‘ : ”;
    					$petition_widget .= ‘
    							<div class="dk-speakout-widget-optin-wrap">
    								id . ‘”‘ . $optin_default . ‘ />
    								<label>id . ‘”>’ . stripslashes( esc_html( $petition->optin_label ) ) . ‘</label>
    							</div>‘;
    				}
    				$petition_widget .= ‘
    							<div class="dk-speakout-widget-submit-wrap">
    								<div>id . ‘” class=”dk-speakout-widget-ajaxloader” style=”visibility: hidden;”> </div>
    								<a>id . ‘” class=”dk-speakout-widget-submit”><span>‘ . stripslashes( esc_html( $options[‘button_text’] ) ) . ‘</span></a>
    							</div>
    						</form>
    						<div class="dk-speakout-widget-share">
    							<p><strong>‘ . stripslashes( esc_html( $options[‘share_message’] ) ) . ‘</strong></p>
    							<p>
    							<a class="dk-speakout-widget-facebook" href="#" title="Facebook"><span></span></a>
    							<a class="dk-speakout-widget-twitter" href="#" title="Twitter"><span></span></a>
    							</p>
    							<div class="dk-speakout-clear"></div>
    						</div>
    					</div>
    				</div>‘;
    			}
    
    			echo $petition_widget;
    		}
    	}
    
    }
    
    ?>

    Et cela devrait fonctionner.

    #1031514
    alexisj
    Participant
    Initié WordPress
    7 contributions

    Un grand merci pour votre réponse et votre temps. Je garde cela précieusement.

    Mais pour l’instant, avec SpeakUp! j’ai trouvé un contournement pour le moins trivial: le fait de mettre les shortcodes dans

    semble le faire fonctionner normalement…

    [signaturelist id=”1″]

    [emailpetition id=”1″]

3 sujets de 1 à 3 (sur un total de 3)
  • Vous devez être connecté pour répondre à ce sujet.