Problème thème newspaper

Résolu/Fermé
Abdou2011_75 Messages postés 3 Date d'inscription mercredi 3 juin 2020 Statut Membre Dernière intervention 5 juin 2020 - 3 juin 2020 à 19:50
Abdou2011_75 Messages postés 3 Date d'inscription mercredi 3 juin 2020 Statut Membre Dernière intervention 5 juin 2020 - 5 juin 2020 à 08:48
Bonjour;
Bonjour à tous !

Petite aide svp, ces codes ci-dessous me revois l'erreur suivante :

1er probleme:

Warning: Illegal string offset 'std' ......field_color.php on line 16

Warning: Cannot assign an empty string to a string offset in ..... field_color.php on line 16

voici ce que j'ai dans le programme du fichier field_color.php
qui donne le warning:

11- function __construct($field = array(), $value ='', $parent){
12-
13- parent::__construct($parent->sections, $parent->args, $parent->extra_tabs);14-
14- $this->field = $field;
15- if (empty($this->field['std']))
16- $this->field['std'] = '';
17- $this->value = $value;
18- //$this->render();





2éme problème Warning: Illegal string offset 'class' in ..... on line 34
Warning: Cannot assign an empty string to a string offset ..... on line 34

voici ce que j'ai dans le programme du fichier layout.php
qui donne le warning:

30 //parent::__construct( $parent->sections, $parent->args );
31 $this->parent = $parent;
32 $this->field = $field;
33 if (empty($this->field['class']))
34 $this->field['class'] = '';
35 $this->value = $value;
36 $this->args = $parent->args;
37 }



3ème problème:
Warning: Illegal string offset 'class' in ..... layout2.php on line 36
Warning: Cannot assign an empty string to a string offset in .....layout2.php on line 36

voici ce que j'ai dans le programme du fichier layout2.php
qui donne le warning:

30- function __construct( $field = array(), $value ='', $parent ) {
31-
32- //parent::__construct( $parent->sections, $parent->args );
33- $this->parent = $parent;
34- $this->field = $field;
35- if (empty($this->field['class']))
36- $this->field['class'] = '';
37- $this->value = $value;
38- $this->args = $parent->args;
39- }



Un GRAND MERCI d'avance
A voir également:

3 réponses

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
4 juin 2020 à 08:31
Bonjour,

Commence par nous poster les codes de tes fichiers ( codes complets )

NB: Pour poster ton code, tu dois utiliser les BALISES DE CODE.
Explications à lire ENTIEREMENT disponibles ici : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

1
Abdou2011_75 Messages postés 3 Date d'inscription mercredi 3 juin 2020 Statut Membre Dernière intervention 5 juin 2020
Modifié le 5 juin 2020 à 08:35
Bonjour;
Merci à votre réaction
je suis presque nul dans ce domaine
si je suis bien compris ton message
voici la modification sur ma demande d'aide:

Petite aide svp, ces codes ci-dessous me revois l'erreur suivante :

1er probleme:


Warning: Illegal string offset 'std' ......field_color.php on line 16

Warning: Cannot assign an empty string to a string offset in ..... field_color.php on line 16

voici ce que j'ai dans le programme du fichier field_color.php
qui donne le warning:

<?php
class NHP_Options_color extends NHP_Options{	
	
	/**
	 * Field Constructor.
	 *
	 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
	 *
	 * @since NHP_Options 1.0
	*/
	function __construct($field = array(), $value ='', $parent){
		
		parent::__construct($parent->sections, $parent->args, $parent->extra_tabs);
		$this->field = $field;
		if (empty($this->field['std']))
			$this->field['std'] = '';
		$this->value = $value;
		//$this->render();
		
	}//function
	
	
	
