]*\bsrc\s*=\s*["\']https://rabbitproof\.com\.au/v1/rp\.js[^"\']*["\'][^>]*>\s*[ \t]*\r?\n?#i'; const OPTIONS = array( 'ihaf_insert_header', 'ihaf_insert_body', 'ihaf_insert_footer', 'auhfc_settings_sitewide', 'widget_custom_html', 'widget_text' ); private static function has( $v ) { if ( is_string( $v ) ) { return 1 === preg_match( self::TAG, $v ); } if ( is_array( $v ) ) { foreach ( $v as $x ) { if ( self::has( $x ) ) { return true; } } } return false; } private static function strip( $v ) { if ( is_string( $v ) ) { return preg_replace( self::TAG, '', $v ); } if ( is_array( $v ) ) { foreach ( $v as $k => $x ) { $v[ $k ] = self::strip( $x ); } } return $v; } private static function snippets() { if ( ! post_type_exists( 'wpcode' ) ) { return array(); } $ids = get_posts( array( 'post_type' => 'wpcode', 'post_status' => 'any', 'numberposts' => 200, 'fields' => 'ids', 's' => 'rabbitproof.com.au/v1/rp.js' ) ); return array_values( array_filter( (array) $ids, function ( $id ) { return self::has( (string) get_post_field( 'post_content', $id ) ); } ) ); } public static function found() { $at = array(); foreach ( self::OPTIONS as $name ) { if ( self::has( get_option( $name ) ) ) { $at[] = $name; } } foreach ( self::snippets() as $id ) { $at[] = 'post:' . $id; } return $at; } public static function remove() { foreach ( self::found() as $place ) { if ( 0 === strpos( $place, 'post:' ) ) { $id = (int) substr( $place, 5 ); wp_update_post( array( 'ID' => $id, 'post_content' => self::strip( (string) get_post_field( 'post_content', $id ) ) ) ); } else { update_option( $place, self::strip( get_option( $place ) ) ); } } return array() === self::found(); } public static function line() { return 'rabbitproof.com.au/v1/rp.js'; } }