Advanced Access Manager - Version 2.1

Version Description

  • Fixed issue with Admin Menu restrictions (thanks to MikeB2B)
  • Added Polish Translation
  • Fixed issue with Widgets restriction
  • Improved internal User & Role handling
  • Implemented caching mechanism
  • Extended Update mechanism (remove the AAM cache after update)
  • Added New ConfigPress setting aam.caching (by default is FALSE)
  • Improved Metabox & Widgets filtering mechanism
  • Added French Translation (by Moskito7)
  • Added "My Feature" Tab
  • Regenerated .pot file
Download this release

Release Info

Developer vasyl_m
Plugin Icon 128x128 Advanced Access Manager
Version 2.1
Comparing to
See all releases

Code changes from version 2.0 to 2.1

Files changed (161) hide show
  1. aam.php +41 -57
  2. application/control/object.php +22 -0
  3. application/control/object/backup.php +7 -0
  4. application/control/object/capability.php +7 -0
  5. application/control/object/configpress.php +19 -7
  6. application/control/object/event.php +7 -0
  7. application/control/object/menu.php +13 -3
  8. application/control/object/metabox.php +1 -1
  9. application/control/object/post.php +26 -1
  10. application/control/object/term.php +18 -6
  11. application/control/subject.php +122 -13
  12. application/control/subject/role.php +41 -1
  13. application/control/subject/user.php +1 -1
  14. application/control/subject/visitor.php +46 -15
  15. application/core/migrate.php +9 -8
  16. application/core/update.php +79 -15
  17. application/view/ajax.php +1 -1
  18. application/view/event.php +2 -1
  19. application/view/manager.php +4 -1
  20. application/view/post.php +4 -1
  21. application/view/tmpl/menu.phtml +1 -1
  22. config.php +5 -2
  23. extension/AAM_Multisite_Support/extension.php +2 -2
  24. extension/AAM_My_Feature/extension.php +133 -0
  25. extension/AAM_My_Feature/images/message-active.png +0 -0
  26. extension/AAM_My_Feature/images/message.png +0 -0
  27. extension/AAM_My_Feature/images/talk-active.png +0 -0
  28. extension/AAM_My_Feature/images/talk.png +0 -0
  29. extension/AAM_My_Feature/images/worker.png +0 -0
  30. extension/AAM_My_Feature/index.php +14 -0
  31. extension/AAM_My_Feature/my_feature.css +66 -0
  32. extension/AAM_My_Feature/my_feature.js +20 -0
  33. extension/AAM_My_Feature/ui.phtml +23 -0
  34. lang/aam-fr_FR.mo +0 -0
  35. lang/aam-fr_FR.po +337 -0
  36. lang/aam-pl_PL.mo +0 -0
  37. lang/aam-pl_PL.po +336 -0
  38. lang/aam.pot +105 -55
  39. media/css/images/capability/add-active.png +0 -0
  40. media/css/images/capability/add.png +0 -0
  41. media/css/images/capability/checked.png +0 -0
  42. media/css/images/capability/copy-active.png +0 -0
  43. media/css/images/capability/copy.png +0 -0
  44. media/css/images/capability/delete-active.png +0 -0
  45. media/css/images/capability/delete.png +0 -0
  46. media/css/images/capability/filter-active.png +0 -0
  47. media/css/images/capability/filter.png +0 -0
  48. media/css/images/capability/restore-active.png +0 -0
  49. media/css/images/capability/restore.png +0 -0
  50. media/css/images/capability/select-active.png +0 -0
  51. media/css/images/capability/select.png +0 -0
  52. media/css/images/capability/unchecked.png +0 -0
  53. media/css/images/cmanager/add-active.png +0 -0
  54. media/css/images/cmanager/add.png +0 -0
  55. media/css/images/cmanager/block-user-active.png +0 -0
  56. media/css/images/cmanager/block-user.png +0 -0
  57. media/css/images/cmanager/delete-active.png +0 -0
  58. media/css/images/cmanager/delete.png +0 -0
  59. media/css/images/cmanager/edit-active.png +0 -0
  60. media/css/images/cmanager/edit-user-active.png +0 -0
  61. media/css/images/cmanager/edit-user.png +0 -0
  62. media/css/images/cmanager/edit.png +0 -0
  63. media/css/images/cmanager/filter-active.png +0 -0
  64. media/css/images/cmanager/filter.png +0 -0
  65. media/css/images/cmanager/multisite-active.png +0 -0
  66. media/css/images/cmanager/multisite.png +0 -0
  67. media/css/images/cmanager/refresh-active.png +0 -0
  68. media/css/images/cmanager/refresh.png +0 -0
  69. media/css/images/cmanager/role-active.png +0 -0
  70. media/css/images/cmanager/role.png +0 -0
  71. media/css/images/cmanager/select-active.png +0 -0
  72. media/css/images/cmanager/select.png +0 -0
  73. media/css/images/cmanager/settings-active.png +0 -0
  74. media/css/images/cmanager/settings.png +0 -0
  75. media/css/images/cmanager/user-active.png +0 -0
  76. media/css/images/cmanager/user.png +0 -0
  77. media/css/images/cmanager/visitor-active.png +0 -0
  78. media/css/images/cmanager/visitor.png +0 -0
  79. media/css/images/configpress/pdf-active.png +0 -0
  80. media/css/images/configpress/pdf.png +0 -0
  81. media/css/images/cpanel/help-forum-active.png +0 -0
  82. media/css/images/cpanel/help-forum.png +0 -0
  83. media/css/images/cpanel/message-active.png +0 -0
  84. media/css/images/cpanel/message.png +0 -0
  85. media/css/images/cpanel/restore-active.png +0 -0
  86. media/css/images/cpanel/restore.png +0 -0
  87. media/css/images/cpanel/save-active.png +0 -0
  88. media/css/images/cpanel/save.png +0 -0
  89. media/css/images/cpanel/star-active.png +0 -0
  90. media/css/images/cpanel/star.png +0 -0
  91. media/css/images/cpanel/twitter-active.png +0 -0
  92. media/css/images/cpanel/twitter.png +0 -0
  93. media/css/images/event/add-active.png +0 -0
  94. media/css/images/event/add.png +0 -0
  95. media/css/images/event/delete-active.png +0 -0
  96. media/css/images/event/delete.png +0 -0
  97. media/css/images/event/edit-active.png +0 -0
  98. media/css/images/event/edit.png +0 -0
  99. media/css/images/extension/download-active.png +0 -0
  100. media/css/images/extension/download.png +0 -0
  101. media/css/images/extension/forum-active.png +0 -0
  102. media/css/images/extension/forum.png +0 -0
  103. media/css/images/extension/link-active.png +0 -0
  104. media/css/images/extension/link.png +0 -0
  105. media/css/images/extension/message-active.png +0 -0
  106. media/css/images/extension/message.png +0 -0
  107. media/css/images/extension/ok-active.png +0 -0
  108. media/css/images/extension/ok.png +0 -0
  109. media/css/images/extension/plus-active.png +0 -0
  110. media/css/images/extension/plus.png +0 -0
  111. media/css/images/extension/purchase-active.png +0 -0
  112. media/css/images/extension/purchase.png +0 -0
  113. media/css/images/extension/twitter-active.png +0 -0
  114. media/css/images/extension/twitter.png +0 -0
  115. media/css/images/extension/youtube-active.png +0 -0
  116. media/css/images/extension/youtube.png +0 -0
  117. media/css/images/feature-active.png +0 -0
  118. media/css/images/lock.png +0 -0
  119. media/css/images/menu/checked.png +0 -0
  120. media/css/images/menu/sorting-active.png +0 -0
  121. media/css/images/menu/sorting.png +0 -0
  122. media/css/images/menu/unchecked.png +0 -0
  123. media/css/images/menu/visibility-active.png +0 -0
  124. media/css/images/menu/visibility.png +0 -0
  125. media/css/images/metabox/add-active.png +0 -0
  126. media/css/images/metabox/add.png +0 -0
  127. media/css/images/metabox/checked.png +0 -0
  128. media/css/images/metabox/link-active.png +0 -0
  129. media/css/images/metabox/link.png +0 -0
  130. media/css/images/metabox/refresh-active.png +0 -0
  131. media/css/images/metabox/refresh.png +0 -0
  132. media/css/images/metabox/unchecked.png +0 -0
  133. media/css/images/post/checked.png +0 -0
  134. media/css/images/post/edit-active.png +0 -0
  135. media/css/images/post/edit.png +0 -0
  136. media/css/images/post/filter-active.png +0 -0
  137. media/css/images/post/filter.png +0 -0
  138. media/css/images/post/info-active.png +0 -0
  139. media/css/images/post/info.png +0 -0
  140. media/css/images/post/lock-big.png +0 -0
  141. media/css/images/post/lock.png +0 -0
  142. media/css/images/post/post.png +0 -0
  143. media/css/images/post/refresh-active.png +0 -0
  144. media/css/images/post/refresh.png +0 -0
  145. media/css/images/post/settings-active.png +0 -0
  146. media/css/images/post/settings.png +0 -0
  147. media/css/images/post/unchecked.png +0 -0
  148. media/css/images/search-active.png +0 -0
  149. media/css/images/search.png +0 -0
  150. media/css/images/sort_asc.png +0 -0
  151. media/css/images/sort_asc_disabled.png +0 -0
  152. media/css/images/sort_both.png +0 -0
  153. media/css/images/sort_desc.png +0 -0
  154. media/css/images/sort_desc_disabled.png +0 -0
  155. media/css/images/table-filtered.png +0 -0
  156. media/css/images/ui-icons_222222_256x240.png +0 -0
  157. media/css/images/ui-icons_454545_256x240.png +0 -0
  158. media/css/images/ui-icons_888888_256x240.png +0 -0
  159. media/js/aam.js +2 -2
  160. media/js/codemirror.js +1 -5829
  161. readme.txt +17 -2
