http://plugins.trac.wordpress.org/browser/seo-content-helper/tags/1.1/get-data.php
不要重复自己
我知道“不要重复自己”。还是有些地方乱七八糟。下面的代码包含三个代码块。
它们在某些方面相似,但在其他方面不同。它不会在所有方面都遵循相同的模式。
它做什么
它创建了一个我在前端循环的数组。
问题
有没有更好的方法来做这种事情?不那么凌乱,结构更好?
$message_start = '<strong>h2 tags</strong> - ';
$message_end = '<span class="counter">' . $this->count_h2 . '</span>';
if( $this->count_h2 == 0 ) {
$message = 'No tags found. Add some!';
$array['content_editor']['count_h2']['status'] = 2;
} elseif( $this->count_h2 == 1 ) {
$message = 'Some found. Too few!';
$array['content_editor']['count_h2']['status'] = 1;
} else {
$message = 'Many found. Great!';
$array['content_editor']['count_h2']['status'] = 0;
}
$array['content_editor']['count_h2']['message'] = $message_start . $message . $message_end;
$array['content_editor']['count_h2']['count'] = $this->count_h2;
$message_start = '<strong>h3-h6 tags</strong> - ';
$h2_h6 = $this->count_h3 + $this->count_h4 + $this->count_h5 + $this->count_h6;
$counter = ( $h2_h6 == 0 ) ? '' : $h2_h6;
$message_end = '<span class="counter">' . $counter . '</span>';
if( $h2_h6 == 0 ) {
$message = 'No found. Add some!';
$array['content_editor']['count_h3_h6']['status'] = 1;
} else {
$message = 'Found, great!';
$array['content_editor']['count_h3_h6']['status'] = 0;
}
$array['content_editor']['count_h3_h6']['message'] = $message_start . $message . $message_end;
$array['content_editor']['count_h3_h6']['count'] = $this->h2_h6;
$message_start = '<strong>Title keywords</strong> - ';
$counter = ( $this->found_keywords1_post_title == 0 ) ? '' : $this->found_keywords1_post_title;
$message_end = '<span class="counter">' . $counter . '</span>';
if( count( $this->keywords1 ) == 0 ) {
$message = 'No primary added.';
$array['content_editor']['missing_keywords1_post_title']['status'] = 2;
} elseif( $this->found_keywords1_post_title == 0 ) {
$message = 'No primary found.';
$array['content_editor']['missing_keywords1_post_title']['status'] = 2;
} else {
$s = ( $this->found_keywords1_post_title != 1 ) ? 's' : '';
$message = 'Primary found.';
$array['content_editor']['missing_keywords1_post_title']['status'] = 0;
}
$array['content_editor']['missing_keywords1_post_title']['message'] = $message_start . $message . $message_end;
$array['content_editor']['missing_keywords1_post_title']['count'] = $this->found_keywords1_post_title;