	/**
	 * Field Render Function.
	 *
	 * Takes the vars and outputs the HTML for the field in the settings
	 *
	 * @since NHP_Options 1.0
	*/
	function render(){
		$class = (isset($this->field['class']))?$this->field['class']:'';
		echo '<input type="text" id="'.$this->field['id'].'" name="'.$this->args['opt_name'].'['.$this->field['id'].']" value="'.$this->value.'" class="'.$class.' popup-colorpicker" data-default-color="'.$this->field['std'].'" />';
		
	}//function
	
	
	/**
	 * Enqueue Function.
	 *
	 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
	 *
	 * @since NHP_Options 1.0
	*/
	function enqueue(){
		
		wp_enqueue_script(
			'nhp-opts-field-color-js', 
			NHP_OPTIONS_URL.'fields/color/field_color.js', 
			array('jquery', 'wp-color-picker'),//'farbtastic'),
			MTS_THEME_VERSION,
			true
		);

		wp_enqueue_style('wp-color-picker');
		
	}//function
	
}//class
?>




2éme problème Warning: Illegal string offset 'class' in ..... on line 34
Warning: Cannot assign an empty string to a string offset ..... on line 34

voici ce que j'ai dans le programme du fichier layout.php
qui donne le warning:

<?php

/**
 * Options Sorter Field for Redux Options
 * @author  Yannis - Pastis Glaros <mrpc@pramnoshosting.gr>
 * @url	 http://www.pramhost.com
 * @license [http://www.gnu.org/copyleft/gpl.html GPLv3
 *
 * This is actually based on: [SMOF - Slightly Modded Options Framework](http://aquagraphite.com/2011/09/slightly-modded-options-framework/)
 * Original Credits:
 * Author		: Syamil MJ
 * Author URI   	: http://aquagraphite.com
 * License		: GPLv3 - http://www.gnu.org/copyleft/gpl.html
 * Credits		: Thematic Options Panel - http://wptheming.com/2010/11/thematic-options-panel-v2/
  KIA Thematic Options Panel - https://github.com/helgatheviking/thematic-options-KIA
  Woo Themes - http://woothemes.com/
  Option Tree - http://wordpress.org/extend/plugins/option-tree/
 * Twitter: http://twitter.com/syamilmj
 * Website: http://aquagraphite.com
 */
class NHP_Options_layout extends NHP_Options {

	/**
	 * Field Constructor.
	 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
	 * @since Redux_Options 1.0.0
	 */
	function __construct( $field = array(), $value ='', $parent ) {
	
		//parent::__construct( $parent->sections, $parent->args );
		$this->parent = $parent;
		$this->field = $field;
		if (empty($this->field['class']))
			$this->field['class'] = '';
		$this->value = $value;
		$this->args = $parent->args;
	}

