/**
  * Redirects if needed.
  *
  * @return bool
  */
 public function redirect()
 {
     if (!empty($_GET['noredirect'])) {
         $this->save_session($_GET['noredirect']);
         return false;
     }
     $redirect_match = $this->negotiation->get_redirect_match();
     $current_site_id = get_current_blog_id();
     if ($redirect_match['site_id'] === $current_site_id) {
         return false;
     }
     /**
      * Filters the redirect URL.
      *
      * @param string $url             Redirect URL.
      * @param array  $redirect_match  Redirect match. {
      *                                    'priority' => int
      *                                    'url'      => string
      *                                    'language' => string
      *                                    'site_id'  => int
      *                                }
      * @param int    $current_site_id Current site ID.
      */
     $url = (string) apply_filters('mlp_redirect_url', $redirect_match['url'], $redirect_match, $current_site_id);
     if (!$url) {
         return false;
     }
     $this->save_session($redirect_match['language']);
     wp_redirect($url);
     \Inpsyde\MultilingualPress\call_exit();
     return true;
 }
 /**
  * Check if current request is allowed and complete.
  *
  * @return array
  */
 private function validate_request()
 {
     \Inpsyde\MultilingualPress\check_admin_referer($this->nonce);
     if (empty($_POST['languages'])) {
         \Inpsyde\MultilingualPress\call_exit('invalid request');
     }
     return (array) $_POST['languages'];
 }
 /**
  * Updates the plugin settings according to the data in the request.
  *
  * @since 3.0.0
  *
  * @return void
  */
 public function update_settings()
 {
     \Inpsyde\MultilingualPress\check_admin_referer($this->nonce);
     array_walk(array_keys($this->module_manager->get_modules()), [$this, 'update_module']);
     $this->module_manager->save_modules();
     /**
      * Runs before the redirect.
      *
      * Process your fields in the $_POST superglobal here and then call update_site_option().
      *
      * @param array $_POST
      */
     do_action('mlp_modules_save_fields', $_POST);
     wp_safe_redirect(add_query_arg('message', 'updated', $this->settings_page->url()));
     \Inpsyde\MultilingualPress\call_exit();
 }
 /**
  * Catches quicklink submissions and redirects if the URL is valid.
  *
  * @since 1.0.4
  *
  * @param string $url The URL that is to be redirected to.
  *
  * @return void
  */
 private function redirect_quick_link($url)
 {
     $callback = [$this, 'extend_allowed_hosts'];
     add_filter('allowed_redirect_hosts', $callback, 10, 2);
     $url = wp_validate_redirect($url, false);
     remove_filter('allowed_redirect_hosts', $callback);
     if (!$url) {
         return;
     }
     // Force GET request.
     wp_redirect($url, 303);
     \Inpsyde\MultilingualPress\call_exit();
 }
 /**
  * Combine all update actions.
  *
  * @return void
  */
 public function update_settings()
 {
     if (!\Inpsyde\MultilingualPress\check_admin_referer($this->nonce)) {
         wp_die('Invalid', 'Invalid', 403);
     }
     $blog_id = $this->get_blog_id();
     $this->update_language($blog_id);
     $this->update_flag($blog_id);
     $this->update_related_blogs($blog_id);
     /**
      * Runs after having saved the site settings.
      *
      * @param array $_POST The $_POST superglobal.
      */
     do_action('mlp_blogs_save_fields', $_POST);
     $url = add_query_arg('msg', 'updated', $_POST['_wp_http_referer']);
     wp_safe_redirect($url);
     \Inpsyde\MultilingualPress\call_exit();
 }
 /**
  * @return void
  */
 public function reset_table()
 {
     \Inpsyde\MultilingualPress\check_admin_referer($this->nonce);
     $table_prefix = $this->wpdb->base_prefix;
     $table = new LanguagesTable($table_prefix);
     $installer = new WPDBTableInstaller($table);
     $installer->uninstall();
     $installer->install();
     /**
      * Runs after having reset the database table.
      *
      * @param Table $table Languages table object.
      */
     do_action('mlp_reset_table_done', $table);
     $url = add_query_arg('msg', 'resettable', $_REQUEST['_wp_http_referer']);
     wp_safe_redirect($url);
     \Inpsyde\MultilingualPress\call_exit();
 }