Есть глобальная переменная $postю Но почему то к ней нет доступа из функции 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;