	/**
	 * Field Render Function.
	 * Takes the vars and outputs the HTML for the field in the settings
	 * @since 1.0.0
	 */
	function render() {

		if (!is_array($this->value) && isset($this->field['options'])) {
			$this->value = $this->field['options'];
		}		

		// Make sure to get list of all the default blocks first
		$all_blocks = !empty( $this->field['options'] ) ? $this->field['options'] : array();

		$temp = array(); // holds default blocks
		$temp2 = array(); // holds saved blocks

		foreach($all_blocks as $blocks) {
			$temp = array_merge($temp, $blocks);
		}

		$sortlists = $this->value;

		if ( is_array( $sortlists ) ) {
			foreach( $sortlists as $sortlist ) {
				$temp2 = array_merge($temp2, $sortlist);
			}

			// now let's compare if we have anything missing
			foreach($temp as $k => $v) {
				if(!array_key_exists($k, $temp2)) {
					$sortlists['disabled'][$k] = $v;
				}
			}

			// now check if saved blocks has blocks not registered under default blocks
			foreach( $sortlists as $key => $sortlist ) {
				foreach($sortlist as $k => $v) {
					if(!array_key_exists($k, $temp)) {
					unset($sortlist[$k]);
					}
				}
				$sortlists[$key] = $sortlist;
			}

			// assuming all sync'ed, now get the correct naming for each block
			foreach( $sortlists as $key => $sortlist ) {
				foreach($sortlist as $k => $v) {
					$sortlist[$k] = $temp[$k];
				}
				$sortlists[$key] = $sortlist;
			}



				if ($sortlists) {
					echo '<fieldset id="'.$this->field['id'].'" class="nhp-opts-sorter-container nhp-opts-sorter">';
					
//					if (empty($sortlists['disabled'])) $sortlists['disabled'] = array();
//					if (empty($sortlists['enabled'])) $sortlists['enabled'] = array();
					// go through field[options] and make sure they exist as a group
					foreach ($all_blocks as $default_block => $val) {
						if (empty($sortlists[$default_block]))
							$sortlists[$default_block] = array();
					}
					
					foreach ( $sortlists as $group => $sortlist ) {
						$filled = "";

						if ( isset( $this->field['limits'][$group] ) && count( $sortlist ) >= $this->field['limits'][$group] ) {
							$filled = " filled";
						}

						echo '<ul id="'.$this->field['id'].'_'.$group.'" class="sortlist_'.$this->field['id'].$filled.'" data-id="'.$this->field['id'].'" data-group-id="' . $group . '">';
						echo '<h3>'.$group.'</h3>';

						if (!isset($sortlist['placebo'])){
							array_unshift($sortlist, array( "placebo" => "placebo" ));
						}

						foreach ($sortlist as $key => $list) {

							//echo '<input class="sorter-placebo" type="hidden" name="' . $this->args['opt_name'].'['.$this->field['id'].'][' . $group . '][placebo]" value="placebo">';

							if ($key != "placebo") {

								echo '<li id="'.$key.'" class="sortee">';
								echo '<input class="position '.$this->field['class'].'" type="hidden" name="' . $this->args['opt_name'].'['.$this->field['id'].'][' . $group . '][' . $key . ']" value="'.$list.'">';
								echo $list;
								echo '</li>';

							}

						}

						echo '</ul>';
					}
					echo '</fieldset>';
					// debug
					// $options = get_option($this->args['opt_name']);
					// echo '<pre>'.print_r($options[$this->field['id']], 1).'</pre>';
				}
			}


		
	}

	function enqueue() {
		
		wp_enqueue_style('nhp-opts-jquery-ui-css');
		wp_enqueue_style('nhp-opts-field-layout-css', NHP_OPTIONS_URL.'fields/layout/field_layout.css');
		
		wp_enqueue_script('jquery-ui-core');
		wp_enqueue_script('jquery-ui-sortable');
		
		wp_enqueue_script(
			'nhp-opts-field-layout-js', 
			NHP_OPTIONS_URL.'fields/layout/field_layout.js', 
			array('jquery', 'jquery-ui-core', 'jquery-ui-sortable'),
			MTS_THEME_VERSION,
			true
		);

	}


}



3ème problème:
Warning: Illegal string offset 'class' in ..... layout2.php on line 36
Warning: Cannot assign an empty string to a string offset in .....layout2.php on line 36

voici ce que j'ai dans le programme du fichier layout2.php
qui donne le warning:

<?php

/**
 * Alternative layout field ( blocks can have sub fields )
 *
 * Options Sorter Field for Redux Options
 * @author  Yannis - Pastis Glaros <mrpc@pramnoshosting.gr>
 * @url	 http://www.pramhost.com
 * @license [http://www.gnu.org/copyleft/gpl.html GPLv3
 *
 * This is actually based on: [SMOF - Slightly Modded Options Framework](http://aquagraphite.com/2011/09/slightly-modded-options-framework/)
 * Original Credits:
 * Author		: Syamil MJ
 * Author URI   	: http://aquagraphite.com
 * License		: GPLv3 - http://www.gnu.org/copyleft/gpl.html
 * Credits		: Thematic Options Panel - http://wptheming.com/2010/11/thematic-options-panel-v2/
  KIA Thematic Options Panel - https://github.com/helgatheviking/thematic-options-KIA
  Woo Themes - http://woothemes.com/
  Option Tree - http://wordpress.org/extend/plugins/option-tree/
 * Twitter: http://twitter.com/syamilmj
 * Website: http://aquagraphite.com
 */
