<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13271] trunk/wp-admin/custom-navigation.php: Cleanups.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13271">13271</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-21 00:34:44 +0000 (Sun, 21 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cleanups. see <a href="http://trac.wordpress.org/ticket/11817">#11817</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustomnavigationphp">trunk/wp-admin/custom-navigation.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustomnavigationphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-navigation.php (13270 => 13271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-navigation.php        2010-02-21 00:19:05 UTC (rev 13270)
+++ trunk/wp-admin/custom-navigation.php        2010-02-21 00:34:44 UTC (rev 13271)
</span><span class="lines">@@ -23,7 +23,6 @@
</span><span class="cx"> wp_enqueue_script( 'jquery-autocomplete' );
</span><span class="cx"> wp_enqueue_script( 'custom-navigation-php-functions' );
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> require_once('admin-header.php');
</span><span class="cx"> require_once (ABSPATH . WPINC . '/custom-navigation.php');
</span><span class="cx"> 
</span><span class="lines">@@ -36,7 +35,6 @@
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> /*-----------------------------------------------------------------------------------*/
</span><span class="cx"> /* Custom Navigation Admin Interface
</span><span class="cx"> /* wp_custom_navigation() is the main function for the Custom Navigation
</span><span class="lines">@@ -55,13 +53,15 @@
</span><span class="cx">         $menu_id_in_edit = 0;
</span><span class="cx"> 
</span><span class="cx">         // Get the theme name
</span><del>-        $themename =  get_current_theme();
</del><ins>+        $themename = get_current_theme();
</ins><span class="cx"> 
</span><span class="cx">         // Check which menu is selected and if menu is in edit already
</span><span class="cx">         if ( isset( $_POST['switch_menu'] ) )
</span><del>-                $menu_selected_id = $_POST['menu_select'];
</del><ins>+                $menu_selected_id = (int) $_POST['menu_select'];
</ins><span class="cx">         elseif ( isset( $_POST['menu_id_in_edit'] ) )
</span><del>-                $menu_selected_id = $_POST['menu_id_in_edit'];
</del><ins>+                $menu_selected_id = (int) $_POST['menu_id_in_edit'];
+        else
+                $menu_selected_id = 0;
</ins><span class="cx"> 
</span><span class="cx">         // Default Menu to show
</span><span class="cx">         $custom_menus = get_terms( 'menu', array( 'hide_empty' =&gt; false ) );
</span><span class="lines">@@ -70,7 +70,7 @@
</span><span class="cx"> 
</span><span class="cx">         $menu_title = '';
</span><span class="cx">         if ( $menu_selected_id &gt; 0 ) {
</span><del>-                foreach( $custom_menus as $menu ) {
</del><ins>+                foreach ( $custom_menus as $menu ) {
</ins><span class="cx">                         if ( $menu-&gt;term_id == $menu_selected_id ) {
</span><span class="cx">                                 $menu_title = $menu-&gt;name;
</span><span class="cx">                                 break;
</span><span class="lines">@@ -79,14 +79,15 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( isset( $_POST['set_wp_menu'] ) ) {
</span><del>-                    update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
</del><ins>+                // @todo validate set_wp_menu
+            update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
</ins><span class="cx">                 $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;updated fade below-h2&quot;&gt;&lt;p&gt;'.$themename.'s Custom Menu has been updated!&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( isset( $_POST['licount'] ) )
</span><span class="cx">                 $postCounter = $_POST['licount'];
</span><span class="cx">         else
</span><del>-                    $postCounter = 0;
</del><ins>+            $postCounter = 0;
</ins><span class="cx"> 
</span><span class="cx">         // Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
</span><span class="cx">         if ( isset( $_POST['add_menu'] ) ) {
</span><span class="lines">@@ -102,7 +103,7 @@
</span><span class="cx">                                         $custom_menus[$term['term_id']] = $term;
</span><span class="cx">                                          $menu_selected_id = $term['term_id'];
</span><span class="cx">                                          $menu_id_in_edit = $menu_selected_id;
</span><del>-                                         $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;updated fade below-h2&quot;&gt;&lt;p&gt;'.$insert_menu_name.' Menu has been created!&lt;/p&gt;&lt;/div&gt;';
</del><ins>+                                         $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;updated fade below-h2&quot;&gt;&lt;p&gt;'.$term['name'].' Menu has been created!&lt;/p&gt;&lt;/div&gt;';
</ins><span class="cx"> 
</span><span class="cx">                                         $postCounter = 0;
</span><span class="cx">                                  }
</span><span class="lines">@@ -113,37 +114,35 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( isset($_POST['reset_wp_menu']) ) {
</span><del>-                    $success = wp_custom_nav_reset();
-                    if ($success) {
-                            // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
-                                $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;updated fade below-h2&quot;&gt;&lt;p&gt;'.$themename.'s Custom Menu has been RESET!&lt;/p&gt;&lt;/div&gt;';
-                                // GET reset menu id
-                                $custom_menus = array();
-                                $menu_selected_id = 0;
-                    } else {
-                            // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
-                                $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;error fade below-h2&quot;&gt;&lt;p&gt;'.$themename.'s Custom Menu could not be RESET. Please try again.&lt;/p&gt;&lt;/div&gt;';
-                    }
</del><ins>+            $success = wp_custom_nav_reset();
+            if ( $success ) {
+                    // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
+                        $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;updated fade below-h2&quot;&gt;&lt;p&gt;'.$themename.'s Custom Menu has been RESET!&lt;/p&gt;&lt;/div&gt;';
+                        // GET reset menu id
+                        $custom_menus = array();
+                        $menu_selected_id = 0;
+            } else {
+                    // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
+                        $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;error fade below-h2&quot;&gt;&lt;p&gt;'.$themename.'s Custom Menu could not be RESET. Please try again.&lt;/p&gt;&lt;/div&gt;';
+            }
</ins><span class="cx">         } elseif ( $postCounter &gt; 0 &amp;&amp; $menu_selected_id &gt; 0 ) {
</span><span class="cx">                 $menu_objects = get_objects_in_term( $menu_selected_id, 'menu' );
</span><span class="cx">                 $menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
</span><span class="cx"> 
</span><del>-                $update_fields = array( 'menu_order', 'guid', 'post_content', 'post_title', 'post_excerpt', 'post_content_filtered' );
-                //Loop through all POST variables
-                 for ($k = 1;$k&lt;= $postCounter; $k++) {
-
</del><ins>+                // Loop through all POST variables
+                 for ( $k = 1; $k &lt;= $postCounter; $k++ ) {
</ins><span class="cx">                          if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; }
</span><span class="cx">                          if (isset($_POST['postmenu'.$k])) { $post_id = $_POST['postmenu'.$k]; } else { $post_id = 0; }
</span><del>-//@todo implement heirarchy
</del><ins>+                        //@todo implement heirarchy
</ins><span class="cx">                         if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; }
</span><del>-                         if (isset($_POST['title'.$k])) { $custom_title = stripslashes($_POST['title'.$k]); } else { $custom_title = ''; }
</del><ins>+                         if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; }
</ins><span class="cx">                          if (isset($_POST['linkurl'.$k])) { $custom_linkurl = $_POST['linkurl'.$k]; } else { $custom_linkurl = ''; }
</span><del>-                         if (isset($_POST['description'.$k])) { $custom_description = stripslashes($_POST['description'.$k]); } else { $custom_description = ''; }
-// doesn't seem to be used by UI
</del><ins>+                         if (isset($_POST['description'.$k])) { $custom_description = $_POST['description'.$k]; } else { $custom_description = ''; }
+                        // doesn't seem to be used by UI
</ins><span class="cx">                         if (isset($_POST['icon'.$k])) { $icon = $_POST['icon'.$k]; } else { $icon = 0; }
</span><span class="cx">                          if (isset($_POST['position'.$k])) { $position = $_POST['position'.$k]; } else { $position = 0; }
</span><span class="cx">                          if (isset($_POST['linktype'.$k])) { $linktype = $_POST['linktype'.$k]; } else { $linktype = 'custom'; }
</span><del>-                         if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = stripslashes($_POST['anchortitle'.$k]); } else { $custom_anchor_title = $custom_title; }
</del><ins>+                         if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; }
</ins><span class="cx">                          if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; }
</span><span class="cx"> 
</span><span class="cx">                         $post = array( 'post_status' =&gt; 'publish', 'post_type' =&gt; 'menu_item', 'post_author' =&gt; $user_ID,
</span><span class="lines">@@ -155,27 +154,22 @@
</span><span class="cx">                         else
</span><span class="cx">                                 $post['post_content_filtered'] = '';
</span><span class="cx"> 
</span><del>-                        //New menu item
-                         if ($db_id == 0) {
</del><ins>+                        // New menu item
+                         if ( $db_id == 0 ) {
</ins><span class="cx">                                 $db_id = $post_id = wp_insert_post( $post );
</span><span class="cx">                         } elseif ( isset( $menu_items[$db_id] ) ) {
</span><del>-                                foreach( $update_fields as $field ) {
-                                        if ( $post[$field] != $menu_items[$db_id]-&gt;$field ) {
-                                                $post['ID'] = $db_id;
-                                                wp_update_post( $post );
-                                                break;
-                                        }
-                                }
</del><ins>+                                $post['ID'] = $db_id;
+                                wp_update_post( $post );
</ins><span class="cx">                                 unset( $menu_items[$db_id] );
</span><span class="cx">                         }
</span><span class="cx">                         update_post_meta($db_id, 'menu_type', $linktype);
</span><span class="cx">                 }
</span><span class="cx">                 if ( !empty( $menu_items ) ) {
</span><del>-                        foreach( array_keys( $menu_items ) as $menu_id ) {
</del><ins>+                        foreach ( array_keys( $menu_items ) as $menu_id ) {
</ins><span class="cx">                                 wp_delete_post( $menu_id );
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                //DISPLAY SUCCESS MESSAGE IF POST CORRECT
</del><ins>+                // DISPLAY SUCCESS MESSAGE IF POST CORRECT
</ins><span class="cx">                 $messagesdiv = '&lt;div id=&quot;message&quot; class=&quot;updated fade below-h2&quot;&gt;&lt;p&gt;'.$themename.'s Custom Menu has been updated!&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>