Внутри функции fun1 недоступен get_the_ID() и $post->ID почему, как исправить?
Т.е. вызываю шорткод, он вызывает свою функцию, она вызывает третью и вот в ней почему то не получается получить текущий номер поста.
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, 'shortcodeclass1'));
}
function getPageCode($url) {
return $pageCode;
}
function parseXML($url) {
return $json;
}
function getTypeclass1($string) {
foreach ($this->types as $id => $name) {
$needType = mb_strtolower($name, 'utf8');
$searchString = mb_strtolower($string, 'utf8');
if (stristr($searchString, $needType)) {
return $id;
}
}
return false;
}
function getMarksclass1($string) {
foreach ($this->marks as $id => $name) {
$needMark = mb_strtolower($name, 'utf8');
$searchString = mb_strtolower($string, 'utf8');
if (stristr($searchString, $needMark)) {
return $id;
}
}
return false;
}
function getclass1($type) {
$resultData = array();
if ($type === 'type1' ){
$currentClass1Json = $this->parseXML('http://...');
}
$currentClass1 = json_decode($currentClass1Json, true);
$currentClass1Need = $currentClass1['channel']['item'];
foreach ($currentClass1['channel']['item'] as $Class1Data) {
$key = $this->getMarksclass1($Class1Data['title']);
$resultData[$key] = $Class1Data['description'];
}
return $resultData;
}
function getclass1All() {
$resultData = array();
foreach ($this->types as $id => $name) {
$resultData[$id] = $this->getclass1($id);
}
return $resultData;
}
function updateData() {
$newClass1 = json_encode($this->getclass1All());
$newDate = strtotime(date('Y-m-d'));
update_option('wp-class1-dateUpdate', $newDate);
update_option('wp-class1-data', $newClass1);
}
function shortcodeclass1($atts) {
extract(shortcode_atts(array(
'type' => 'typy1',
'mark' => 'mark1'
), $atts));
$currentType = $this->getTypeclass1($type);
$currentMark = $this->getMarksclass1($mark);
$data = json_decode($this->data, true);
$Class1 = $data[$currentType][$currentMark];
return $Class1;
}
}
$class1 = new class1;