function mb_convert_wp_galleries_array_to_consolidated_wp_gallery_array($wp_galleries_array) { $consolidated_wp_gallery_array = array(); foreach ($wp_galleries_array as $key => $this_wp_gallery_string) { // first create id array $id_explode_array = explode('ids="', $this_wp_gallery_string); $id_explode_array2 = explode('"', $id_explode_array[1]); $id_string = $id_explode_array2[0]; $id_array = explode(',', $id_string); // get category $cat_explode_array = explode('category="', $this_wp_gallery_string); if (isset($cat_explode_array[1])) { $cat_explode_array2 = explode('"', $cat_explode_array[1]); $category_name = $cat_explode_array2[0]; $category_slug = mb_create_slug($category_name); } else { $category_name = __("Category ", "loc_canon") . ($key + 1); $category_slug = mb_create_slug($category_name); } //handle each id foreach ($id_array as $key => $id) { // first check if duplicate $duplicate = false; foreach ($consolidated_wp_gallery_array as $key => $value) { if ($value['id'] === $id) { $duplicate = true; // if duplicate check if category exists and add if not add $duplicate_cat = false; foreach ($value['categories'] as $this_cat_slug => $this_cat_name) { if ($this_cat_name === $category_name) { $duplicate_cat = true; } } if ($duplicate_cat === false) { $cat_add_array = array($category_slug => $category_name); $consolidated_wp_gallery_array[$key]['categories'][$category_slug] = $category_name; } } } // add if not duplicate if ($duplicate === false) { $add_array = array('id' => $id, 'categories' => array($category_slug => $category_name)); array_push($consolidated_wp_gallery_array, $add_array); } } // foreach id_array } // foreach wp_gallery_array return $consolidated_wp_gallery_array; }
function canon_setup_theme() { /************************************** ADD ACTIONS ***************************************/ // front end includes add_action('wp_enqueue_scripts', 'canon_load_to_front'); // back end includes add_action('admin_enqueue_scripts', 'canon_load_to_back'); // add post views counter to all posts add_action('wp_head', 'mb_update_post_views_single_check'); // media upload customize add_action('admin_init', 'check_upload_page'); // hide theme settings from non-admins add_action('admin_menu', 'hide_theme_settings_from_non_admins'); // unregister timetable widgets add_action('widgets_init', 'unregister_timetable_widgets'); // bundled plugins automatic update checker add_action('init', 'init_canon_auc'); /************************************** ADD FILTERS ***************************************/ // disable woocommerce default styles if (class_exists('Woocommerce')) { add_filter('woocommerce_enqueue_styles', '__return_false'); } // make shortcodes execute in widget texts add_filter('widget_text', 'do_shortcode'); // adjust the WordPress menus add_filter('wp_nav_menu_items', 'canon_filter_wp_menus', 10, 2); // filter wp_title add_filter('wp_title', 'canon_filter_wp_title', 10, 2); // filter search query add_filter('pre_get_posts', 'canon_filter_search_query'); /************************************** ADD_THEME_SUPPORT CALLS ***************************************/ // Add default posts and comments RSS feed links to <head>. add_theme_support('automatic-feed-links'); // This theme uses Featured Images add_theme_support('post-thumbnails'); //post formats add_theme_support('post-formats', array('quote', 'gallery', 'video', 'audio')); // woocommerce add_theme_support('woocommerce'); /************************************** IMAGE SIZES ***************************************/ add_image_size('gallery_isotope_x2', 900, 600, true); add_image_size('featured_posts_thumb_x2', 1048, 582, true); add_image_size('timeline_gallery_thumb_x2', 212, 140, true); add_image_size('posts_graph_thumb_x2', 200, 200, true); add_image_size('menu_item_thumb_x2', 1086, 722, true); //set general content width if (!isset($content_width)) { $content_width = 1120; } /************************************** REGISTER MENUS ***************************************/ //register primary menu register_nav_menus(array('primary_menu' => 'Primary Menu')); //register secondary menu register_nav_menus(array('secondary_menu' => 'Secondary Menu')); /************************************** LOCALIZATION INIT ***************************************/ $lang_dir = get_template_directory() . '/lang'; load_theme_textdomain('loc_canon', $lang_dir); /************************************** REGISTER THEME WIDGET AREAS ***************************************/ // SIDEBARS if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_archive_sidebar_widget_area", 'name' => 'Post/Archive Sidebar Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_page_sidebar_widget_area", 'name' => 'Page Sidebar Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_404_sidebar_widget_area", 'name' => '404 Sidebar Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_search_sidebar_widget_area", 'name' => 'Search Sidebar Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_contact_sidebar_widget_area", 'name' => 'Contact Sidebar Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } // FOOTER WIDGET AREAS if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_footer_widget_area_1", 'name' => 'Footer: Widget Area 1', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_footer_widget_area_2", 'name' => 'Footer: Widget Area 2', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_footer_widget_area_3", 'name' => 'Footer: Widget Area 3', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_footer_widget_area_4", 'name' => 'Footer: Widget Area 4', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar')) { register_sidebar(array('id' => "canon_footer_widget_area_5", 'name' => 'Footer: Widget Area 5', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } // PLUGIN SIDEBARS if (function_exists('register_sidebar') && class_exists('Woocommerce')) { register_sidebar(array('id' => "canon_woocommerce_widget_area", 'name' => 'WooCommerce Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar') && function_exists('bp_is_active')) { register_sidebar(array('id' => "canon_buddypress_widget_area", 'name' => 'BuddyPress Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar') && class_exists('bbPress')) { register_sidebar(array('id' => "canon_bbpress_widget_area", 'name' => 'bbPress Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } if (function_exists('register_sidebar') && class_exists('TribeEvents')) { register_sidebar(array('id' => "canon_events_widget_area", 'name' => 'Events Widget Area', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div><hr class="dots"/>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } /************************************** REGISTER CUSTOM WIDGET AREAS ***************************************/ $canon_options_advanced = get_option('canon_options_advanced'); if (isset($canon_options_advanced['custom_widget_areas'])) { for ($i = 0; $i < count($canon_options_advanced['custom_widget_areas']); $i++) { if (isset($canon_options_advanced['custom_widget_areas'][$i]['name'])) { $cwa_name = $canon_options_advanced['custom_widget_areas'][$i]['name']; $cwa_slug = mb_create_slug($cwa_name); if (function_exists('register_sidebar') && !empty($cwa_name)) { register_sidebar(array('id' => 'canon_cwa_' . $cwa_slug, 'name' => $cwa_name, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>')); } } } } }