Hooks.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\RewriteRules; |
| 4 | |
| 5 | use WPML\Core\ISitePress; |
| 6 | use WCML\StandAlone\NullSitePress; |
| 7 | use SitePress; |
| 8 | |
| 9 | class Hooks implements \IWPML_Backend_Action, \IWPML_Frontend_Action, \IWPML_DIC_Action { |
| 10 | |
| 11 | private $sitepress; |
| 12 | |
| 13 | public function __construct( ISitePress $sitepress ) { |
| 14 | $this->sitepress = $sitepress; |
| 15 | } |
| 16 | |
| 17 | public function add_hooks() { |
| 18 | add_filter( 'pre_option_woocommerce_queue_flush_rewrite_rules', [ $this, 'preventFlushInNonDefaultLang' ] ); |
| 19 | } |
| 20 | |
| 21 | public function preventFlushInNonDefaultLang( $value ) { |
| 22 | if ( |
| 23 | $this->sitepress->get_current_language() !== $this->sitepress->get_default_language() |
| 24 | ) { |
| 25 | return 'no'; |
| 26 | } |
| 27 | if ( isset( $_REQUEST['preview_woocommerce_mail'] ) && 'true' === $_REQUEST['preview_woocommerce_mail'] ) { |
| 28 | return 'no'; |
| 29 | } |
| 30 | if ( ! is_admin() ) { |
| 31 | return 'no'; |
| 32 | } |
| 33 | |
| 34 | return $value; |
| 35 | } |
| 36 | } |
| 37 |