/**
  * Display an input field customize object's permalink.
  */
 public function permalink_structure_field()
 {
     global $wp_rewrite;
     $obj_tag = '%' . $this->obj_type . '%';
     $setting = $this->obj_name . '_structure';
     $options = get_option('boilerplate', []);
     $value = isset($options[$setting]) ? $options[$setting] : '/' . $obj_tag . '/';
     $object = get_post_type_object($this->obj_type);
     $object_prefix = $object->rewrite['slug'];
     $front = class_exists('Polylang') ? pll_get_rewrite_front() : $wp_rewrite->front;
     if ($front and $object->rewrite['with_front']) {
         $slug = $front . $object_prefix;
     }
     echo '<code>' . home_url() . '/' . $object_prefix . (got_url_rewrite() ? '' : '?post_type=' . $this->obj_type . '&p=123') . '</code>';
     if (got_url_rewrite()) {
         echo '<input name="' . 'boilerplate-' . $setting . '" id="' . 'boilerplate-' . $setting . '" type="text" value="' . esc_attr($value) . '" class="regular-text code" />';
     }
 }
 /**
  * Remove extra rules for archives.
  *
  * This removes rewrite rules dedicated for archive routes for certain
  * special object types. These special object types, like post, rely
  * on the `page_for_*` option as their archive center.
  *
  * @see Extra rules from WordPress (wp-include/post.php, register_post_type()).
  */
 public function remove_extra_rules($rules)
 {
     global $wp_rewrite;
     if ($this->obj_rewrite) {
         $front = pll_get_rewrite_front();
         $translated_slugs = $this->pll_translate_slugs();
         $translated_slugs = $translated_slugs[$this->obj_type];
         foreach ($translated_slugs as $lang => $translated_slug) {
             $translated_slug = (object) $translated_slug;
             /**
              * Remove the root archive request such that the request matches
              * with the `pagename` query variable.
              *
              * @example Matchs & Removes "(fr|en)/statements/?$"
              */
             $extra_rule_key = $front . $translated_slug->rewrite['slug'] . '/?$';
             if (array_key_exists($extra_rule_key, $rules)) {
                 unset($rules[$extra_rule_key]);
             }
             /**
              * Replace the archive pagination route such that the request matches
              * with the `pagename` query variable.
              *
              * @example - Matches  "(fr|en)/statements/page/([0-9]{1,})/?$"
              *          - Modifies "index.php?lang=$matches[1]&post_type=upa-statement&paged=$matches[2]"
              */
             // Replace Archive Pagination Route
             // to match
             $extra_rule_key = $front . $translated_slug->rewrite['slug'] . '/' . $wp_rewrite->pagination_base . '/([0-9]{1,})/?$';
             if (array_key_exists($extra_rule_key, $rules)) {
                 $search = ['#lang=\\$matches\\[\\d+?\\]&?#', '#post_type=' . $this->obj_type . '#'];
                 $replace = ['', 'pagename=' . $translated_slug->rewrite['slug']];
                 $rules[$extra_rule_key] = preg_replace($search, $replace, $rules[$extra_rule_key]);
             }
         }
     }
     return $rules;
 }
 /**
  * Remove extra rules for archives.
  *
  * Modified method to target all object types.
  *
  * @see \Boilerplate\AbstractObject::remove_extra_rules().
  */
 public function remove_extra_rules($rules)
 {
     $front = pll_get_rewrite_front();
     foreach (static::$post_types as $obj_name => $obj_inst) {
         if ($obj_inst->obj_rewrite && method_exists($obj_inst, 'remove_extra_rules')) {
             $rules = $obj_inst->remove_extra_rules($rules);
         }
     }
     return $rules;
 }