From 26deb029ee78c8ed6fd0c22338f84bfc2b4994ec Mon Sep 17 00:00:00 2001 From: Ben Word Date: Thu, 1 Nov 2012 18:23:49 -0500 Subject: [PATCH] Fix #580 - Menu always gets added & set on activation Also updated the method of setting the permalink structure on activation. --- CHANGELOG.md | 1 + lib/activation.php | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 897a67d..14fdb34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### HEAD +* Make sure Primary Navigation menu always gets created and has the location set upon activation, update activation permalink method * Update to Bootstrap 2.2.1 * Update conditional feed method * Update to Bootstrap 2.2.0 diff --git a/lib/activation.php b/lib/activation.php index c885892..43d33a5 100644 --- a/lib/activation.php +++ b/lib/activation.php @@ -16,13 +16,11 @@ function roots_theme_activation_options_init() { 'roots_theme_activation_options_validate' ); } - add_action('admin_init', 'roots_theme_activation_options_init'); function roots_activation_options_page_capability($capability) { return 'edit_theme_options'; } - add_filter('option_page_capability_roots_activation_options', 'roots_activation_options_page_capability'); function roots_theme_activation_options_add_page() { @@ -43,9 +41,7 @@ function roots_theme_activation_options_add_page() { exit; } } - } - add_action('admin_menu', 'roots_theme_activation_options_add_page', 50); function roots_get_default_theme_activation_options() { @@ -66,10 +62,9 @@ function roots_get_theme_activation_options() { } function roots_theme_activation_options_render_page() { ?> -
-

+

@@ -80,7 +75,7 @@ function roots_theme_activation_options_render_page() { ?> $roots_default_activation_options = roots_get_default_theme_activation_options(); ?> - + @@ -91,7 +86,7 @@ function roots_theme_activation_options_render_page() { ?> -
+
@@ -104,7 +99,7 @@ function roots_theme_activation_options_render_page() { ?> -
+
@@ -117,7 +112,7 @@ function roots_theme_activation_options_render_page() { ?> -
+
@@ -130,7 +125,7 @@ function roots_theme_activation_options_render_page() { ?> -
+
@@ -143,7 +138,7 @@ function roots_theme_activation_options_render_page() { ?> -
+
@@ -260,12 +255,12 @@ function roots_theme_activation_action() { if ($roots_theme_activation_options['change_permalink_structure']) { $roots_theme_activation_options['change_permalink_structure'] = false; + global $wp_rewrite; if (get_option('permalink_structure') !== '/%postname%/') { - update_option('permalink_structure', '/%postname%/'); + $wp_rewrite->set_permalink_structure('/%postname%/'); } - global $wp_rewrite; $wp_rewrite->init(); $wp_rewrite->flush_rules(); } @@ -282,9 +277,13 @@ function roots_theme_activation_action() { $roots_nav_theme_mod = false; - if (!has_nav_menu('primary_navigation')) { + $existing_nav = wp_get_nav_menu_object('Primary Navigation'); + if (!$existing_nav) { $primary_nav_id = wp_create_nav_menu('Primary Navigation', array('slug' => 'primary_navigation')); $roots_nav_theme_mod['primary_navigation'] = $primary_nav_id; + } else { + $primary_nav = wp_get_nav_menu_object('Primary Navigation'); + $roots_nav_theme_mod['primary_navigation'] = $primary_nav->term_id; } if ($roots_nav_theme_mod) { @@ -314,11 +313,9 @@ function roots_theme_activation_action() { update_option('roots_theme_activation_options', $roots_theme_activation_options); } - add_action('admin_init','roots_theme_activation_action'); -function roots_deactivation_action() { - update_option('roots_theme_activation_options', roots_get_default_theme_activation_options()); +function roots_deactivation() { + delete_option('roots_theme_activation_options'); } - -add_action('switch_theme', 'roots_deactivation_action'); \ No newline at end of file +add_action('switch_theme', 'roots_deactivation');