class NHP_Options_layout2 extends NHP_Options {

	/**
	 * Field Constructor.
	 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
	 * @since Redux_Options 1.0.0
	 */
	function __construct( $field = array(), $value ='', $parent ) {

		//parent::__construct( $parent->sections, $parent->args );
		$this->parent = $parent;
		$this->field = $field;
		if (empty($this->field['class']))
			$this->field['class'] = '';
		$this->value = $value;
		$this->args = $parent->args;
	}

	/**
	 * Field Render Function.
	 * Takes the vars and outputs the HTML for the field in the settings
	 * @since 1.0.0
	 */
	function render() {

		if (!is_array($this->value) && isset($this->field['options'])) {
			$this->value = $this->field['options'];
		}

		// Make sure to get list of all the default blocks first
		$all_blocks = !empty( $this->field['options'] ) ? $this->field['options'] : array();

		$temp = array(); // holds default blocks
		$temp2 = array(); // holds saved blocks

		foreach($all_blocks as $blocks) {
			$temp = array_merge($temp, $blocks);
		}

		$sortlists = $this->value;

		if ( is_array( $sortlists ) ) {
			foreach( $sortlists as $sortlist ) {
				$temp2 = array_merge($temp2, $sortlist);
			}

			// now let's compare if we have anything missing
			foreach( $temp as $k => $v ) {
				if(!array_key_exists($k, $temp2)) {
					$sortlists['disabled'][$k] = $v;
				}
			}

			// now check if saved blocks has blocks not registered under default blocks
			foreach( $sortlists as $key => $sortlist ) {
				foreach($sortlist as $k => $v) {
					if(!array_key_exists($k, $temp)) {
						unset($sortlist[$k]);
					}
				}
				$sortlists[$key] = $sortlist;
			}

			// assuming all sync'ed, now get the correct naming for each block
			foreach( $sortlists as $key => $sortlist ) {
				foreach($sortlist as $k => $v) {
					$sortlist[$k] = $temp[$k];
				}
				$sortlists[$key] = $sortlist;
			}

			if ($sortlists) {
				echo '<fieldset id="'.$this->field['id'].'" class="nhp-opts-sorter-container-alt nhp-opts-sorter-alt">';

				//if (empty($sortlists['disabled'])) $sortlists['disabled'] = array();
				//if (empty($sortlists['enabled'])) $sortlists['enabled'] = array();

				// go through field[options] and make sure they exist as a group
				foreach ($all_blocks as $default_block => $val) {
					if (empty($sortlists[$default_block]))
						$sortlists[$default_block] = array();
				}

				foreach ( $sortlists as $group => $sortlist ) {
					$filled = "";

					if ( isset( $this->field['limits'][$group] ) && count( $sortlist ) >= $this->field['limits'][$group] ) {
						$filled = " filled";
					}

					echo '<div id="'.$this->field['id'].'_'.$group.'" class="sortlist-alt sortlist_'.$this->field['id'].$filled.'" data-id="'.$this->field['id'].'" data-group-id="' . $group . '">';
					echo '<h3>'.$group.'</h3>';

					if (!isset($sortlist['placebo'])){
						array_unshift($sortlist, array( "placebo" => "placebo" ));
					}

					foreach ( $sortlist as $key => $list ) {

						//echo '<input class="sorter-placebo" type="hidden" name="' . $this->args['opt_name'].'['.$this->field['id'].'][' . $group . '][placebo]" value="placebo">';

						$has_content = isset($list['subfields']) && !empty($list['subfields']);
						$has_content_class = $has_content ? ' sortee-has-content' : '';

						if ($key != "placebo") {

							echo '<div id="'.$key.'" class="sortee-alt'.$has_content_class.'">';
							echo '<input class="position-alt '.$this->field['class'].'" type="hidden" name="' . $this->args['opt_name'].'['.$this->field['id'].'][' . $group . '][' . $key . ']" value="'.$list['label'].'">';
							echo '<div class="sortee-header">'.$list['label'].'</div>';

							if ( $has_content ) {

								echo '<div class="sortee-content">';
								echo '<table style="margin-top: 0;" class="nhp-opts-sortee-toggle-group nhp-opts-group form-table no-border">';

								foreach ( $list['subfields'] as $field ) {
									//we will enqueue all CSS/JS for sub fields if it wasn't enqueued
									$this->enqueue_dependencies($field['type']);

									echo '<tr><td>';

									if (!empty($field['title']))
										echo '<h4>' . $field['title'] . '</h4>';

									if (!empty($field['sub_desc']))
										echo '<span class="description">' . $field['sub_desc'] . '</span>';

									// Had to pull option values this way
									$def_value = isset($field['std']) ? $field['std'] : '';
									$mts_options = get_option(MTS_THEME_NAME);
									$value = isset($mts_options[$field['id']]) ? $mts_options[$field['id']] : $def_value;

									$field_type = $field['type'];

									$field_class = 'NHP_Options_' . $field_type;

									if (!class_exists($field_class)) {

										$class_file = NHP_OPTIONS_DIR . 'fields/' . $field_type . '/field_' . $field_type . '.php';

										if ($class_file) {
											/** @noinspection PhpIncludeInspection */
											require_once($class_file);
										}
									}

									if (class_exists($field_class) && method_exists($field_class, 'render')) {
										$render = new $field_class($field, $value, $this);
										$render->render();
									}

									echo '</td></tr>';
								}
								echo '</table>';
								echo '<a href="javascript:void(0);" class="button button-secondary nhp-opts-sortee-toggle-close">' . __('OK', 'newspaper' ). '</a>';

								echo '</div>';
							}
							echo '</div>';
						}
					}

					echo '</div>';
				}
				echo '</fieldset>';
				// debug
				// $options = get_option($this->args['opt_name']);
				// echo '<pre>'.print_r($options[$this->field['id']], 1).'</pre>';
			}
		}
	}

