ignore ) ) { $this->ignore = '' === $this->ignore ? array() : array( $this->ignore ); $this->save(); } return in_array( $slug, $this->ignore, true ); } /** * Is the tweak in the Issue list?. * * @param string $slug Tweak slug. * * @return bool */ public function is_tweak_issue( string $slug ): bool { return in_array( $slug, $this->issues, true ); } /** * Mark a tweak as actioned. * * @param string $status Status. * @param string $slug Tweak slug. */ public function mark( $status, $slug ) { foreach ( array( \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES, \WP_Defender\Controller\Security_Tweaks::STATUS_RESOLVE, \WP_Defender\Controller\Security_Tweaks::STATUS_IGNORE, ) as $collection_name ) { $collection = $this->get_collection( $collection_name ); if ( ! is_array( $collection ) ) { continue; } $index = array_search( $slug, $collection, true ); if ( false !== $index ) { unset( $collection[ $index ] ); } $this->set_collection( $collection_name, $collection ); } if ( \WP_Defender\Controller\Security_Tweaks::STATUS_RESTORE === $status ) { $status = \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES; } if ( ! property_exists( $this, $status ) ) { return; } try { $collection = $this->get_collection( $status ); } catch ( \InvalidArgumentException $e ) { return; } $collection[] = $slug; $this->set_collection( $status, $collection ); $this->save(); } /** * Get a tweak collection by name. * * @param string $name Collection name. * * @return array * * @throws \InvalidArgumentException Invalid collection name. */ public function get_collection( string $name ): array { switch ( $name ) { case \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES: return $this->issues; case \WP_Defender\Controller\Security_Tweaks::STATUS_RESOLVE: return $this->fixed; case \WP_Defender\Controller\Security_Tweaks::STATUS_IGNORE: return $this->ignore; default: throw new \InvalidArgumentException( 'Invalid collection name.' ); } } /** * Set a tweak collection by name. * * @param string $name Collection name. * @param array $value Collection value. * * @throws \InvalidArgumentException Invalid collection name. */ private function set_collection( string $name, array $value ): void { switch ( $name ) { case \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES: $this->issues = $value; break; case \WP_Defender\Controller\Security_Tweaks::STATUS_RESOLVE: $this->fixed = $value; break; case \WP_Defender\Controller\Security_Tweaks::STATUS_IGNORE: $this->ignore = $value; break; default: throw new \InvalidArgumentException( 'Invalid collection name.' ); } } /** * Define settings labels. * * @return array */ public function labels(): array { return array( 'data' => 'data', 'fixed' => esc_html__( 'Actioned', 'defender-security' ), 'issues' => esc_html__( 'Recommendations', 'defender-security' ), 'ignore' => esc_html__( 'Ignored', 'defender-security' ), 'automate' => 'automate', ); } /** * Todo: Find a less expensive way. * * @return array */ public function get_tweak_types(): array { return array( 'count_fixed' => count( $this->fixed ), 'count_ignored' => count( $this->ignore ), 'count_issues' => count( $this->issues ), ); } }