aam.php CHANGED
@@ -1,9 +1,8 @@
1
  <?php
2
-
3
  /**
4
  Plugin Name: Advanced Access Manager
5
  Description: Manage User and Role Access to WordPress Backend and Frontend.
6
- Version: 2.0
7
  Author: Vasyl Martyniuk <support@wpaam.com>
8
  Author URI: http://www.wpaam.com
9
 
@@ -80,13 +79,7 @@ class aam {
80
  //manager AAM Ajax Requests
81
  add_action('wp_ajax_aam', array($this, 'ajax'));
82
  //manager WordPress metaboxes
83
- //add_action("do_meta_boxes", array($this, 'metaboxes'), 1, 3);
84
  add_action("in_admin_header", array($this, 'metaboxes'), 999);
85
- //add_action("add_meta_boxes", array($this, 'filterMetaboxes'), 999, 2);
86
- //add_filter(
87
- // 'get_user_option_meta-box-order_dashboard',
88
- // array($this, 'dashboardFilter'), 999, 3
89
- //);
90
  //manager user search and authentication control
91
  add_filter('user_search_columns', array($this, 'searchColumns'));
92
  //terms & post restriction handlers
@@ -117,6 +110,9 @@ class aam {
117
 
118
  //load extensions only when admin
119
  $this->loadExtensions();
 
 
 
120
  }
121
 
122
  /**
@@ -127,7 +123,7 @@ class aam {
127
  * @access public
128
  */
