false, ); /** * Groups of variables to restrict. * * @return array */ public function getGroups() { return array( 'posts_per_page' => array( 'type' => 'error', 'keys' => array( 'posts_per_page', 'nopaging', 'numberposts', ), ), ); } /** * Callback to process each confirmed key, to check value. * * @param string $key Array index / key. * @param mixed $val Assigned value. * @param int $line Token line. * @param array $group Group definition. * @return mixed FALSE if no match, TRUE if matches, STRING if matches * with custom error message passed to ->process(). */ public function callback( $key, $val, $line, $group ) { if ( 100 !== (int) $this->posts_per_page && false === $this->thrown['FoundDeprecatedProperty'] ) { $this->phpcsFile->addWarning( 'The "posts_per_page" property for the "WordPress.VIP.PostsPerPage" sniff is deprecated. The detection of high pagination limits has been moved to the "WordPress.WP.PostsPerPage" sniff. Please update your custom ruleset.', 0, 'FoundDeprecatedProperty' ); $this->thrown['FoundDeprecatedProperty'] = true; } $key = strtolower( $key ); if ( ( 'nopaging' === $key && ( 'true' === $val || 1 === $val ) ) || ( \in_array( $key, array( 'numberposts', 'posts_per_page' ), true ) && '-1' === $val ) ) { return 'Disabling pagination is prohibited in VIP context, do not set `%s` to `%s` ever.'; } return false; } }