PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Services / AuthorizationService.php

AuthorizationService.php in Depicter — Popup & Slider Builder trunk, at app/src/Services/AuthorizationService.php

67 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Services;
4
5 class AuthorizationService {
6
7 /**
8 * Whether the current user has specified capabilities or not.
9 *
10 * @param string|array $capabilities
11 *
12 * @return bool
13 */
14 public function currentUserCan( $capabilities ){
15 if( empty( $capabilities ) ){
16 return false;
17 }
18
19 $capabilities = (array) $capabilities;
20 foreach( $capabilities as $capability ){
21 if( current_user_can( $capability ) ){
22 return true;
23 }
24 }
25
26 return false;
27 }
28
29 /**
30 * Whether current user is allowed to publish document or not
31 *
32 * @return bool
33 */
34 public function currentUserCanPublishDocument(){
35 return $this->currentUserCan( [ 'manage_options', 'publish_depicter' ] );
36 }
37
38 /**
39 * Checks if user has enough quota to publish a new document based on their tier
40 *
41 * @return bool
42 */
43 public function userHasPublishQuota(){
44 // For free tier users, check if they've reached the limit (currently 2)
45 if ( \Depicter::auth()->isFreeTier() ) {
46 return \Depicter::documentRepository()->getNumberOfPublishedDocuments() < 2;
47 }
48
49 return true;
50 }
51
52 /**
53 * Get user session
54 *
55 * @return string
56 */
57 public function getUserSession(){
58 if ( !isset( $_COOKIE['depicter_session'] ) ) {
59 $session = wp_generate_uuid4();
60 setcookie( 'depicter_session', $session, 86400 * 30, '/' );
61 return $session;
62 }
63
64 return $_COOKIE['depicter_session'];
65 }
66 }
67