Addresses on this site, each once. */ public static function all(): array { return array_slice( self::onSite( array_merge( self::sample(), self::more() ) ), 0, self::MAX ); } /** * The sample of the site's pages. * * @return array */ public static function sample(): array { $pages = array( home_url( '/' ) ); if ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_for_posts' ) > 0 ) { $pages[] = (string) get_permalink( (int) get_option( 'page_for_posts' ) ); } // The newest entry of each kind of content: a post, a page, a product. foreach ( get_post_types( array( 'public' => true ) ) as $type ) { if ( 'attachment' === $type || ! is_post_type_viewable( $type ) ) { continue; } $newest = get_posts( array( 'post_type' => $type, 'post_status' => 'publish', 'has_password' => false, 'numberposts' => 1, 'fields' => 'ids', 'suppress_filters' => false, ) ); if ( array() !== $newest ) { $pages[] = (string) get_permalink( (int) $newest[0] ); } } // A shop's own pages: carts and checkouts load what other pages do not. if ( function_exists( 'wc_get_page_permalink' ) ) { foreach ( array( 'shop', 'cart', 'checkout', 'myaccount' ) as $page ) { $pages[] = (string) wc_get_page_permalink( $page ); } } /** * Filters the sample of pages a scan opens. * * @param array $pages Addresses on this site. */ $pages = apply_filters( 'wmcc_scan_pages', $pages ); return self::onSite( is_array( $pages ) ? $pages : array() ); } /** * The addresses the owner added. * * @return array */ public static function more(): array { $more = get_option( self::MORE_OPTION ); return self::onSite( is_array( $more ) ? $more : array() ); } /** * Keep the addresses the owner added (those on this site, at most MAX). * * @param array $addresses What was typed. * @return array What was kept. */ public static function saveMore( array $addresses ): array { $more = array_slice( self::onSite( $addresses ), 0, self::MAX ); if ( array() === $more ) { delete_option( self::MORE_OPTION ); } else { update_option( self::MORE_OPTION, $more, false ); } return $more; } /** * Addresses of this site only, each once, without fragments. A path * ("/shop/") is taken as a page of this site. * * @param array $addresses Addresses. * @return array */ private static function onSite( array $addresses ): array { $host = strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ); $pages = array(); foreach ( $addresses as $address ) { if ( ! is_string( $address ) ) { continue; } $address = trim( $address ); if ( '' !== $address && '/' === $address[0] && '/' !== substr( $address, 1, 1 ) ) { $address = home_url( $address ); } $address = esc_url_raw( (string) strtok( $address, '#' ), array( 'http', 'https' ) ); if ( '' === $address || strtolower( (string) wp_parse_url( $address, PHP_URL_HOST ) ) !== $host ) { continue; } // The marks of a scan itself are not part of an address to scan. $address = remove_query_arg( array( Request::QUERY, Request::TOKEN, Request::INDEX, '_wpnonce' ), $address ); $pages[ $address ] = $address; }//end foreach return array_values( $pages ); } }