' .
esc_html__( 'Success! Your Wordfence Firewall rules have been optimized to work with OptinMonster.', 'optin-monster-api' ) .
'
';
}
/**
* Handles auto-fixing the WF rules after user clicks the "Fix this for me" button.
*
* @since 2.10.0
*/
public function auto_update_rules() {
if ( ! self::has_expired_rules() ) {
return;
}
// Make sure nonce check passes.
check_admin_referer( 'om_fix_waf_rules', 'nonce' );
self::remove_expired_rules();
$url = add_query_arg(
'om_fix_waf_rules',
'success',
! empty( $_GET['return'] ) ? $_GET['return'] : admin_url()
);
wp_safe_redirect( esc_url_raw( $url ) );
exit;
}
/**
* Determine if the WF firewall rules have any of the expired OM rules enabled.
*
* @since 2.10.0
*
* @return boolean Whether the WF firewall rules have any of the expired OM rules enabled..
*/
protected static function has_expired_rules() {
if ( ! is_callable( array( wfWAF::getInstance(), 'getStorageEngine' ) ) ) {
return false;
}
$disabled_rules = (array) wfWAF::getInstance()->getStorageEngine()->getConfig( 'disabledRules' );
$found_rules = self::$expired_om_rules;
foreach ( $found_rules as $rule_id => $one ) {
if ( ! empty( $disabled_rules[ $rule_id ] ) ) {
unset( $found_rules[ $rule_id ] );
}
}
return ! empty( $found_rules );
}
/**
* Handles updating the WF firewall disabled rules to include the expired OM rules.
*
* @since 2.10.0
*/
protected function remove_expired_rules() {
$disabled = (array) wfWAF::getInstance()->getStorageEngine()->getConfig( 'disabledRules' );
foreach ( self::$expired_om_rules as $rule_id => $one ) {
$disabled[ $rule_id ] = true;
}
wfWAF::getInstance()->getStorageEngine()->setConfig( 'disabledRules', $disabled );
}
/**
* Checks if given (or current) page is a wordfence admin page.
*
* @since 2.10.0
*
* @param strgin $page Page to check. Falls back to $_REQUEST['page'].
*
* @return boolean Whether given (or current) page is a wordfence admin page.
*/
public static function is_wf_page( $page = null ) {
if ( empty( $page ) && ! empty( $_REQUEST['page'] ) ) {
$page = $_REQUEST['page'];
}
if ( empty( $page ) ) {
return false;
}
$page = sanitize_key( $page );
return 'wfls' === $page || preg_match( '/wordfence/', $page );
}
/**
* Check if the Wordfence plugin is active.
*
* @since 2.10.0
*
* @return bool
*/
public static function is_active() {
return is_callable( 'wfWAF::getInstance' );
}
}