eprivalov
@eprivalov
Учусь

Notice: Undefined property: stdClass. Как исправить?

Добрый день, пытаюсь встроить плагин Wordpress в тему Wordpress. Но получаюсь Notice:

Notice: Undefined property: stdClass::$publish in /nas/wp/www/cluster-1664/brandivodemo/wp-content/themes/enfold-child/includes/leads/classes/class.dashboard.php on line 187

И такое ощущение, что PHP не работает после Notice... Как его исправить? Помогите пожалуйста.

Строка 187: $all_time_leads = $count_posts->publish;

public static function display_lead_report_widget()
	{
		global $wpdb;
		$count_posts = wp_count_posts('wp-lead');
		$url = site_url();

		$c_month	= date( 'n' ) == 1 ? 12 : date( 'n' ); // GETS INT from EDD
		$previous_month	= date( 'n' ) == 1 ? 12 : date( 'n' ) - 1; // GETS INT from EDD
		$previous_year	= $previous_month == 12 ? date( 'Y' ) - 1 : date( 'Y' ); // Gets INT year val

		$start_current = date("Y-m-01"); // start of current month
		$end_current = date("Y-m-t",strtotime('last day of this month')); // end of current month

		//getting the previous month

		$previous_month_start = date("Y-m-01", strtotime("previous month"));
		$previous_month_end = date("Y-m-d", strtotime("-1 month"));

		$this_month = self::count_leads_by_time( $start_current, $end_current);
		$last_month = self::count_leads_by_time( $previous_month_start, $previous_month_end);

		$all_time_leads = $count_posts->publish;
		$all_lead_text = ($all_time_leads == 1) ? "Lead" : "Leads";
		$leads_today = Leads_Dashboard::get_lead_count_from_today('wp-lead');
		$leads_today_text = ($leads_today == 1) ? "Lead" : "Leads";
		$month_comparasion = $this_month - $last_month;

		if ($month_comparasion < 0)
		{
			$month_class = 'negative-leads';
			$sign = "";
			$sign_text = "decrease";
		} elseif($month_comparasion === 0) {
			$month_class= 'no-change';
			$sign = "";
			$sign_text = "No Change ";
		} else {
			$month_class = 'positive-leads';
			$sign = "+";
			$sign_text = "increase";
		}
		echo '<div id="lead-before-dashboard">';
		do_action('wp_lead_before_dashboard');
		echo "</div>";

		$clean_dates = date("m", strtotime("first day of previous month") );
		$clean_date_two = date("m");
		?>

		<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="/wp-content/plugins/lead-dashboard-widgets/js/flot/excanvas.min.js"></script><![endif]-->

		<div class="wp_leads_dashboard_widget">

		<script type="text/javascript">
		/* <![CDATA[ */
		window.data1 = [ <?php echo self::get_lead_graph_data( $clean_date_two, 'this-month'); ?> ];
		window.data2 = [ <?php echo self::get_lead_graph_data( $clean_dates, 'last-month'); ?> ];
		/* ]]> */
		</script>
			<div id="flot-placeholder" style='width: 100%; height: 250px; margin: 10px auto 0px; padding: 0px; position: relative; margin-bottom:10px;'></div>


			<div id="wp-leads-stat-boxes">
			<div class='wp-leads-today'>
				<a class="data-block widget-block" alt='Click to View Todays Leads' href="<?php echo $url . "/wp-admin/edit.php?post_type=wp-lead&current_date";?>">
					<section>
						<?php echo $leads_today; ?>
						<br><?php echo $leads_today_text;?>
						<br><strong><?php _e('Today' , 'leads'); ?></strong>
					</section>
				</a>
			</div>
			<div class='wp-leads-this-month'>
				<a class="data-block widget-block" alt='Click to View This Months Leads' href="<?php echo $url . "/wp-admin/edit.php?post_type=wp-lead&current_month";?>">
					<section>
						<?php echo $this_month; ?>
						<br><?php echo $all_lead_text;?>
						<br><strong><?php _e('This Month' , 'leads'); ?></strong>
					</section>
				</a>
			</div>
			<div class='wp-leads-all-time'>
				<a class="data-block widget-block" title='Click to View All Leads' href="<?php echo $url . "/wp-admin/edit.php?post_type=wp-lead";?>">
					<section>
						<?php echo $all_time_leads;?>
						<br><?php _e('Leads' , 'leads'); ?>
						<strong><?php _e('All Time' , 'leads'); ?></strong>
					</section>
				</a>
			</div>
			<div class="wp-leads-change-box" style="text-align: center;">
				<small class='<?php echo $month_class; ?>'><?php echo "<span>" . $sign . $month_comparasion . "</span> " . $sign_text;?> <?php _e('Since Last Month' , 'leads'); ?></small>
			</div>
		</div>
			<!-- <div class='wp-leads-last-month'>
			last month: <?php echo $last_month; ?>

			<?php echo $this_month - $last_month;	?>
			</div>	-->
			<div id='leads-list'>
			<?php	$r = new WP_Query( apply_filters( 'widget_posts_args', array(
				'posts_per_page' => 20,
				'post_type' => 'wp-lead',
				'post_status' => 'publish') ) );

			if ($r->have_posts()) : ?>
			<h4 class='marketing-widget-header'>Latest Leads<span class="toggle-lead-list">-</span></h4>
			<ul id='lead-ul'>
			<?php while ( $r->have_posts() ) : $r->the_post(); ?>
				<li><?php $id = get_the_ID();
				$first_name = get_post_meta( $id , 'wpleads_first_name',true );
				$last_name = get_post_meta( $id , 'wpleads_last_name', true );
				$name = $first_name . " " . $last_name;
				if ($name === " ") {
					$name = get_the_title( $id );
				}
				?>

					<?php edit_post_link($name);?> on <?php the_time('F jS, Y'); ?> (<?php the_title();?>)
				</li>
			<?php endwhile; ?>
			</ul>
			<?php endif; ?>
			</div>
		</div>
		<?php
	}
  • Вопрос задан
  • 9833 просмотра
Пригласить эксперта
Ответы на вопрос 2
FanatPHP
@FanatPHP
Чебуратор тега РНР
Undefined property у тебя - это не stdClass, а $publish
проверяй, что вернула wp_count_posts() (var_dump) и почему.
Ответ написан
@Centrino
Предлагаю вам только дебажить, то что вы пытаетесь встроить. Что у вас в хранится в $count_posts? Есть ли там вообще что либо, что бы вызвать у него publish?
перехватываете ли вы где-либо ошибки?
Ответ написан
Ваш ответ на вопрос

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

Похожие вопросы