WordPress.org

Make WordPress Core

Changeset 13271


Ignore:
Timestamp:
02/21/2010 12:34:44 AM (8 years ago)
Author:
ryan
Message:

Cleanups. see #11817

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-navigation.php

    r13269 r13271  
    2424wp_enqueue_script( 'custom-navigation-php-functions' );
    2525
    26 
    2726require_once('admin-header.php');
    2827require_once (ABSPATH . WPINC . '/custom-navigation.php');
     
    3635
    3736}
    38 
    3937
    4038/*-----------------------------------------------------------------------------------*/
     
    5654
    5755    // Get the theme name
    58     $themename =  get_current_theme();
     56    $themename = get_current_theme();
    5957
    6058    // Check which menu is selected and if menu is in edit already
    6159    if ( isset( $_POST['switch_menu'] ) )
    62         $menu_selected_id = $_POST['menu_select'];
     60        $menu_selected_id = (int) $_POST['menu_select'];
    6361    elseif ( isset( $_POST['menu_id_in_edit'] ) )
    64         $menu_selected_id = $_POST['menu_id_in_edit'];
     62        $menu_selected_id = (int) $_POST['menu_id_in_edit'];
     63    else
     64        $menu_selected_id = 0;
    6565
    6666    // Default Menu to show
     
    7171    $menu_title = '';
    7272    if ( $menu_selected_id > 0 ) {
    73         foreach( $custom_menus as $menu ) {
     73        foreach ( $custom_menus as $menu ) {
    7474            if ( $menu->term_id == $menu_selected_id ) {
    7575                $menu_title = $menu->name;
     
    8080
    8181    if ( isset( $_POST['set_wp_menu'] ) ) {
    82             update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
     82        // @todo validate set_wp_menu
     83        update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
    8384        $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been updated!</p></div>';
    8485    }
     
    8788        $postCounter = $_POST['licount'];
    8889    else
    89             $postCounter = 0;
     90        $postCounter = 0;
    9091
    9192    // Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
     
    103104                    $menu_selected_id = $term['term_id'];
    104105                    $menu_id_in_edit = $menu_selected_id;
    105                     $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$insert_menu_name.' Menu has been created!</p></div>';
     106                    $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$term['name'].' Menu has been created!</p></div>';
    106107
    107108                    $postCounter = 0;
     
    114115
    115116    if ( isset($_POST['reset_wp_menu']) ) {
    116             $success = wp_custom_nav_reset();
    117             if ($success) {
    118                 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
    119                 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been RESET!</p></div>';
    120                 // GET reset menu id
    121                 $custom_menus = array();
    122                 $menu_selected_id = 0;
    123             } else {
    124                 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
    125                 $messagesdiv = '<div id="message" class="error fade below-h2"><p>'.$themename.'s Custom Menu could not be RESET. Please try again.</p></div>';
    126             }
     117        $success = wp_custom_nav_reset();
     118        if ( $success ) {
     119            // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
     120            $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been RESET!</p></div>';
     121            // GET reset menu id
     122            $custom_menus = array();
     123            $menu_selected_id = 0;
     124        } else {
     125            // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
     126            $messagesdiv = '<div id="message" class="error fade below-h2"><p>'.$themename.'s Custom Menu could not be RESET. Please try again.</p></div>';
     127        }
    127128    } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
    128129        $menu_objects = get_objects_in_term( $menu_selected_id, 'menu' );
    129130        $menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
    130131
    131         $update_fields = array( 'menu_order', 'guid', 'post_content', 'post_title', 'post_excerpt', 'post_content_filtered' );
    132         //Loop through all POST variables
    133         for ($k = 1;$k<= $postCounter; $k++) {
    134 
     132        // Loop through all POST variables
     133        for ( $k = 1; $k <= $postCounter; $k++ ) {
    135134            if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; }
    136135            if (isset($_POST['postmenu'.$k])) { $post_id = $_POST['postmenu'.$k]; } else { $post_id = 0; }
    137 //@todo implement heirarchy
     136            //@todo implement heirarchy
    138137            if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; }
    139             if (isset($_POST['title'.$k])) { $custom_title = stripslashes($_POST['title'.$k]); } else { $custom_title = ''; }
     138            if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; }
    140139            if (isset($_POST['linkurl'.$k])) { $custom_linkurl = $_POST['linkurl'.$k]; } else { $custom_linkurl = ''; }
    141             if (isset($_POST['description'.$k])) { $custom_description = stripslashes($_POST['description'.$k]); } else { $custom_description = ''; }
    142 // doesn't seem to be used by UI
     140            if (isset($_POST['description'.$k])) { $custom_description = $_POST['description'.$k]; } else { $custom_description = ''; }
     141            // doesn't seem to be used by UI
    143142            if (isset($_POST['icon'.$k])) { $icon = $_POST['icon'.$k]; } else { $icon = 0; }
    144143            if (isset($_POST['position'.$k])) { $position = $_POST['position'.$k]; } else { $position = 0; }
    145144            if (isset($_POST['linktype'.$k])) { $linktype = $_POST['linktype'.$k]; } else { $linktype = 'custom'; }
    146             if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = stripslashes($_POST['anchortitle'.$k]); } else { $custom_anchor_title = $custom_title; }
     145            if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; }
    147146            if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; }
    148147
     
    156155                $post['post_content_filtered'] = '';
    157156
    158             //New menu item
    159             if ($db_id == 0) {
     157            // New menu item
     158            if ( $db_id == 0 ) {
    160159                $db_id = $post_id = wp_insert_post( $post );
    161160            } elseif ( isset( $menu_items[$db_id] ) ) {
    162                 foreach( $update_fields as $field ) {
    163                     if ( $post[$field] != $menu_items[$db_id]->$field ) {
    164                         $post['ID'] = $db_id;
    165                         wp_update_post( $post );
    166                         break;
    167                     }
    168                 }
     161                $post['ID'] = $db_id;
     162                wp_update_post( $post );
    169163                unset( $menu_items[$db_id] );
    170164            }
     
    172166        }
    173167        if ( !empty( $menu_items ) ) {
    174             foreach( array_keys( $menu_items ) as $menu_id ) {
     168            foreach ( array_keys( $menu_items ) as $menu_id ) {
    175169                wp_delete_post( $menu_id );
    176170            }
    177171        }
    178         //DISPLAY SUCCESS MESSAGE IF POST CORRECT
     172        // DISPLAY SUCCESS MESSAGE IF POST CORRECT
    179173        $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been updated!</p></div>';
    180174    }
Note: See TracChangeset for help on using the changeset viewer.