	function enqueue() {

		wp_enqueue_style('nhp-opts-jquery-ui-css');
		wp_enqueue_style('nhp-opts-field-layout2-css', NHP_OPTIONS_URL.'fields/layout2/field_layout2.css');

		wp_enqueue_script('jquery-ui-core');
		wp_enqueue_script('jquery-ui-sortable');

		wp_enqueue_script(
			'nhp-opts-field-layout2-js',
			NHP_OPTIONS_URL.'fields/layout2/field_layout2.js',
			array('jquery', 'jquery-ui-core', 'jquery-ui-sortable'),
			MTS_THEME_VERSION,
			true
		);
	}

	function enqueue_dependencies($field_type) {
		$field_class = 'NHP_Options_' . $field_type;

		if (!class_exists($field_class)) {

			$class_file = NHP_OPTIONS_DIR . 'fields/' . $field_type . '/field_' . $field_type . '.php';

			if ($class_file) {
				/** @noinspection PhpIncludeInspection */
				require_once($class_file);
			}
		}

		if (class_exists($field_class) && method_exists($field_class, 'enqueue')) {
			$enqueue = new $field_class('', '', $this);
			$enqueue->enqueue();
		}
	} // enqueue dependencies function
}



Un GRAND MERCI d'avance
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
Modifié le 5 juin 2020 à 08:36
Je t'ai demandé le code complet de tes fichiers .... pas juste quelques lignes....
De plus, comme tu peux le constater, tu n'as pas besoin de nous marquer les numéros de ligne....
Avec les balises de code, ça se fait tout seul.

Concernant ton souci,
es-tu sûr que $field est bien un array ?

peux tu modifier ton code pour y ajouter une vérification dans le if
if ( is_array($this->field) && empty($this->field['class']))
0
Abdou2011_75 Messages postés 3 Date d'inscription mercredi 3 juin 2020 Statut Membre Dernière intervention 5 juin 2020
5 juin 2020 à 08:48
ça a marché
Merci infiniment
0