129
  public function checkUpdate() {
130
- if (class_exists('aam_Core_Update') && (AAM_APPL_ENV != 'development')) {
131
  $update = new aam_Core_Update($this);
132
  $update->run();
133
  }
@@ -219,10 +215,11 @@ class aam {
219
  */
220
  public function getTerms($area, $terms) {
221
  if (is_array($terms)) {
222
- $object = $this->getUser()->getObject(aam_Control_Object_Term::UID);
223
  foreach ($terms as $i => $term) {
224
  if (is_object($term)) {
225
- $object->init($term->term_id);
 
 
226
  if ($object->has($area, aam_Control_Object_Term::ACTION_LIST)) {
227
  unset($terms[$i]);
228
  }
@@ -244,10 +241,12 @@ class aam {
244
  * @todo Cache this process
245
  */
246
  public function getPages($pages){
247
- $object = $this->getUser()->getObject(aam_Control_Object_Post::UID);
248
  if (is_array($pages)){
249
  foreach($pages as $i => $page){
250
- $object->init($page);
 
 
251
  if ($object->has('frontend', aam_Control_Object_Post::ACTION_EXCLUDE)){
252
  unset($pages[$i]);
253
  }
@@ -268,17 +267,18 @@ class aam {
268
  */
269
  public function getNavigationMenu($pages){
270
  if (is_array($pages)){
271
- $post = $this->getUser()->getObject(aam_Control_Object_Post::UID);
272
- $term = $this->getUser()->getObject(aam_Control_Object_Term::UID);
273
  foreach($pages as $i => $page){
274
  if ($page->type === 'taxonomy'){
275
- $object = $term;
 
 
276
  $exclude = aam_Control_Object_Term::ACTION_EXCLUDE;
277
  } else {
278
- $object = $post;
 
 
279
  $exclude = aam_Control_Object_Post::ACTION_EXCLUDE;
280
  }
281
- $object->init($page->object_id);
282
 
283
  if ($object->has('frontend', $exclude)){
284
  unset($pages[$i]);
@@ -782,10 +782,10 @@ class aam {
782
  */
783
  public function ajax() {
784
  check_ajax_referer('aam_ajax');
785
-
786
  //clean buffer to make sure that nothing messing around with system
787
  while (@ob_end_clean());
788
-
789
  //process ajax request
790
  $model = new aam_View_Ajax;
791
  echo $model->run();
@@ -802,51 +802,24 @@ class aam {
802
  public function metaboxes() {
803
  global $post;
804
 
805
- $post_type = ($post instanceof WP_Post ? $post->post_type : '');
 
 
 
 
 
 
 
806
 
807
  if (aam_Core_Request::get('aam_meta_init')) {
808
  $model = new aam_View_Metabox;
809
- $model->run($post_type);
810
  } else {
811
  $this->getUser()->getObject(aam_Control_Object_Metabox::UID)
812
- ->filterBackend($post_type, 'dashboard');
813
  }
814
  }
815
 
816
- /**
817
- * Filter Dashboard Widgets & Metaboxes
818
- *
819
- * @param array $result
820
- * @param mixed $option
821
- * @param mixed $user
822
- *
823
- * @return void
824
- *
825
- * @access public
826
- * @deprecated since 2.0 Beta 3
827
- */
828
- public function dashboardFilter($result, $option, $user) {
829
- $this->getUser()->getObject(
830
- aam_Control_Object_Metabox::UID)->filterBackend('dashboard');
831
- }
832
-
833
- /**
834
- * Filter Screen Metaboxes
835
- *
836
- * @param string $post_type
837
- * @param WP_Post $post
838
- *
839
- * @return void
840
- *
841
- * @access public
842
- * @deprecated since 2.0 Beta 3
843
- */
844
- public function filterMetaboxes($post_type, $post) {
845
- $this->getUser()->getObject(aam_Control_Object_Metabox::UID)->filterBackend(
846
- $post_type, $post
847
- );
848
- }
849
-
850
  /**
851
  * Register Admin Menu
852
  *
@@ -983,6 +956,17 @@ class aam {
983
  $this->_user = $user;
984
  }
985
 
 
 
 
 
 
 
 
 
 
 
 
986
  /**
987
  * Load Installed extensions
988
  *
1
  <?php
 
2
  /**
3
  Plugin Name: Advanced Access Manager
4
  Description: Manage User and Role Access to WordPress Backend and Frontend.
5
+ Version: 2.1
6
  Author: Vasyl Martyniuk <support@wpaam.com>
7
  Author URI: http://www.wpaam.com
8
 
79
  //manager AAM Ajax Requests
80
  add_action('wp_ajax_aam', array($this, 'ajax'));
81
  //manager WordPress metaboxes
 
82
  add_action("in_admin_header", array($this, 'metaboxes'), 999);
 
 
 
 
 
83
  //manager user search and authentication control
84
  add_filter('user_search_columns', array($this, 'searchColumns'));
85
  //terms & post restriction handlers
110
 
111
  //load extensions only when admin
112
  $this->loadExtensions();
113
+
114
+ //add shutdown action
115
+ add_action('shutdown', array($this, 'shutdown'), 1);
116
  }
117
 
118
  /**
123
  * @access public
124
  */
125
  public function checkUpdate() {
126
+ if (aam_Core_API::getBlogOption('aam_updated', '', 1) != AAM_VERSION) {
127
  $update = new aam_Core_Update($this);
128
  $update->run();
129
  }
215
  */
216
  public function getTerms($area, $terms) {
217
  if (is_array($terms)) {
 
218
  foreach ($terms as $i => $term) {
219
  if (is_object($term)) {
220
+ $object = $this->getUser()->getObject(
221
+ aam_Control_Object_Term::UID, $term->term_id
222
+ );
223
  if ($object->has($area, aam_Control_Object_Term::ACTION_LIST)) {
224
  unset($terms[$i]);
225
  }
241
  * @todo Cache this process
242
  */
243
  public function getPages($pages){
244
+
245
  if (is_array($pages)){
246
  foreach($pages as $i => $page){
247
+ $object = $this->getUser()->getObject(
248
+ aam_Control_Object_Post::UID, $page->ID
249
+ );
250
  if ($object->has('frontend', aam_Control_Object_Post::ACTION_EXCLUDE)){
251
  unset($pages[$i]);
252
  }
267
  */
268
  public function getNavigationMenu($pages){
269
  if (is_array($pages)){
 
 
270
  foreach($pages as $i => $page){
271
  if ($page->type === 'taxonomy'){
272
+ $object = $this->getUser()->getObject(
273
+ aam_Control_Object_Term::UID, $page->object_id
274
+ );
275
  $exclude = aam_Control_Object_Term::ACTION_EXCLUDE;
276
  } else {
277
+ $object = $this->getUser()->getObject(
278
+ aam_Control_Object_Post::UID, $page->object_id
279
+ );
280
  $exclude = aam_Control_Object_Post::ACTION_EXCLUDE;
281
  }
 
282
 
283
  if ($object->has('frontend', $exclude)){
284
  unset($pages[$i]);
782
  */
783
  public function ajax() {
784
  check_ajax_referer('aam_ajax');
785
+
786
  //clean buffer to make sure that nothing messing around with system
787
  while (@ob_end_clean());
788
+
789
  //process ajax request
790
  $model = new aam_View_Ajax;
791
  echo $model->run();
802
  public function metaboxes() {
803
  global $post;
804
 
805
+ //make sure that nobody is playing with screen options
806
+ if ($post instanceof WP_Post){
807
+ $screen = $post->post_type;
808
+ } elseif($screen_object = get_current_screen()) {
809
+ $screen = $screen_object->id;
810
+ } else {
811
+ $screen = '';
812
+ }
813
 
814
  if (aam_Core_Request::get('aam_meta_init')) {
815
  $model = new aam_View_Metabox;
816
+ $model->run($screen);
817
  } else {
818
  $this->getUser()->getObject(aam_Control_Object_Metabox::UID)
819
+ ->filterBackend($screen);
820
  }
821
  }
822
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
  /**
824
  * Register Admin Menu
825
  *
956
  $this->_user = $user;
957
  }
958
 
959
+ /**
960
+ * Execute before shutdown actions
961
+ *
962
+ * @return void
963
+ *
964
+ * @access public
965
+ */
966
+ public function shutdown(){
967
+ $this->getUser()->saveCache();
968
+ }
969
+
970
  /**
971
  * Load Installed extensions
972
  *
application/control/object.php CHANGED
@@ -43,6 +43,28 @@ abstract class aam_Control_Object {
43
  $this->init($object_id);
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /**
47
  * Initialize object
48
  *
43
  $this->init($object_id);
44
  }
45
 
46
+ /**
47
+ * Sleep method
48
+ *
49
+ * Used for caching mechanism
50
+ *
51
+ * @return array
52
+ *
53
+ * @access public
54
+ */
55
+ public function __sleep(){
56
+ return array('_option');
57
+ }
58
+
59
+ /**
60
+ * Indicate either object can be cached on not
61
+ *
62
+ * @return boolean
63
+ *
64
+ * @access public
65
+ */
66
+ abstract public function cacheObject();
67
+
68
  /**
69
  * Initialize object
70
  *
application/control/object/backup.php CHANGED
@@ -67,6 +67,13 @@ class aam_Control_Object_Backup extends aam_Control_Object {
67
  return self::UID;
68
  }
69
 
 
 
 
 
 
 
 
70
  /**
71
  *
72
  * @param type $option
67
  return self::UID;
68
  }
69
 
70
+ /**
71
+ * @inheritdoc
72
+ */
73
+ public function cacheObject(){
74
+ return false;
75
+ }
76
+
77
  /**
78
  *
79
  * @param type $option
application/control/object/capability.php CHANGED
@@ -42,6 +42,13 @@ class aam_Control_Object_Capability extends aam_Control_Object {
42
  }
43
  }
44
 
 
 
 
 
 
 
 
45
  /**
46
  *
47
  * @param type $object_id
42
  }
43
  }
44
 
45
+ /**
46
+ * @inheritdoc
47
+ */
48
+ public function cacheObject(){
49
+ return false;
50
+ }
51
+
52
  /**
53
  *
54
  * @param type $object_id
application/control/object/configpress.php CHANGED
@@ -38,6 +38,20 @@ class aam_Control_Object_ConfigPress extends aam_Control_Object {
38
  */
39
  private $_tree = null;
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /**
42
  *
43
  * @param type $config_press
@@ -74,13 +88,11 @@ class aam_Control_Object_ConfigPress extends aam_Control_Object {
74
  * @param type $object_id
75
  */
76
  public function init($object_id) {
77
- if (empty($this->_option)) {
78
- $filename = aam_Core_API::getBlogOption('aam_' . self::UID, '');
79
- if ($filename && file_exists(AAM_TEMP_DIR . $filename)) {
80
- $this->setOption($filename);
81
- $this->setConfig(file_get_contents(AAM_TEMP_DIR . $filename));
82
- $this->parseConfig(AAM_TEMP_DIR . $filename);
83
- }
84
  }
85
  }
86
 
38
  */
39
  private $_tree = null;
40
 
41
+ /**
42
+ * @inheritdoc
43
+ */
44
+ public function __sleep(){
45
+ return array('_option', '_config', '_tree');
46
+ }
47
+
48
+ /**
49
+ * @inheritdoc
50
+ */
51
+ public function cacheObject(){
52
+ return false;
53
+ }
54
+
55
  /**
56
  *
57
  * @param type $config_press
88
  * @param type $object_id
89
  */
90
  public function init($object_id) {
91
+ $filename = aam_Core_API::getBlogOption('aam_' . self::UID, '');
92
+ if ($filename && file_exists(AAM_TEMP_DIR . $filename)) {
93
+ $this->setOption($filename);
94
+ $this->setConfig(file_get_contents(AAM_TEMP_DIR . $filename));
95
+ $this->parseConfig(AAM_TEMP_DIR . $filename);
 
 
96
  }
97
  }
98
 
application/control/object/event.php CHANGED
@@ -36,6 +36,13 @@ class aam_Control_Object_Event extends aam_Control_Object {
36
  }
37
  }
38
 
 
 
 
 
 
 
 
39
  /**
40
  *
41
  * @return type
36
  }
37
  }
38
 
39
+ /**
40
+ * @inheritdoc
41
+ */
42
+ public function cacheObject(){
43
+ return true;
44
+ }
45
+
46
  /**
47
  *
48
  * @return type
application/control/object/menu.php CHANGED
@@ -114,6 +114,13 @@ class aam_Control_Object_Menu extends aam_Control_Object {
114
  }
115
  }
116
 
 
 
 
 
 
 
 
117
  /**
118
  *
119
  * @return type
@@ -153,11 +160,14 @@ class aam_Control_Object_Menu extends aam_Control_Object {
153
  */
154
  public function has($menu) {
155
  $response = false;
156
- if (isset($this->_option[$menu])) {
157
- $response = (intval($this->_option[$menu]) ? true : false);
 
 
 
158
  }
159
 
160
  return $response;
161
  }
162
 
163
- }
114
  }
115
  }
116
 
117
+ /**
118
+ * @inheritdoc
119
+ */
120
+ public function cacheObject(){
121
+ return true;
122
+ }
123
+
124
  /**
125
  *
126
  * @return type
160
  */
161
  public function has($menu) {
162
  $response = false;
163
+ //decode URL in case of any special characters like &amp;
164
+ $menu_decoded = htmlspecialchars_decode($menu);
165
+ //check if menu is restricted
166
+ if (isset($this->_option[$menu_decoded])) {
167
+ $response = (intval($this->_option[$menu_decoded]) ? true : false);
168
  }
169
 
170
  return $response;
171
  }
172
 
173
+ }
application/control/object/metabox.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  * ======================================================================
3
  * LICENSE: This file is subject to the terms and conditions defined in *
4
  * file 'license.txt', which is part of this source code package. *
5
  * ======================================================================
6
  */
7
  *
8
  * @package AAM
9
  * @author Vasyl Martyniuk <support@wpaam.com>
10
  * @copyright Copyright C 2013 Vasyl Martyniuk
11
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
12
  */
13
  /**
14
  *
15
  */
16
  const UID = 'metabox';
17
  /**
18
  *
19
  * @var type
20
  */
21
  private $_option = array();
22
  /**
23
  *
24
  * @global type $wp_registered_widgets
25
  * @param type $sidebar_widgets
26
  * @return type
27
  */
28
  public function filterFrontend($sidebar_widgets) {
29
  global $wp_registered_widgets;
30
  if (is_array($wp_registered_widgets)) {
31
  foreach ($wp_registered_widgets as $id => $data) {
32
  if (is_object($data['callback'][0])) {
33
  $callback = get_class($data['callback'][0]);
34
  } elseif (is_string($data['callback'][0])) {
35
  $callback = $data['callback'][0];
36
  }
37
  if ($this->has('widgets', $callback)) {
38
  unregister_widget($callback);
39
  //remove it from registered widget global var!!
40
  //INFORM: Why Unregister Widget does not clear global var?
41
  unset($wp_registered_widgets[$id]);
42
  }
43
  }
44
  }
45
  return $sidebar_widgets;
46
  }
47
  /**
48
  *
49
  * @global type $wp_meta_boxes
50
  * @param type $screen
51
  * @param type $post
52
  */
53
  public function filterBackend($screen, $post = null) {
54
  global $wp_meta_boxes;
55
  if (is_array($wp_meta_boxes)) {
56
  foreach ($wp_meta_boxes as $screen_id => $zones) {
57
  if ($screen == $screen_id) {
58
  foreach ($zones as $zone => $priorities) {
59
  foreach ($priorities as $priority => $metaboxes) {
60
  foreach ($metaboxes as $metabox => $data) {
61
  if ($this->has($screen_id, $metabox)) {
62
  remove_meta_box($metabox, $screen_id, $zone);
63
  }
64
  }
65
  }
66
  }
67
  }
68
  }
69
  }
70
  }
71
  /**
72
  *
73
  * @param type $metaboxes
74
  */
75
  public function save($metaboxes = null) {
76
  if (is_array($metaboxes)) {
77
  $this->getSubject()->updateOption($metaboxes, self::UID);
78
  }
79
  }
80
  /**
81
  *
82
  * @return type
83
  */
84
  public function backup() {
85
  return $this->getSubject()->readOption(self::UID, '', array());
86
  }
87
  /**
88
  *
89
  * @return type
90
  */
91
  public function getUID() {
92
  return self::UID;
93
  }
94
  /**
95
  *
96
  * @param type $option
97
  */
98
  public function setOption($option) {
99
  $this->_option = (is_array($option) ? $option : array());
100
  }
101
  /**
102
  *
103
  * @return type
104
  */
105
  public function getOption() {
106
  return $this->_option;
107
  }
108
  /**
109
  *
110
  * @param type $group
111
  * @param type $metabox
112
  * @return type
113
  */
114
  public function has($group, $metabox) {
115
  $response = false;
116
  if (isset($this->_option[$group][$metabox])) {
117
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
118
  }
119
  return $response;
120
  }
 
121
  * ======================================================================
122
  * LICENSE: This file is subject to the terms and conditions defined in *
123
  * file 'license.txt', which is part of this source code package. *
124
  * ======================================================================
125
  */
126
  *
127
  * @package AAM
128
  * @author Vasyl Martyniuk <support@wpaam.com>
129
  * @copyright Copyright C 2013 Vasyl Martyniuk
130
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
131
  */
132
  /**
133
  *
134
  */
135
  const UID = 'metabox';
136
  /**
137
  *
138
  * @var type
139
  */
140
  private $_option = array();
141
  /**
142
  *
143
  * @global type $wp_registered_widgets
144
  * @param type $sidebar_widgets
145
  * @return type
146
  */
147
  public function filterFrontend($sidebar_widgets) {
148
  global $wp_registered_widgets;
149
  if (is_array($wp_registered_widgets)) {
150
  foreach ($wp_registered_widgets as $id => $data) {
151
  if (is_object($data['callback'][0])) {
152
  $callback = get_class($data['callback'][0]);
153
  } elseif (is_string($data['callback'][0])) {
154
  $callback = $data['callback'][0];
155
  }
156
  if ($this->has('widgets', $callback)) {
157
  unregister_widget($callback);
158
  //remove it from registered widget global var!!
159
  //INFORM: Why Unregister Widget does not clear global var?
160
  unset($wp_registered_widgets[$id]);
161
  }
162
  }
163
  }
164
  return $sidebar_widgets;
165
  }
166
  /**
167
  *
168
  * @global type $wp_meta_boxes
169
  * @param type $screen
170
  * @param type $post
171
  */
172
  public function filterBackend($screen, $post = null) {
173
  global $wp_meta_boxes;
174
  if (is_array($wp_meta_boxes)) {
175
  foreach ($wp_meta_boxes as $screen_id => $zones) {
176
  if ($screen == $screen_id) {
177
  foreach ($zones as $zone => $priorities) {
178
  foreach ($priorities as $priority => $metaboxes) {
179
  foreach ($metaboxes as $metabox => $data) {
180
  if ($this->has($screen_id, $metabox)) {
181
  remove_meta_box($metabox, $screen_id, $zone);
182
  }
183
  }
184
  }
185
  }
186
  }
187
  }
188
  }
189
  }
190
  /**
191
  *
192
  * @param type $metaboxes
193
  */
194
  public function save($metaboxes = null) {
195
  if (is_array($metaboxes)) {
196
  $this->getSubject()->updateOption($metaboxes, self::UID);
197
  }
198
  }
199
  /**
200
  * @inheritdoc
201
  */
202
  public function cacheObject(){
203
  return true;
204
  }
205
  /**
206
  *
207
  * @return type
208
  */
209
  public function backup() {
210
  return $this->getSubject()->readOption(self::UID, '', array());
211
  }
212
  /**
213
  *
214
  * @return type
215
  */
216
  public function getUID() {
217
  return self::UID;
218
  }
219
  /**
220
  *
221
  * @param type $option
222
  */
223
  public function setOption($option) {
224
  $this->_option = (is_array($option) ? $option : array());
225
  }
226
  /**
227
  *
228
  * @return type
229
  */
230
  public function getOption() {
231
  return $this->_option;
232
  }
233
  /**
234
  *
235
  * @param type $group
236
  * @param type $metabox
237
  * @return type
238
  */
239
  public function has($group, $metabox) {
240
  $response = false;
241
  if (isset($this->_option[$group][$metabox])) {
242
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
243
  }
244
  return $response;
245
  }
 
1
  * ======================================================================
2
  * LICENSE: This file is subject to the terms and conditions defined in *
3
  * file 'license.txt', which is part of this source code package. *
4
  * ======================================================================
5
  */
6
  *
7
  * @package AAM
8
  * @author Vasyl Martyniuk <support@wpaam.com>
9
  * @copyright Copyright C 2013 Vasyl Martyniuk
10
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
11
  */
12
  /**
13
  *
14
  */
15
  const UID = 'metabox';
16
  /**
17
  *
18
  * @var type
19
  */
20
  private $_option = array();
21
  /**
22
  *
23
  * @global type $wp_registered_widgets
24
  * @param type $sidebar_widgets
25
  * @return type
26
  */
27
  public function filterFrontend($sidebar_widgets) {
28
  global $wp_registered_widgets;
29
  if (is_array($wp_registered_widgets)) {
30
  foreach ($wp_registered_widgets as $id => $data) {
31
  if (is_object($data['callback'][0])) {
32
  $callback = get_class($data['callback'][0]);
33
  } elseif (is_string($data['callback'][0])) {
34
  $callback = $data['callback'][0];
35
  }
36
  if ($this->has('widgets', $callback)) {
37
  unregister_widget($callback);
38
  //remove it from registered widget global var!!
39
  //INFORM: Why Unregister Widget does not clear global var?
40
  unset($wp_registered_widgets[$id]);
41
  }
42
  }
43
  }
44
  return $sidebar_widgets;
45
  }
46
  /**
47
  *
48
  * @global type $wp_meta_boxes
49
  * @param type $screen
50
  * @param type $post
51
  */
52
  public function filterBackend($screen, $post = null) {
53
  global $wp_meta_boxes;
54
  if (is_array($wp_meta_boxes)) {
55
  foreach ($wp_meta_boxes as $screen_id => $zones) {
56
  if ($screen == $screen_id) {
57
  foreach ($zones as $zone => $priorities) {
58
  foreach ($priorities as $priority => $metaboxes) {
59
  foreach ($metaboxes as $metabox => $data) {
60
  if ($this->has($screen_id, $metabox)) {
61
  remove_meta_box($metabox, $screen_id, $zone);
62
  }
63
  }
64
  }
65
  }
66
  }
67
  }
68
  }
69
  }
70
  /**
71
  *
72
  * @param type $metaboxes
73
  */
74
  public function save($metaboxes = null) {
75
  if (is_array($metaboxes)) {
76
  $this->getSubject()->updateOption($metaboxes, self::UID);
77
  }
78
  }
79
  /**
80
  *
81
  * @return type
82
  */
83
  public function backup() {
84
  return $this->getSubject()->readOption(self::UID, '', array());
85
  }
86
  /**
87
  *
88
  * @return type
89
  */
90
  public function getUID() {
91
  return self::UID;
92
  }
93
  /**
94
  *
95
  * @param type $option
96
  */
97
  public function setOption($option) {
98
  $this->_option = (is_array($option) ? $option : array());
99
  }
100
  /**
101
  *
102
  * @return type
103
  */
104
  public function getOption() {
105
  return $this->_option;
106
  }
107
  /**
108
  *
109
  * @param type $group
110
  * @param type $metabox
111
  * @return type
112
  */
113
  public function has($group, $metabox) {
114
  $response = false;
115
  if (isset($this->_option[$group][$metabox])) {
116
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
117
  }
118
  return $response;
119
  }
120
+ <?php
121
  * ======================================================================
122
  * LICENSE: This file is subject to the terms and conditions defined in *
123
  * file 'license.txt', which is part of this source code package. *
124
  * ======================================================================
125
  */
126
  *
127
  * @package AAM
128
  * @author Vasyl Martyniuk <support@wpaam.com>
129
  * @copyright Copyright C 2013 Vasyl Martyniuk
130
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
131
  */
132
  /**
133
  *
134
  */
135
  const UID = 'metabox';
136
  /**
137
  *
138
  * @var type
139
  */
140
  private $_option = array();
141
  /**
142
  *
143
  * @global type $wp_registered_widgets
144
  * @param type $sidebar_widgets
145
  * @return type
146
  */
147
  public function filterFrontend($sidebar_widgets) {
148
  global $wp_registered_widgets;
149
  if (is_array($wp_registered_widgets)) {
150
  foreach ($wp_registered_widgets as $id => $data) {
151
  if (is_object($data['callback'][0])) {
152
  $callback = get_class($data['callback'][0]);
153
  } elseif (is_string($data['callback'][0])) {
154
  $callback = $data['callback'][0];
155
  }
156
  if ($this->has('widgets', $callback)) {
157
  unregister_widget($callback);
158
  //remove it from registered widget global var!!
159
  //INFORM: Why Unregister Widget does not clear global var?
160
  unset($wp_registered_widgets[$id]);
161
  }
162
  }
163
  }
164
  return $sidebar_widgets;
165
  }
166
  /**
167
  *
168
  * @global type $wp_meta_boxes
169
  * @param type $screen
170
  * @param type $post
171
  */
172
  public function filterBackend($screen, $post = null) {
173
  global $wp_meta_boxes;
174
  if (is_array($wp_meta_boxes)) {
175
  foreach ($wp_meta_boxes as $screen_id => $zones) {
176
  if ($screen == $screen_id) {
177
  foreach ($zones as $zone => $priorities) {
178
  foreach ($priorities as $priority => $metaboxes) {
179
  foreach ($metaboxes as $metabox => $data) {
180
  if ($this->has($screen_id, $metabox)) {
181
  remove_meta_box($metabox, $screen_id, $zone);
182
  }
183
  }
184
  }
185
  }
186
  }
187
  }
188
  }
189
  }
190
  /**
191
  *
192
  * @param type $metaboxes
193
  */
194
  public function save($metaboxes = null) {
195
  if (is_array($metaboxes)) {
196
  $this->getSubject()->updateOption($metaboxes, self::UID);
197
  }
198
  }
199
  /**
200
  * @inheritdoc
201
  */
202
  public function cacheObject(){
203
  return true;
204
  }
205
  /**
206
  *
207
  * @return type
208
  */
209
  public function backup() {
210
  return $this->getSubject()->readOption(self::UID, '', array());
211
  }
212
  /**
213
  *
214
  * @return type
215
  */
216
  public function getUID() {
217
  return self::UID;
218
  }
219
  /**
220
  *
221
  * @param type $option
222
  */
223
  public function setOption($option) {
224
  $this->_option = (is_array($option) ? $option : array());
225
  }
226
  /**
227
  *
228
  * @return type
229
  */
230
  public function getOption() {
231
  return $this->_option;
232
  }
233
  /**
234
  *
235
  * @param type $group
236
  * @param type $metabox
237
  * @return type
238
  */
239
  public function has($group, $metabox) {
240
  $response = false;
241
  if (isset($this->_option[$group][$metabox])) {
242
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
243
  }
244
  return $response;
245
  }
application/control/object/post.php CHANGED
@@ -62,6 +62,20 @@ class aam_Control_Object_Post extends aam_Control_Object {
62
  */
63
  private $_option = array();
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  *
67
  * @param type $params
@@ -115,8 +129,13 @@ class aam_Control_Object_Post extends aam_Control_Object {
115
  }
116
 
117
  /**
 
118
  *
119
- * @param type $object
 
 
 
 
120
  */
121
  public function init($object) {
122
  //make sure that we are dealing with WP_Post object
@@ -132,7 +151,13 @@ class aam_Control_Object_Post extends aam_Control_Object {
132
  }
133
 
134
  /**
 
135
  *
 
 
 
 
 
136
  */
137
  public function read() {
138
  $option = get_post_meta($this->getPost()->ID, $this->getOptionName(), true);
62
  */
63
  private $_option = array();
64
 
65
+ /**
66
+ * @inheritdoc
67
+ */
68
+ public function __sleep(){
69
+ return array('_post', '_option');
70
+ }
71
+
72
+ /**
73
+ * @inheritdoc
74
+ */
75
+ public function cacheObject(){
76
+ return true;
77
+ }
78
+
79
  /**
80
  *
81
  * @param type $params
129
  }
130
 
131
  /**
132
+ * Init Post Object
133
  *
134
+ * @param WP_Post|Int $object
135
+ *
136
+ * @return void
137
+ *
138
+ * @access public
139
  */
140
  public function init($object) {
141
  //make sure that we are dealing with WP_Post object
151
  }
152
 
153
  /**
154
+ * Read the Post AAM Metadata
155
  *
156
+ * Get all settings related to specified post
157
+ *
158
+ * @return void
159
+ *
160
+ * @access public
161
  */
162
  public function read() {
163
  $option = get_post_meta($this->getPost()->ID, $this->getOptionName(), true);
application/control/object/term.php CHANGED
@@ -25,9 +25,9 @@ class aam_Control_Object_Term extends aam_Control_Object {
25
  *
26
  */
27
  const ACTION_BROWSE = 'browse';
28
-
29
  /**
30
- *
31
  */
32
  const ACTION_EXCLUDE = 'exclude';
33
 
@@ -35,9 +35,9 @@ class aam_Control_Object_Term extends aam_Control_Object {
35
  *
36
  */
37
  const ACTION_EDIT = 'edit';
38
-
39
  /**
40
- *
41
  */
42
  const ACTION_LIST = 'list';
43
 
@@ -53,6 +53,13 @@ class aam_Control_Object_Term extends aam_Control_Object {
53
  */
54
  private $_option = array();
55
 
 
 
 
 
 
 
 
56
  /**
57
  *
58
  * @param type $params
@@ -114,8 +121,6 @@ class aam_Control_Object_Term extends aam_Control_Object {
114
  $this->setOption(
115
  apply_filters('aam_term_access_option', $access, $this->getSubject())
116
  );
117
- } else {
118
- aam_Core_Console::write("Term {$object_id} does not exist");
119
  }
120
  }
121
  }
@@ -198,6 +203,13 @@ class aam_Control_Object_Term extends aam_Control_Object {
198
  return $this->_option;
199
  }
200
 
 
 
 
 
 
 
 
201
  /**
202
  *
203
  * @param type $area
25
  *
26
  */
27
  const ACTION_BROWSE = 'browse';
28
+
29
  /**
30
+ *
31
  */
32
  const ACTION_EXCLUDE = 'exclude';
33
 
35
  *
36
  */
37
  const ACTION_EDIT = 'edit';
38
+
39
  /**
40
+ *
41
  */
42
  const ACTION_LIST = 'list';
43
 
53
  */
54
  private $_option = array();
55
 
56
+ /**
57
+ * @inheritdoc
58
+ */
59
+ public function __sleep(){
60
+ return array('_term', '_option');
61
+ }
62
+
63
  /**
64
  *
65
  * @param type $params
121
  $this->setOption(
122
  apply_filters('aam_term_access_option', $access, $this->getSubject())
123
  );
 
 
124
  }
125
  }
126
  }
203
  return $this->_option;
204
  }
205
 
206
+ /**
207
+ * @inheritdoc
208
+ */
209
+ public function cacheObject(){
210
+ return true;
211
+ }
212
+
213
  /**
214
  *
215
  * @param type $area
application/control/subject.php CHANGED
@@ -28,7 +28,7 @@ abstract class aam_Control_Subject {
28
  private $_id;
29
 
30
  /**
31
- * Subject itself
32
  *
33
  * It can be WP_User or WP_Role, based on what class has been used
34
  *
@@ -49,6 +49,17 @@ abstract class aam_Control_Subject {
49
  */
50
  private $_objects = array();
51
 
 
 
 
 
 
 
 
 
 
 
 
52
  /**
53
  * Constructor
54
  *
@@ -63,6 +74,44 @@ abstract class aam_Control_Subject {
63
  $this->setId($id);
64
  //retrieve and set subject itself
65
  $this->setSubject($this->retrieveSubject());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
  /**
@@ -166,6 +215,19 @@ abstract class aam_Control_Subject {
166
  $this->_subject = $subject;
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * Get Access Objects
171
  *
@@ -188,23 +250,36 @@ abstract class aam_Control_Subject {
188
  * @access public
189
  */
190
  public function getObject($object, $object_id = 0) {
191
- if (!isset($this->_objects[$object])) {
 
 
 
 
 
192
  $class_name = 'aam_Control_Object_' . ucfirst($object);
193
  if (class_exists($class_name)) {
194
- $this->_objects[$object] = new $class_name($this, $object_id);
 
 
195
  } else {
196
- $this->_objects[$object] = apply_filters(
197
- 'aam_object', null, $this, $object_id
198
  );
199
  }
200
- }
201
 
202
- //make sure that object exists, otherwise log it
203
- if (is_null($this->_objects[$object])) {
204
- aam_Core_Console::write("Object {$object} does not exist");
 
 
 
 
 
 
 
205
  }
206
 
207
- return $this->_objects[$object];
208
  }
209
 
210
  /**
@@ -250,6 +325,37 @@ abstract class aam_Control_Subject {
250
  */
251
  abstract public function getCapabilities();
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  /**
254
  * Save Access Parameters
255
  *
@@ -263,10 +369,10 @@ abstract class aam_Control_Subject {
263
  //initialize the backup first
264
  $backup = array();
265
 
266
- foreach ($params as $object_id => $dump) {
267
- if ($object = $this->getObject($object_id)) {
268
  if (method_exists($object, 'backup')) {
269
- $backup[$object_id] = $object->backup();
270
  }
271
  $object->save($dump);
272
  }
@@ -274,6 +380,9 @@ abstract class aam_Control_Subject {
274
 
275
  //store backup
276
  $this->getObject(aam_Control_Object_Backup::UID)->save($backup);
 
 
 
277
  }
278
 
279
  /**
28
  private $_id;
29
 
30
  /**
31
+ * WordPres Subject
32
  *
33
  * It can be WP_User or WP_Role, based on what class has been used
34
  *
49
  */
50
  private $_objects = array();
51
 
52
+ /**
53
+ * Update Cache flag
54
+ *
55
+ * If there is any new object instantiated, update cache too
56
+ *
57
+ * @var boolean
58
+ *
59
+ * @access private
60
+ */
61
+ private $_updateCache = false;
62
+
63
  /**
64
  * Constructor
65
  *
74
  $this->setId($id);
75
  //retrieve and set subject itself
76
  $this->setSubject($this->retrieveSubject());
77
+ //retrieve cache if there is any
78
+ $this->initCache();
79
+ }
80
+
81
+ /**
82
+ * Initialize cache
83
+ *
84
+ * @return void
85
+ *
86
+ * @access public
87
+ */
88
+ public function initCache(){
89
+ $cpress = $this->getObject(aam_Control_Object_ConfigPress::UID);
90
+ if ($cpress->getParam('aam.caching', 'false') === "true"){
91
+ $this->setObjects($this->readCache());
92
+ foreach($this->_objects as $objects){
93
+ foreach($objects as $object){
94
+ $object->setSubject($this);
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Desctruct the subject
102
+ *
103
+ * Execute extra actions during application shutdown
104
+ *
105
+ * @return void
106
+ *
107
+ * @access public
108
+ */
109
+ public function saveCache(){
110
+ $cpress = $this->getObject(aam_Control_Object_ConfigPress::UID);
111
+ if (($this->_updateCache === true)
112
+ && ($cpress->getParam('aam.caching', 'false') === "true")){
113
+ $this->updateCache();
114
+ }
115
  }
116
 
117
  /**
215
  $this->_subject = $subject;
216
  }
217
 
218
+ /**
219
+ * Set Objects
220
+ *
221
+ * If there is any cache, set the complete set of objects
222
+ *
223
+ * @return void
224
+ *
225
+ * @access public
226
+ */
227
+ public function setObjects($objects) {
228
+ $this->_objects = $objects;
229
+ }
230
+
231
  /**
232
  * Get Access Objects
233
  *
250
  * @access public
251
  */
252
  public function getObject($object, $object_id = 0) {
253
+ //make sure that object group is defined
254
+ if (!isset($this->_objects[$object])){
255
+ $this->_objects[$object] = array();
256
+ }
257
+ //check if there is an object with specified ID
258
+ if (!isset($this->_objects[$object][$object_id])) {
259
  $class_name = 'aam_Control_Object_' . ucfirst($object);
260
  if (class_exists($class_name)) {
261
+ $this->_objects[$object][$object_id] = new $class_name(
262
+ $this, $object_id
263
+ );
264
  } else {
265
+ $this->_objects[$object][$object_id] = apply_filters(
266
+ 'aam_object', $this, $object, $object_id
267
  );
268
  }
 
269
 
270
+ //optimize the memory. make sure that the number of objects is not longer
271
+ //than 50, othewise remove first one (most likely it is not used)
272
+ if (count($this->_objects[$object]) > 50){
273
+ array_shift($this->_objects[$object]); //remove the first
274
+ }
275
+
276
+ //set update cache flag to true if object can be cached
277
+ if ($this->_objects[$object][$object_id]->cacheObject() === true){
278
+ $this->_updateCache = true;
279
+ }
280
  }
281
 
282
+ return $this->_objects[$object][$object_id];
283
  }
284
 
285
  /**
325
  */
326
  abstract public function getCapabilities();
327
 
328
+ /**
329
+ * Read Cache
330
+ *
331
+ * Cache all settings to speed-up the AAM execution
332
+ *
333
+ * @return void
334
+ *
335
+ * @access public
336
+ */
337
+ abstract public function readCache();
338
+
339
+ /**
340
+ * Update Cache
341
+ *
342
+ * If there is any change to cache, update it and save to database
343
+ *
344
+ * @return boolean
345
+ *
346
+ * @access public
347
+ */
348
+ abstract public function updateCache();
349
+
350
+ /**
351
+ * Clear the Subject Cache
352
+ *
353
+ * @return boolean
354
+ *
355
+ * @access public
356
+ */
357
+ abstract public function clearCache();
358
+
359
  /**
360
  * Save Access Parameters
361
  *
369
  //initialize the backup first
370
  $backup = array();
371
 
372
+ foreach ($params as $object_type => $dump) {
373
+ if ($object = $this->getObject($object_type)) {
374
  if (method_exists($object, 'backup')) {
375
+ $backup[$object_type] = $object->backup();
376
  }
377
  $object->save($dump);
378
  }
380
 
381
  //store backup
382
  $this->getObject(aam_Control_Object_Backup::UID)->save($backup);
383
+
384
+ //clear cache
385
+ $this->clearCache();
386
  }
387
 
388
  /**
application/control/subject/role.php CHANGED
@@ -111,7 +111,7 @@ class aam_Control_Subject_Role extends aam_Control_Subject {
111
  public function removeCapability($capability) {
112
  return $this->getSubject()->remove_cap($capability);
113
  }
114
-
115
  /**
116
  * Check if Subject has capability
117
  *
@@ -194,4 +194,44 @@ class aam_Control_Subject_Role extends aam_Control_Subject {
194
  return self::UID;
195
  }
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  }
111
  public function removeCapability($capability) {
112
  return $this->getSubject()->remove_cap($capability);
113
  }
114
+
115
  /**
116
  * Check if Subject has capability
117
  *
194
  return self::UID;
195
  }
196
 
197
+ /**
198
+ * Get Role Cache
199
+ *
200
+ * AAM does not store individual Role cache that is why this function returns
201
+ * always empty array
202
+ *
203
+ * @return array
204
+ *
205
+ * @access public
206
+ */
207
+ public function readCache(){
208
+ return array();
209
+ }
210
+
211
+ /**
212
+ * Update Role Cache
213
+ *
214
+ * This function does nothing because AAM does not store Role's cache
215
+ *
216
+ * @return boolean
217
+ *
218
+ * @access public
219
+ */
220
+ public function updateCache(){
221
+ return true;
222
+ }
223
+
224
+ /**
225
+ * Clear Role Cache
226
+ *
227
+ * This function does nothing because AAM does not store Role's cache
228
+ *
229
+ * @return boolean
230
+ *
231
+ * @access public
232
+ */
233
+ public function clearCache(){
234
+ return true;
235
+ }
236
+
237
  }
application/control/subject/user.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  * ======================================================================
3
  * LICENSE: This file is subject to the terms and conditions defined in *
4
  * file 'license.txt', which is part of this source code package. *
5
  * ======================================================================
6
  */
7
  *
8
  * @package AAM
9
  * @author Vasyl Martyniuk <support@wpaam.com>
10
  * @copyright Copyright C 2013 Vasyl Martyniuk
11
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
12
  */
13
  /**
14
  * Subject UID: USER
15
  */
16
  const UID = 'user';
17
 
18
  /**
19
  * AAM Capability Key
20
  *
21
  * WordPress does not allow to have different set of capabilities for one user
22
  * between sites. aam_capability key stores the set of capabilities stored after
23
  * individual user edit and merge them with system capabilities.
24
  * The merging process overwrites allcaps.
25
  *
26
  * @var array
27
  *
28
  * @access private
29
  */
30
  private $_cap_key = '';
31
  /**
32
  *
33
  * @param type $id
34
  */
35
  public function __construct($id) {
36
  parent::__construct($id);
37
 
38
  //initialize list of capabilities
39
  //$this->getObject(aam_Control_Object_Capability::UID);
40
 
41
  //overwrite default set of capabilities if AAM capset is defined
42
  if ($this->isDefaultCapSet() === false){
43
  //make sure that aam_capability is actually array
44
  if (is_array($this->getSubject()->aam_caps)){
45
  $allcaps = array_merge(
46
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
47
  );
48
  $this->getSubject()->allcaps = $allcaps;
49
  }
50
  }
51
  }
52
  /**
53
  *
54
  * @return type
55
  */
56
  public function delete() {
57
  $response = false;
58
  if (current_user_can('delete_users')
59
  && ($this->getId() !== get_current_user_id())) {
60
  $response = wp_delete_user($this->getId());
61
  }
62
  return $response;
63
  }
64
  /**
65
  *
66
  * @global type $wpdb
67
  * @return boolean
68
  */
69
  public function block() {
70
  global $wpdb;
71
  $response = false;
72
  if (current_user_can('edit_users')
73
  && ($this->getId() != get_current_user_id())) {
74
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
75
  if ($wpdb->update(
76
  $wpdb->users,
77
  array('user_status' => $status),
78
  array('ID' => $this->getId())
79
  )) {
80
  $this->getSubject()->user_status = $status;
81
  clean_user_cache($this->getSubject());
82
  $response = true;
83
  }
84
  }
85
  return $response;
86
  }
87
  /**
88
  * Retrieve User based on ID
89
  *
90
  * @return WP_Role|null
91
  *
92
  * @access protected
93
  */
94
  protected function retrieveSubject() {
95
  global $current_user;
96
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
97
  $subject = $current_user;
98
  } else {
99
  $subject = new WP_User($this->getId());
100
  }
101
 
102
  //retrieve aam capabilities
103
  $this->_cap_key = 'aam_capability';
104
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
105
 
106
  return $subject;
107
  }
108
 
109
  /**
110
  * Check if user has default capability set
111
  *
112
  * @return boolean
113
  *
114
  * @access public
115
  */
116
  public function isDefaultCapSet(){
117
  return empty($this->getSubject()->aam_caps);
118
  }
119
  /**
120
  *
121
  * @return type
122
  */
123
  public function getCapabilities() {
124
  return $this->getSubject()->allcaps;
125
  }
126
  /**
127
  *
128
  * @param type $capability
129
  * @return type
130
  */
131
  public function hasCapability($capability) {
132
  return user_can($this->getSubject(), $capability);
133
  }
134
 
135
  /**
136
  * Check if Subject has capability
137
  *
138
  * Keep compatible with WordPress core
139
  *
140
  * @param string $capability
141
  *
142
  * @return boolean
143
  *
144
  * @access public
145
  */
146
  public function addCapability($capability) {
147
  return $this->updateCapability($capability, true);
148
  }
149
  /**
150
  * Remove Capability
151
  *
152
  * @param string $capability
153
  *
154
  * @return boolean
155
  *
156
  * @access public
157
  */
158
  public function removeCapability($capability) {
159
  return $this->updateCapability($capability, false);
160
  }
161
 
162
  /**
163
  * Reset User Capability
164
  *
165
  * @return array
166
  *
167
  * @access public
168
  */
169
  public function resetCapability(){
170
  return delete_user_option($this->getId(), $this->_cap_key);
171
  }
172
 
173
  /**
174
  * Update User's Capability Set
175
  *
176
  * @param string $capability
177
  * @param boolean $grand
178
  *
179
  * @return boolean
180
  *
181
  * @access public
182
  */
183
  public function updateCapability($capability, $grand){
184
  //make sure that we have right array
185
  if (is_array($this->getSubject()->aam_caps)){
186
  $aam_caps = $this->getSubject()->aam_caps;
187
  } else {
188
  $aam_caps = array();
189
  }
190
 
191
  //add capability
192
  $aam_caps[$capability] = $grand;
193
  //update user data. TODO - Keep eyes on this part
194
  $this->getSubject()->data->aam_caps = $aam_caps;
195
  //save and return the result of operation
196
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
197
  }
198
  /**
199
  *
200
  * @param type $value
201
  * @param type $object
202
  * @param type $object_id
203
  * @return type
204
  */
205
  public function updateOption($value, $object, $object_id = '') {
206
  return update_user_option(
207
  $this->getId(), $this->getOptionName($object, $object_id), $value
208
  );
209
  }
210
  /**
211
  *
212
  * @param type $object
213
  * @param type $object_id
214
  * @return type
215
  */
216
  public function readOption($object, $object_id = '') {
217
  $option = get_user_option(
218
  $this->getOptionName($object, $object_id), $this->getId()
219
  );
220
  if (empty($option)) {
221
  //try to get this option from the User's Role
222
  $roles = $this->getSubject()->roles;
223
  //first user role is counted only. AAM does not support multi-roles
224
  $subject_role = array_shift($roles);
225
  //in case of multisite & current user does not belong to the site
226
  if ($subject_role){
227
  $role = new aam_Control_Subject_Role($subject_role);
228
  $option = $role->getObject($object, $object_id)->getOption();
229
  }
230
  }
231
  return $option;
232
  }
233
  /**
234
  *
235
  * @param type $object
236
  * @param type $object_id
237
  * @return type
238
  */
239
  public function deleteOption($object, $object_id = '') {
240
  return delete_user_option(
241
  $this->getId(), $this->getOptionName($object, $object_id)
242
  );
243
  }
244
  /**
245
  *
246
  * @param type $object
247
  * @param type $object_id
248
  * @return type
249
  */
250
  protected function getOptionName($object, $object_id) {
251
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
252
  }
253
  /**
254
  *
255
  * @return type
256
  */
257
  public function getUID() {
258
  return self::UID;
259
  }
 
260
  * ======================================================================
261
  * LICENSE: This file is subject to the terms and conditions defined in *
262
  * file 'license.txt', which is part of this source code package. *
263
  * ======================================================================
264
  */
265
  *
266
  * @package AAM
267
  * @author Vasyl Martyniuk <support@wpaam.com>
268
  * @copyright Copyright C 2013 Vasyl Martyniuk
269
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
270
  */
271
  /**
272
  * Subject UID: USER
273
  */
274
  const UID = 'user';
275
  /**
276
  * AAM Capability Key
277
  *
278
  * WordPress does not allow to have different set of capabilities for one user
279
  * between sites. aam_capability key stores the set of capabilities stored after
280
  * individual user edit and merge them with system capabilities.
281
  * The merging process overwrites allcaps.
282
  *
283
  * @var array
284
  *
285
  * @access private
286
  */
287
  private $_cap_key = '';
288
  /**
289
  *
290
  * @param type $id
291
  */
292
  public function __construct($id) {
293
  parent::__construct($id);
294
  //overwrite default set of capabilities if AAM capset is defined
295
  if ($this->isDefaultCapSet() === false){
296
  //make sure that aam_capability is actually array
297
  if (is_array($this->getSubject()->aam_caps)){
298
  $allcaps = array_merge(
299
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
300
  );
301
  $this->getSubject()->allcaps = $allcaps;
302
  }
303
  }
304
  }
305
  /**
306
  *
307
  * @return type
308
  */
309
  public function delete() {
310
  $response = false;
311
  if (current_user_can('delete_users')
312
  && ($this->getId() !== get_current_user_id())) {
313
  $response = wp_delete_user($this->getId());
314
  }
315
  return $response;
316
  }
317
  /**
318
  *
319
  * @global type $wpdb
320
  * @return boolean
321
  */
322
  public function block() {
323
  global $wpdb;
324
  $response = false;
325
  if (current_user_can('edit_users')
326
  && ($this->getId() != get_current_user_id())) {
327
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
328
  if ($wpdb->update(
329
  $wpdb->users,
330
  array('user_status' => $status),
331
  array('ID' => $this->getId())
332
  )) {
333
  $this->getSubject()->user_status = $status;
334
  clean_user_cache($this->getSubject());
335
  $response = true;
336
  }
337
  }
338
  return $response;
339
  }
340
  /**
341
  * Retrieve User based on ID
342
  *
343
  * @return WP_Role|null
344
  *
345
  * @access protected
346
  */
347
  protected function retrieveSubject() {
348
  global $current_user;
349
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
350
  $subject = $current_user;
351
  } else {
352
  $subject = new WP_User($this->getId());
353
  }
354
  //retrieve aam capabilities if are not retrieved yet
355
  $this->_cap_key = 'aam_capability';
356
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
357
  return $subject;
358
  }
359
  /**
360
  * Check if user has default capability set
361
  *
362
  * @return boolean
363
  *
364
  * @access public
365
  */
366
  public function isDefaultCapSet(){
367
  return empty($this->getSubject()->aam_caps);
368
  }
369
  /**
370
  *
371
  * @return type
372
  */
373
  public function getCapabilities() {
374
  return $this->getSubject()->allcaps;
375
  }
376
  /**
377
  *
378
  * @param type $capability
379
  * @return type
380
  */
381
  public function hasCapability($capability) {
382
  return user_can($this->getSubject(), $capability);
383
  }
384
  /**
385
  * Check if Subject has capability
386
  *
387
  * Keep compatible with WordPress core
388
  *
389
  * @param string $capability
390
  *
391
  * @return boolean
392
  *
393
  * @access public
394
  */
395
  public function addCapability($capability) {
396
  return $this->updateCapability($capability, true);
397
  }
398
  /**
399
  * Remove Capability
400
  *
401
  * @param string $capability
402
  *
403
  * @return boolean
404
  *
405
  * @access public
406
  */
407
  public function removeCapability($capability) {
408
  return $this->updateCapability($capability, false);
409
  }
410
  /**
411
  * Reset User Capability
412
  *
413
  * @return array
414
  *
415
  * @access public
416
  */
417
  public function resetCapability(){
418
  return delete_user_option($this->getId(), $this->_cap_key);
419
  }
420
  /**
421
  * Update User's Capability Set
422
  *
423
  * @param string $capability
424
  * @param boolean $grand
425
  *
426
  * @return boolean
427
  *
428
  * @access public
429
  */
430
  public function updateCapability($capability, $grand){
431
  //make sure that we have right array
432
  if (is_array($this->getSubject()->aam_caps)){
433
  $aam_caps = $this->getSubject()->aam_caps;
434
  } else {
435
  $aam_caps = array();
436
  }
437
  //add capability
438
  $aam_caps[$capability] = $grand;
439
  //update user data. TODO - Keep eyes on this part
440
  $this->getSubject()->data->aam_caps = $aam_caps;
441
  //save and return the result of operation
442
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
443
  }
444
  /**
445
  *
446
  * @param type $value
447
  * @param type $object
448
  * @param type $object_id
449
  * @return type
450
  */
451
  public function updateOption($value, $object, $object_id = '') {
452
  return update_user_option(
453
  $this->getId(), $this->getOptionName($object, $object_id), $value
454
  );
455
  }
456
  /**
457
  *
458
  * @param type $object
459
  * @param type $object_id
460
  * @return type
461
  */
462
  public function readOption($object, $object_id = '') {
463
  $option = get_user_option(
464
  $this->getOptionName($object, $object_id), $this->getId()
465
  );
466
  if (empty($option)) {
467
  //try to get this option from the User's Role
468
  $roles = $this->getSubject()->roles;
469
  //first user role is counted only. AAM does not support multi-roles
470
  $subject_role = array_shift($roles);
471
  //in case of multisite & current user does not belong to the site
472
  if ($subject_role){
473
  $role = new aam_Control_Subject_Role($subject_role);
474
  $option = $role->getObject($object, $object_id)->getOption();
475
  }
476
  }
477
  return $option;
478
  }
479
  /**
480
  *
481
  * @param type $object
482
  * @param type $object_id
483
  * @return type
484
  */
485
  public function deleteOption($object, $object_id = '') {
486
  return delete_user_option(
487
  $this->getId(), $this->getOptionName($object, $object_id)
488
  );
489
  }
490
  /**
491
  *
492
  * @param type $object
493
  * @param type $object_id
494
  * @return type
495
  */
496
  protected function getOptionName($object, $object_id) {
497
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
498
  }
499
  /**
500
  * Get Subject UID
501
  *
502
  * @return string
503
  *
504
  * @access public
505
  */
506
  public function getUID() {
507
  return self::UID;
508
  }
509
  /**
510
  * Get User's Cache
511
  *
512
  * Read User's option aam_cache and return it
513
  *
514
  * @return array
515
  *
516
  * @access public
517
  */
518
  public function readCache(){
519
  $cache = get_user_option('aam_cache', $this->getId());
520
  return (is_array($cache) ? $cache : array());
521
  }
522
  /**
523
  * Insert or Update User's Cache
524
  *
525
  * @return boolean
526
  *
527
  * @access public
528
  */
529
  public function updateCache(){
530
  return update_user_option($this->getId(), 'aam_cache', $this->getObjects());
531
  }
532
  /**
533
  * Delete User's Cache
534
  *
535
  * @return boolean
536
  *
537
  * @access public
538
  */
539
  public function clearCache(){
540
  return delete_user_option($this->getId(), 'aam_cache');
541
  }
 
1
  * ======================================================================
2
  * LICENSE: This file is subject to the terms and conditions defined in *
3
  * file 'license.txt', which is part of this source code package. *
4
  * ======================================================================
5
  */
6
  *
7
  * @package AAM
8
  * @author Vasyl Martyniuk <support@wpaam.com>
9
  * @copyright Copyright C 2013 Vasyl Martyniuk
10
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
11
  */
12
  /**
13
  * Subject UID: USER
14
  */
15
  const UID = 'user';
16
 
17
  /**
18
  * AAM Capability Key
19
  *
20
  * WordPress does not allow to have different set of capabilities for one user
21
  * between sites. aam_capability key stores the set of capabilities stored after
22
  * individual user edit and merge them with system capabilities.
23
  * The merging process overwrites allcaps.
24
  *
25
  * @var array
26
  *
27
  * @access private
28
  */
29
  private $_cap_key = '';
30
  /**
31
  *
32
  * @param type $id
33
  */
34
  public function __construct($id) {
35
  parent::__construct($id);
36
 
37
  //initialize list of capabilities
38
  //$this->getObject(aam_Control_Object_Capability::UID);
39
 
40
  //overwrite default set of capabilities if AAM capset is defined
41
  if ($this->isDefaultCapSet() === false){
42
  //make sure that aam_capability is actually array
43
  if (is_array($this->getSubject()->aam_caps)){
44
  $allcaps = array_merge(
45
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
46
  );
47
  $this->getSubject()->allcaps = $allcaps;
48
  }
49
  }
50
  }
51
  /**
52
  *
53
  * @return type
54
  */
55
  public function delete() {
56
  $response = false;
57
  if (current_user_can('delete_users')
58
  && ($this->getId() !== get_current_user_id())) {
59
  $response = wp_delete_user($this->getId());
60
  }
61
  return $response;
62
  }
63
  /**
64
  *
65
  * @global type $wpdb
66
  * @return boolean
67
  */
68
  public function block() {
69
  global $wpdb;
70
  $response = false;
71
  if (current_user_can('edit_users')
72
  && ($this->getId() != get_current_user_id())) {
73
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
74
  if ($wpdb->update(
75
  $wpdb->users,
76
  array('user_status' => $status),
77
  array('ID' => $this->getId())
78
  )) {
79
  $this->getSubject()->user_status = $status;
80
  clean_user_cache($this->getSubject());
81
  $response = true;
82
  }
83
  }
84
  return $response;
85
  }
86
  /**
87
  * Retrieve User based on ID
88
  *
89
  * @return WP_Role|null
90
  *
91
  * @access protected
92
  */
93
  protected function retrieveSubject() {
94
  global $current_user;
95
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
96
  $subject = $current_user;
97
  } else {
98
  $subject = new WP_User($this->getId());
99
  }
100
 
101
  //retrieve aam capabilities
102
  $this->_cap_key = 'aam_capability';
103
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
104
 
105
  return $subject;
106
  }
107
 
108
  /**
109
  * Check if user has default capability set
110
  *
111
  * @return boolean
112
  *
113
  * @access public
114
  */
115
  public function isDefaultCapSet(){
116
  return empty($this->getSubject()->aam_caps);
117
  }
118
  /**
119
  *
120
  * @return type
121
  */
122
  public function getCapabilities() {
123
  return $this->getSubject()->allcaps;
124
  }
125
  /**
126
  *
127
  * @param type $capability
128
  * @return type
129
  */
130
  public function hasCapability($capability) {
131
  return user_can($this->getSubject(), $capability);
132
  }
133
 
134
  /**
135
  * Check if Subject has capability
136
  *
137
  * Keep compatible with WordPress core
138
  *
139
  * @param string $capability
140
  *
141
  * @return boolean
142
  *
143
  * @access public
144
  */
145
  public function addCapability($capability) {
146
  return $this->updateCapability($capability, true);
147
  }
148
  /**
149
  * Remove Capability
150
  *
151
  * @param string $capability
152
  *
153
  * @return boolean
154
  *
155
  * @access public
156
  */
157
  public function removeCapability($capability) {
158
  return $this->updateCapability($capability, false);
159
  }
160
 
161
  /**
162
  * Reset User Capability
163
  *
164
  * @return array
165
  *
166
  * @access public
167
  */
168
  public function resetCapability(){
169
  return delete_user_option($this->getId(), $this->_cap_key);
170
  }
171
 
172
  /**
173
  * Update User's Capability Set
174
  *
175
  * @param string $capability
176
  * @param boolean $grand
177
  *
178
  * @return boolean
179
  *
180
  * @access public
181
  */
182
  public function updateCapability($capability, $grand){
183
  //make sure that we have right array
184
  if (is_array($this->getSubject()->aam_caps)){
185
  $aam_caps = $this->getSubject()->aam_caps;
186
  } else {
187
  $aam_caps = array();
188
  }
189
 
190
  //add capability
191
  $aam_caps[$capability] = $grand;
192
  //update user data. TODO - Keep eyes on this part
193
  $this->getSubject()->data->aam_caps = $aam_caps;
194
  //save and return the result of operation
195
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
196
  }
197
  /**
198
  *
199
  * @param type $value
200
  * @param type $object
201
  * @param type $object_id
202
  * @return type
203
  */
204
  public function updateOption($value, $object, $object_id = '') {
205
  return update_user_option(
206
  $this->getId(), $this->getOptionName($object, $object_id), $value
207
  );
208
  }
209
  /**
210
  *
211
  * @param type $object
212
  * @param type $object_id
213
  * @return type
214
  */
215
  public function readOption($object, $object_id = '') {
216
  $option = get_user_option(
217
  $this->getOptionName($object, $object_id), $this->getId()
218
  );
219
  if (empty($option)) {
220
  //try to get this option from the User's Role
221
  $roles = $this->getSubject()->roles;
222
  //first user role is counted only. AAM does not support multi-roles
223
  $subject_role = array_shift($roles);
224
  //in case of multisite & current user does not belong to the site
225
  if ($subject_role){
226
  $role = new aam_Control_Subject_Role($subject_role);
227
  $option = $role->getObject($object, $object_id)->getOption();
228
  }
229
  }
230
  return $option;
231
  }
232
  /**
233
  *
234
  * @param type $object
235
  * @param type $object_id
236
  * @return type
237
  */
238
  public function deleteOption($object, $object_id = '') {
239
  return delete_user_option(
240
  $this->getId(), $this->getOptionName($object, $object_id)
241
  );
242
  }
243
  /**
244
  *
245
  * @param type $object
246
  * @param type $object_id
247
  * @return type
248
  */
249
  protected function getOptionName($object, $object_id) {
250
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
251
  }
252
  /**
253
  *
254
  * @return type
255
  */
256
  public function getUID() {
257
  return self::UID;
258
  }
259
+ <?php
260
  * ======================================================================
261
  * LICENSE: This file is subject to the terms and conditions defined in *
262
  * file 'license.txt', which is part of this source code package. *
263
  * ======================================================================
264
  */
265
  *
266
  * @package AAM
267
  * @author Vasyl Martyniuk <support@wpaam.com>
268
  * @copyright Copyright C 2013 Vasyl Martyniuk
269
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
270
  */
271
  /**
272
  * Subject UID: USER
273
  */
274
  const UID = 'user';
275
  /**
276
  * AAM Capability Key
277
  *
278
  * WordPress does not allow to have different set of capabilities for one user
279
  * between sites. aam_capability key stores the set of capabilities stored after
280
  * individual user edit and merge them with system capabilities.
281
  * The merging process overwrites allcaps.
282
  *
283
  * @var array
284
  *
285
  * @access private
286
  */
287
  private $_cap_key = '';
288
  /**
289
  *
290
  * @param type $id
291
  */
292
  public function __construct($id) {
293
  parent::__construct($id);
294
  //overwrite default set of capabilities if AAM capset is defined
295
  if ($this->isDefaultCapSet() === false){
296
  //make sure that aam_capability is actually array
297
  if (is_array($this->getSubject()->aam_caps)){
298
  $allcaps = array_merge(
299
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
300
  );
301
  $this->getSubject()->allcaps = $allcaps;
302
  }
303
  }
304
  }
305
  /**
306
  *
307
  * @return type
308
  */
309
  public function delete() {
310
  $response = false;
311
  if (current_user_can('delete_users')
312
  && ($this->getId() !== get_current_user_id())) {
313
  $response = wp_delete_user($this->getId());
314
  }
315
  return $response;
316
  }
317
  /**
318
  *
319
  * @global type $wpdb
320
  * @return boolean
321
  */
322
  public function block() {
323
  global $wpdb;
324
  $response = false;
325
  if (current_user_can('edit_users')
326
  && ($this->getId() != get_current_user_id())) {
327
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
328
  if ($wpdb->update(
329
  $wpdb->users,