PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/admin/capabilities/class-capability-utils.php

https://bitbucket.org/carloskikea/helpet
PHP | 54 lines | 20 code | 5 blank | 29 comment | 2 complexity | 4b7e532d6474ccbfb5769691e5d37bd1 MD5 | raw file
 1<?php
 2/**
 3 * WPSEO plugin file.
 4 *
 5 * @package WPSEO\Admin\Capabilities
 6 */
 7
 8/**
 9 * Capability Utils collection.
10 */
11class WPSEO_Capability_Utils {
12	/**
13	 * Checks if the user has the proper capabilities.
14	 *
15	 * @param string $capability Capability to check.
16	 *
17	 * @return bool True if the user has the proper rights.
18	 */
19	public static function current_user_can( $capability ) {
20		if ( $capability === 'wpseo_manage_options' ) {
21			return self::has( $capability );
22		}
23
24		return self::has_any( array( 'wpseo_manage_options', $capability ) );
25	}
26
27	/**
28	 * Checks if the current user has at least one of the supplied capabilities.
29	 *
30	 * @param array $capabilities Capabilities to check against.
31	 *
32	 * @return bool True if the user has at least one capability.
33	 */
34	protected static function has_any( array $capabilities ) {
35		foreach ( $capabilities as $capability ) {
36			if ( self::has( $capability ) ) {
37				return true;
38			}
39		}
40
41		return false;
42	}
43
44	/**
45	 * Checks if the user has a certain capability.
46	 *
47	 * @param string $capability Capability to check against.
48	 *
49	 * @return bool True if the user has the capability.
50	 */
51	protected static function has( $capability ) {
52		return current_user_can( $capability );
53	}
54}