@anriko

Как добавить метод в класс плагина в function.php?

хочу доработать плагин добавив классу метод в function.php,как это сделать?
так не получилось
вот так сделал 
require_once $_SERVER['DOCUMENT_ROOT']."/wp-content/wp-recall/add-on/top-user-by-rating/class/Tub_Rating.php";


add_shortcode('top_user_rating2', 'rcl_top_user_by_rating2');
function rcl_top_user_by_rating2($atts) {
  //Параметры шорткода
  $atts = shortcode_atts(array(
	  'templates' => 'block',
	  'sorting' => '1',
	  'limit' => '50',
	  'day' => '30',
	  'exclude' => '',
	  'type' => '',
	  'period' => '',
	  'paged' => '',
	  'role' => '',
	  'cache_time' => '86400'
  ), $atts);
тут объявил экземпляр класса 
$tubrating =new Tub_Rating($atts);
тут добавил метод
 $tubrating->getTopUserHtml2 = function() {

	$result = '<div class="tubr">';

	$result .= $this->getSort();

	$result .= '<div class="tubr-content ' . $this->templates . '">';

	$total_users = $this->getTopUser();

	if ($total_users) {
	  $position = $this->limit * ($this->page - 1);

	  $val		 = 0;
	  $firstCheck	 = 0;

	  foreach ($total_users as $max) {

		if ($max['total_rating'] > $val)
		  $val = $max['total_rating'];
	  }

	  foreach ($total_users as $top_user) {

		$position++;
		$firstCheck++;
		//Подключаем файл с шаблоном вывода
		$result .= rcl_get_include_template('user-tubr-' . $this->templates . '.php', __FILE__, array(
			'top_user'	 => $top_user,
			'position'	 => $position,
			'val'		 => $val,
			'firstCheck' => $firstCheck
		));
	  }
	} else {
	  $result .= 'Нет данных';
	}
	$result	 .= $this->getNav();
	$result	 .= '</div>';
	$result	 .= '</div>';

	return $result;
  };
  return $tubrating->getTopUserHtml2();

}

ошибка Fatal error: Uncaught Error: Call to undefined method stdClass::getTopUserHtml2() in
  • Вопрос задан
  • 45 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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