[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/routes/ -> settings.php (source)

   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          if ( isset( $_POST['submit'] ) ) {
  36              // Sometimes we get null, sometimes we get 0, depending on where it comes from.
  37              // Let's make sure we have a consistent value to test against and that it's an integer.
  38              $user_id = (int) $user_id;
  39  
  40              if ( 0 === $user_id ) {
  41                  $user_id = get_current_user_id();
  42              }
  43  
  44              if ( $this->invalid_nonce_and_redirect( 'update-settings_' . $user_id ) ) {
  45                  return;
  46              }
  47  
  48              $per_page = (int) $_POST['per_page'];
  49              update_user_option( $user_id, 'gp_per_page', $per_page );
  50  
  51              $default_sort = array(
  52                  'by'  => 'priority',
  53                  'how' => 'desc',
  54              );
  55  
  56              $user_sort = wp_parse_args( $_POST['default_sort'], $default_sort );
  57              update_user_option( $user_id, 'gp_default_sort', $user_sort );
  58  
  59              $this->notices[] = __( 'Settings saved!', 'glotpress' );
  60          }
  61  
  62          $this->redirect( gp_url( '/settings' ) );
  63          exit;
  64      }
  65  }


Generated: Sun Jun 7 01:01:45 2020 Cross-referenced by PHPXref 0.7.1