Beispiel #1
0
 private function getMenuAssignmentTemplate()
 {
     if (count($this->menu_assignments) < 1) {
         $menu_locations = get_nav_menu_locations();
         if (count($menu_locations) == 0) {
             return;
         }
         foreach ($menu_locations as $menu) {
             $menu = wp_get_nav_menu_object($menu);
             $this->menu_assignments[] = $menu;
             //$this->menu_assignments[$menu->slug] = $menu;
         }
     }
     if (is_null($this->display_checkbox_menus)) {
         $menus = $this->menu_assignments;
         $html = '';
         $html .= '<div class="adoptions-display-menu">';
         foreach ($menus as $menu) {
             if (!isset($menu) || $menu != NULL || $menu != "") {
                 $items = $this->menu_assignments[$menu->slug] = wp_get_nav_menu_items($menu);
                 if (count($items) > 0) {
                     $menu_checkbox = new YA_Menu_Checkbox($menu->slug);
                     $html .= '<strong>' . $menu->name . '</strong><span> (Menu)</span>';
                     $html .= '<ul>';
                     $html .= $menu_checkbox->init($items);
                     $html .= '</ul>';
                 }
             }
         }
         $html .= '</div>';
         $this->display_checkbox_menus = $html;
     }
     return $this->display_checkbox_menus;
 }
Beispiel #2
0
/**
 * Check widget display
 * */
function check_wdisplay($widget_display)
{
    $widget_display = json_decode(json_encode($widget_display), true);
    $YA_Menu_Checkbox = new YA_Menu_Checkbox();
    if (isset($widget_display['display_select']) && $widget_display['display_select'] == 'all') {
        return true;
    } else {
        if (in_array('sitepress-multilingual-cms/sitepress.php', apply_filters('active_plugins', get_option('active_plugins')))) {
            if (isset($widget_display['display_language']) && strcmp($widget_display['display_language'], ICL_LANGUAGE_CODE) != 0) {
                return false;
            }
        }
        if (isset($widget_display['display_select']) && $widget_display['display_select'] == 'if_selected') {
            if (isset($widget_display['checkbox'])) {
                if (isset($widget_display['checkbox']['users'])) {
                    global $user_ID;
                    foreach ($widget_display['checkbox']['users'] as $key => $value) {
                        if ($key == 'login' && $user_ID || $key == 'logout' && !$user_ID) {
                            if (isset($widget_display['checkbox']['general'])) {
                                foreach ($widget_display['checkbox']['general'] as $key => $value) {
                                    $is = 'is_' . $key;
                                    if ($is() === true) {
                                        return true;
                                    }
                                }
                            }
                            if (isset($widget_display['taxonomy-slugs'])) {
                                $taxonomy_slugs = preg_split('/[\\s,]/', $widget_display['taxonomy-slugs']);
                                foreach ($taxonomy_slugs as $slug) {
                                    is_post_type_archive('product_cat');
                                    if (!empty($slug) && is_tax($slug) === true) {
                                        return true;
                                    }
                                }
                            }
                            if (isset($widget_display['post-type'])) {
                                $post_type = preg_split('/[\\s,]/', $widget_display['post-type']);
                                foreach ($post_type as $type) {
                                    if (is_archive()) {
                                        if (!empty($type) && is_post_type_archive($type) === true) {
                                            return true;
                                        }
                                    }
                                    if ($type != PRODUCT_TYPE) {
                                        if (!empty($type) && $type == PRODUCT_DETAIL_TYPE && is_single() && get_post_type() != 'post') {
                                            return true;
                                        } else {
                                            if (!empty($type) && is_singular($type) === true) {
                                                return true;
                                            }
                                        }
                                    }
                                }
                            }
                            if (isset($widget_display['catid'])) {
                                $catid = preg_split('/[\\s,]/', $widget_display['catid']);
                                foreach ($catid as $id) {
                                    if (!empty($id) && is_category($id) === true) {
                                        return true;
                                    }
                                }
                            }
                            if (isset($widget_display['postid'])) {
                                $postid = preg_split('/[\\s,]/', $widget_display['postid']);
                                foreach ($postid as $id) {
                                    if (!empty($id) && (is_page($id) === true || is_single($id) === true)) {
                                        return true;
                                    }
                                }
                            }
                            if (isset($widget_display['checkbox']['menus'])) {
                                foreach ($widget_display['checkbox']['menus'] as $menu_id => $item_ids) {
                                    if ($YA_Menu_Checkbox->is_menu_item_active($menu_id, $item_ids)) {
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
                return false;
            } else {
                return false;
            }
        } elseif (isset($widget_display['display_select']) && $widget_display['display_select'] == 'if_no_selected') {
            if (isset($widget_display['checkbox'])) {
                if (isset($widget_display['checkbox']['users'])) {
                    global $user_ID;
                    foreach ($widget_display['checkbox']['users'] as $key => $value) {
                        if ($key == 'login' && $user_ID || $key == 'logout' && !$user_ID) {
                            return false;
                        }
                    }
                }
                if (isset($widget_display['checkbox']['general'])) {
                    foreach ($widget_display['checkbox']['general'] as $key => $value) {
                        $is = 'is_' . $key;
                        if ($is() === true) {
                            return false;
                        }
                    }
                }
                if (isset($widget_display['taxonomy-slugs'])) {
                    $taxonomy_slugs = preg_split('/[\\s,]/', $widget_display['taxonomy-slugs']);
                    foreach ($taxonomy_slugs as $slug) {
                        if (!empty($slug) && is_tax($slug) === true) {
                            return false;
                        }
                    }
                }
                if (isset($widget_display['post-type'])) {
                    $post_type = preg_split('/[\\s,]/', $widget_display['post-type']);
                    foreach ($post_type as $type) {
                        if (is_archive()) {
                            if (!empty($type) && is_post_type_archive($type) === true) {
                                return true;
                            }
                        }
                        if ($type != PRODUCT_TYPE) {
                            if (!empty($type) && $type == PRODUCT_DETAIL_TYPE && is_single() && get_post_type() != 'post') {
                                return true;
                            } else {
                                if (!empty($type) && is_singular($type) === true) {
                                    return true;
                                }
                            }
                        }
                    }
                }
                if (isset($widget_display['catid'])) {
                    $catid = preg_split('/[\\s,]/', $widget_display['catid']);
                    foreach ($catid as $id) {
                        if (!empty($id) && is_category($id) === true) {
                            return false;
                        }
                    }
                }
                if (isset($widget_display['postid'])) {
                    $postid = preg_split('/[\\s,]/', $widget_display['postid']);
                    foreach ($postid as $id) {
                        if (!empty($id) && (is_page($id) === true || is_single($id) === true)) {
                            return false;
                        }
                    }
                }
                if (isset($widget_display['checkbox']['menus'])) {
                    foreach ($widget_display['checkbox']['menus'] as $menu_id => $item_ids) {
                        if ($YA_Menu_Checkbox->is_menu_item_active($menu_id, $item_ids)) {
                            return false;
                        }
                    }
                }
            } else {
                return false;
            }
        }
    }
    return true;
}