selftrips
@selftrips

Как добавть еще одну переменную в класс?

Как добавить еще одну переменную в класс, скажем$this-> param Чтобы она была доступна в fun1
Дописывание ниже
protected $data;
строчки
protected $param;
эффекта не дает переменная остается недоступной вfun1
`<?php
/*
Plugin Name: Plugin1
*/

class class1 {
  protected $types;		
  protected $marks;	
  protected $dateUpdate;	
  protected $data;		

  function __construct() {
    $this->types = array(
      'type1'		=>	'type1',
      );
    $this->marks = array(
      'mark1' 		=> 'mark1', 
      );

    $this->dateUpdate 	= get_option('wp-class1-dateUpdate');
    $this->data 		= get_option('wp-class1-data');

    if (($this->dateUpdate == 0 && $this->data == 0) || (strtotime(date('Y-m-d')) > $this->dateUpdate))  {
      $this->updateData();
    }

    add_shortcode('class1', array($this, 'shortcode1'));
  }

  function getTypes($string) {
    foreach ($this->types as $id => $name) {
        return $id;
      }
    }
    return false;
  }


  function getMarks($string) {
    foreach ($this->marks as $id => $name) {
        return $id;
      }
    }
    return false;
  }

  function fun1($type) {
global $post;
    $resultData 			= array();
$my_post_id =	get_the_ID();///////////!!!!!!!!!//////////// пустое и get_the_ID() и $post->ID;

    return $resultData;
  }


  function getAll() {
    $resultData = array();	
    foreach ($this->types as $id => $name) {
      $resultData[$id] = $this->fun1($id);
    }
    return $resultData;
  }

  function updateData() {
  }

  /**
   * Создание шорткода

  function shortcode1($atts) {
global $post;
    extract(shortcode_atts(array(
      'type' => 'тип',
      'mark' => 'метка'
      ), $atts));
$my_post_id =	$post->ID;

    $currentType = $this->getTypes($type);
    $currentMark = $this->getMarks($mark);
    $data = json_decode($this->data, true);
    $scope = $data[$currentType][$currentMark];
update_post_meta( $my_post_id, 'horo_dannie', $horoscope); 		
//}
    return $scope;
  }

  
}

$class1 = new class1;
?>
  • Вопрос задан
  • 70 просмотров
Пригласить эксперта
Ответы на вопрос 2
Driver86
@Driver86
Немодератор toster.ru
Если "остаётся недоступной", то решение:
public $param;
Ответ написан
@morricone85
function getTypes($string) {
    foreach ($this->types as $id => $name) {
        return $id;
      }
    }
    return false;
  }


  function getMarks($string) {
    foreach ($this->marks as $id => $name) {
        return $id;
      }
    }
    return false;
  }


Там, по-моему, лишние фигурные скобки
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы