[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Routes: GP_Route_Settings class 4 * 5 * @package GlotPress 6 * @subpackage Routes 7 * @since 2.0.0 8 */ 9 10 /** 11 * Core class used to implement the settings route. 12 * 13 * @since 2.0.0 14 */ 15 class GP_Route_Settings extends GP_Route_Main { 16 17 /** 18 * Displays the settings page, requires a user to be logged in. 19 */ 20 public function settings_get() { 21 if ( ! is_user_logged_in() ) { 22 $this->redirect( wp_login_url( gp_url_profile() ) ); 23 exit; 24 } 25 26 $this->tmpl( 'settings' ); 27 } 28 29 /** 30 * Saves settings for a user and redirects back to the settings page. 31 * 32 * @param int $user_id Optional. A user id, if not provided the id of the currently logged in user will be used. 33 */ 34 public function settings_post( $user_id = null ) { 35 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by invalid_nonce_and_redirect() 36 if ( isset( $_POST['submit'] ) ) { 37 // Sometimes we get null, sometimes we get 0, depending on where it comes from. 38 // Let's make sure we have a consistent value to test against and that it's an integer. 39 $user_id = (int) $user_id; 40 41 if ( 0 === $user_id ) { 42 $user_id = get_current_user_id(); 43 } 44 45 if ( $this->invalid_nonce_and_redirect( 'update-settings_' . $user_id ) ) { 46 return; 47 } 48 49 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by invalid_nonce_and_redirect() 50 $per_page = (int) $_POST['per_page']; 51 update_user_option( $user_id, 'gp_per_page', $per_page ); 52 53 $default_sort = array( 54 'by' => 'priority', 55 'how' => 'desc', 56 ); 57 58 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by invalid_nonce_and_redirect() 59 $user_sort = wp_parse_args( $_POST['default_sort'], $default_sort ); 60 update_user_option( $user_id, 'gp_default_sort', $user_sort ); 61 62 $this->notices[] = __( 'Settings saved!', 'glotpress' ); 63 } 64 65 $this->redirect( gp_url( '/settings' ) ); 66 exit; 67 } 68 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:01:04 2024 | Cross-referenced by PHPXref 0.7.1 |