Я пишу плагин фильтраций тегов для wordpress но почему то у меня появляется ошибка
Fatal error: Cannot redeclare exc_post() (previously declared in C:\xampp\htdocs\wor\wp-content\plugins\GOG11\GOG11.php:64) in C:\xampp\htdocs\wor\wp-content\plugins\GOG11\GOG11.php on line 141
На строке
if ($_SESSION['filter2'] == ''){
И самое любопытное то что на точно такой же строке только
if ($_SESSION['filter1'] == ''){
Ошибки нету
И она возникает только когда ['filter2'] == '' при всех остальных значениях все работает нормально
Если вместо пропуска я указываю 1 то ошибка появляется уже на filter4 перескакивая filter3
Вот весь код плагина
session_start();
if ($_POST['filter1']){
$_SESSION['filter1'] = $_POST['filter1'];
}
if ($_POST['filter2']){
$_SESSION['filter2'] = $_POST['filter2'];
}
add_shortcode ('wp-r_dop_filter','A2');
function A2(){
$R1='
<form method="POST" >
<p>Option filter</p>
<p>Filter 1</p>
level 1: <input type="radio" name="filter1" value="1"' . ($_SESSION["filter1"] == 1 ? 'checked' : '') . '/>
level 2: <input type="radio" name="filter1" value="2"' . ($_SESSION["filter1"] == 2 ? 'checked' : '') . '/>
<p>Filter 2</p>
level 1: <input type="radio" name="filter2" value="1"' . ($_SESSION["filter2"] == 1 ? 'checked' : '') . '/>
level 2: <input type="radio" name="filter2" value="2"' . ($_SESSION["filter2"] == 2 ? 'checked' : '') . '/>
<p><input type="submit" value="User"></p>
</form>
';
return $R1;
}
if ($_SESSION['filter1'] == ''){
add_filter('pre_get_posts','exc_post');
function exc_post($filter1_query_lv0 ) {
if ($filter1_query_lv0->is_category || ($filter1_query_lv0->is_home || ($filter1_query_lv0->is_feed) || ($filter1_query_lv0->is_tag)))
{
$filter1_way_lv0_1 = plugin_dir_url( __FILE__ );
$filter1_way_lv0_2 = file_get_contents( $filter1_way_lv0_1 . 'filter1/level_1.txt');
$filter1_way_lv0_3 = explode (",", $filter1_way_lv0_2);
$filter1_query_lv0->set('tax_query', array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $filter1_way_lv0_3,
'operator' => 'NOT IN'
)
));
}
return $filter1_query_lv0;
}
}
else if ($_SESSION['filter1'] == 1){
add_filter('pre_get_posts','exc_post');
function exc_post($filter1_query_lv1) {
if ($filter1_query_lv1->is_category || ($filter1_query_lv1->is_home || ($filter1_query_lv1->is_feed) || ($filter1_query_lv1->is_tag)))
{
$filter1_way_lv1_1 = plugin_dir_url( __FILE__ );
$filter1_way_lv1_2 = file_get_contents( $filter1_way_lv1_1 . 'filter1/level_1.txt');
$filter1_way_lv1_3 = explode (",", $filter1_way_lv1_2);
$filter1_query_lv1->set('tax_query', array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $filter1_way_lv1_3,
'operator' => 'NOT IN'
)
));
}
return $filter1_query_lv1;
}
}
else if ($_SESSION['filter1'] == 2){
add_filter('pre_get_posts','exc_post');
function exc_post($filter1_query_lv2) {
if ($filter1_query_lv2->is_category || ($filter1_query_lv2->is_home || ($filter1_query_lv2->is_feed) || ($filter1_query_lv2->is_tag)))
{
$filter1_way_lv2_1 = plugin_dir_url( __FILE__ );
$filter1_way_lv2_2 = file_get_contents( $filter1_way_lv2_1 . 'filter1/level_2.txt');
$filter1_way_lv2_3 = explode (",", $filter1_way_lv2_2);
$filter1_query_lv2->set('tax_query', array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $filter1_way_lv2_3,
'operator' => 'NOT IN'
)
));
}
return $filter1_query_lv2;
}
}
if ($_SESSION['filter2'] == 1){
add_filter('pre_get_posts','exc_post');
function exc_post($filter2_query_lv0) {
if ($filter2_query_lv0->is_category || ($filter2_query_lv0->is_home || ($filter2_query_lv0->is_feed) || ($filter2_query_lv0->is_tag)))
{
$filter2_way_lv0_1 = plugin_dir_url( __FILE__ );
$filter2_way_lv0_2 = file_get_contents( $filter2_way_lv0_1 . 'filter2/level_1.txt');
$filter2_way_lv0_3 = explode (",", $filter2_way_lv0_2);
$filter2_query_lv0->set('tax_query', array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $filter2_way_lv0_3,
'operator' => 'NOT IN'
)
));
}
return $filter2_query_lv0;
}
}
else if ($_SESSION['filter2'] == 2){
add_filter('pre_get_posts','exc_post');
function exc_post($filter2_query_lv1) {
if ($filter2_query_lv1->is_category || ($filter2_query_lv1->is_home || ($filter2_query_lv1->is_feed) || ($filter2_query_lv1->is_tag)))
{
$filter2_way_lv1_1 = plugin_dir_url( __FILE__ );
$filter2_way_lv1_2 = file_get_contents( $filter2_way_lv1_1 . 'filter2/level_1.txt');
$filter2_way_lv1_3 = explode (",", $filter2_way_lv1_2);
$filter2_query_lv1->set('tax_query', array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $filter2_way_lv1_3,
'operator' => 'NOT IN'
)
));
}
return $filter2_query_lv1;
}
}
else if ($_SESSION['filter2'] == ''){
add_filter('pre_get_posts','exc_post');
function exc_post($filter2_query_lv2) {
if ($filter2_query_lv2->is_category || ($filter2_query_lv2->is_home || ($filter2_query_lv2->is_feed) || ($filter2_query_lv2->is_tag)))
{
$filter2_way_lv2_1 = plugin_dir_url( __FILE__ );
$filter2_way_lv2_2 = file_get_contents( $filter2_way_lv2_1 . 'filter2/level_2.txt');
$filter2_way_lv2_3 = explode (",", $filter2_way_lv2_2);
$filter2_query_lv2->set('tax_query', array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $filter2_way_lv2_3,
'operator' => 'NOT IN'
)
));
}
return $filter2_query_lv2;
}
}
Код был упрощен