Ticket #22002: 22002.2.diff

File 22002.2.diff, 2.7 KB (added by Japh, 8 months ago)

Updated to user get_user_option and update_user_meta as per @nacin's advice

  • wp-admin/includes/plugin-install.php

     
    155155add_action('install_plugins_upload', 'install_plugins_upload', 10, 1); 
    156156 
    157157/** 
     158 * Show a username form for the favorites page 
     159 * @since 3.5.0 
     160 * 
     161 * @param string $page 
     162 */ 
     163function install_plugins_favorites( $page = 1 ) { 
     164        $favorites_username = isset( $_REQUEST['user'] ) ? stripslashes( $_REQUEST['user'] ) : get_user_option( 'favorites_username' ); 
     165        ?> 
     166        <h4><?php _e('Find Favorite Plugins for a WordPress.org username:') ?></h4> 
     167        <form method="post" enctype="multipart/form-data" action="<?php echo self_admin_url('plugin-install.php?tab=favorites') ?>"> 
     168                <label class="screen-reader-text" for="user"><?php _e('WordPress.org username'); ?></label> 
     169                <input type="text" id="user" name="user" value="<?php echo esc_attr($favorites_username); ?>" /> 
     170                <input type="submit" class="button" value="<?php esc_attr_e('Find Favorites') ?>" /> 
     171        </form> 
     172        <?php 
     173} 
     174add_action('install_plugins_favorites', 'install_plugins_favorites', 10, 1); 
     175 
     176/** 
    158177 * Display plugin content based on plugin list. 
    159178 * 
    160179 * @since 2.7.0 
     
    168187add_action('install_plugins_featured', 'display_plugins_table'); 
    169188add_action('install_plugins_popular', 'display_plugins_table'); 
    170189add_action('install_plugins_new', 'display_plugins_table'); 
     190add_action('install_plugins_favorites', 'display_plugins_table'); 
    171191 
    172192/** 
    173193 * Determine the status we can perform on a plugin. 
  • wp-admin/includes/class-wp-plugin-install-list-table.php

     
    3333                $tabs['featured'] = _x( 'Featured','Plugin Installer' ); 
    3434                $tabs['popular']  = _x( 'Popular','Plugin Installer' ); 
    3535                $tabs['new']      = _x( 'Newest','Plugin Installer' ); 
     36                $tabs['favorites'] = _x( 'Favorites','Plugin Installer' ); 
    3637 
    3738                $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item. 
    3839 
     
    7172                                $args['browse'] = $tab; 
    7273                                break; 
    7374 
     75                        case 'favorites': 
     76                                $favorites_username = isset( $_REQUEST['user'] ) ? stripslashes( $_REQUEST['user'] ) : get_user_option( 'favorites_username' ); 
     77                                if ( ! empty( $favorites_username ) ) { 
     78                                        $args['user'] = $favorites_username; 
     79                                        update_user_meta( get_current_user_id(), 'favorites_username', $favorites_username ); 
     80                                } else { 
     81                                        $args = false; 
     82                                } 
     83                                break; 
     84 
    7485                        default: 
    7586                                $args = false; 
    7687                }