8
8
9
9
defined ('ABSPATH ' ) || exit;
10
10
11
+ /**
12
+ * @deprecated
13
+ */
11
14
final class RUA_App
12
15
{
13
16
/**
@@ -24,7 +27,7 @@ final class RUA_App
24
27
/**
25
28
* Post Type for restriction
26
29
*/
27
- const TYPE_RESTRICT = ' restriction ' ;
30
+ const TYPE_RESTRICT = \ RestrictUserAccess \ Level \PostType:: NAME ;
28
31
29
32
/**
30
33
* Post type statuses
@@ -73,9 +76,6 @@ final class RUA_App
73
76
*/
74
77
public $ level_manager ;
75
78
76
- /** @var RUA_Member_Automator[]|RUA_Collection<RUA_Member_Automator> */
77
- private $ level_automators ;
78
-
79
79
public function __construct ()
80
80
{
81
81
$ this ->level_manager = new RUA_Level_Manager ();
@@ -114,10 +114,6 @@ public function __construct()
114
114
'edit_user_profile_update ' ,
115
115
[$ this ,'save_user_profile ' ]
116
116
);
117
- add_action (
118
- 'delete_post ' ,
119
- [$ this ,'sync_level_deletion ' ]
120
- );
121
117
add_action (
122
118
'delete_user ' ,
123
119
[$ this , 'sync_user_deletion ' ],
@@ -149,11 +145,8 @@ public function __construct()
149
145
);
150
146
} else {
151
147
new RUA_Admin_Bar ();
152
- new RUA_Content_Mode ();
153
148
}
154
149
155
- new RUA_Query_Filters ();
156
-
157
150
add_action ('wpca/loaded ' , [$ this , 'ensure_wpca_loaded ' ]);
158
151
159
152
add_shortcode (
@@ -165,17 +158,10 @@ public function __construct()
165
158
'cas/user_visibility ' ,
166
159
[$ this ,'sidebars_check_levels ' ]
167
160
);
168
-
169
- add_filter (
170
- 'rest_authentication_errors ' ,
171
- [$ this , 'rest_api_access ' ]
172
- );
173
161
}
174
162
175
163
public function ensure_wpca_loaded ()
176
164
{
177
- $ this ->process_level_automators ();
178
-
179
165
//hook early, other plugins might add dynamic caps later
180
166
//fixes problem with WooCommerce Orders
181
167
//todo: verify if this is still an issue, now that we run in wpca/loaded
@@ -518,45 +504,6 @@ public function get_levels()
518
504
return $ this ->levels ;
519
505
}
520
506
521
- /**
522
- * Delete foreign metadata belonging to level
523
- *
524
- * @since 0.11.1
525
- * @param int $post_id
526
- * @return void
527
- */
528
- public function sync_level_deletion ($ post_id )
529
- {
530
- $ post = get_post ($ post_id );
531
-
532
- if (!$ post || $ post ->post_type != RUA_App::TYPE_RESTRICT ) {
533
- return ;
534
- }
535
-
536
- global $ wpdb ;
537
-
538
- //Delete user levels
539
- $ wpdb ->query ($ wpdb ->prepare (
540
- "DELETE FROM $ wpdb ->usermeta
541
- WHERE
542
- (meta_key = %s AND meta_value = %d)
543
- OR
544
- meta_key = %s " ,
545
- self ::META_PREFIX . 'level ' ,
546
- $ post_id ,
547
- self ::META_PREFIX . 'level_ ' . $ post_id
548
- ));
549
-
550
- //Delete nav menu item levels
551
- $ wpdb ->query ($ wpdb ->prepare (
552
- "DELETE FROM $ wpdb ->postmeta
553
- WHERE
554
- meta_key = %s AND meta_value = %d " ,
555
- '_menu_item_level ' ,
556
- $ post_id
557
- ));
558
- }
559
-
560
507
public function sync_user_deletion ($ id , $ reassign , $ user )
561
508
{
562
509
global $ wpdb ;
@@ -634,142 +581,11 @@ public function load_admin_scripts($hook)
634
581
}
635
582
636
583
/**
637
- * @return RUA_Collection|RUA_Member_Automator []
584
+ * @return RUA_Collection|\RestrictUserAccess\Membership\Automator\AbstractAutomator []
638
585
*/
639
586
public function get_level_automators ()
640
587
{
641
- if ($ this ->level_automators === null ) {
642
- $ automators = [
643
- new RUA_Role_Member_Automator (),
644
- new RUA_Role_Sync_Member_Automator (),
645
- new RUA_LoggedIn_Member_Automator (),
646
- new RUA_BP_Member_Type_Member_Automator (),
647
- new RUA_EDD_Product_Member_Automator (),
648
- new RUA_WooProduct_Member_Automator (),
649
- new RUA_GiveWP_Donation_Member_Automator ()
650
- ];
651
-
652
- $ this ->level_automators = new RUA_Collection ();
653
- /** @var RUA_Member_Automator $automator */
654
- foreach ($ automators as $ automator ) {
655
- if ($ automator ->can_enable ()) {
656
- $ this ->level_automators ->put ($ automator ->get_name (), $ automator );
657
- if (is_admin ()) {
658
- add_action (
659
- 'wp_ajax_rua/automator/ ' . $ automator ->get_name (),
660
- [$ automator ,'ajax_print_content ' ]
661
- );
662
- }
663
- }
664
- }
665
- }
666
- return $ this ->level_automators ;
667
- }
668
-
669
- public function process_level_automators ()
670
- {
671
- $ metadata = $ this ->level_manager ->metadata ();
672
- $ levels = $ this ->get_levels ();
673
- $ automators = $ this ->get_level_automators ();
674
-
675
- foreach ($ levels as $ level ) {
676
- if ($ level ->post_status != RUA_App::STATUS_ACTIVE ) {
677
- continue ;
678
- }
679
-
680
- $ automators_data = $ metadata ->get ('member_automations ' )->get_data ($ level ->ID );
681
- if (empty ($ automators_data )) {
682
- continue ;
683
- }
684
-
685
- foreach ($ automators_data as $ automator_data ) {
686
- if (!isset ($ automator_data ['value ' ],$ automator_data ['name ' ])) {
687
- continue ;
688
- }
689
-
690
- if (!$ automators ->has ($ automator_data ['name ' ])) {
691
- continue ;
692
- }
693
-
694
- $ automators ->get ($ automator_data ['name ' ])->queue ($ level ->ID , $ automator_data ['value ' ]);
695
- }
696
- }
697
-
698
- foreach ($ automators as $ automator ) {
699
- if (!empty ($ automator ->get_level_data ())) {
700
- $ automator ->add_callback ();
701
- }
702
- }
703
- }
704
-
705
- public function rest_api_access ($ result )
706
- {
707
- //bail if auth has been handled elsewhere
708
- if ($ result === true || is_wp_error ($ result )) {
709
- return $ result ;
710
- }
711
-
712
- if (rua_get_user ()->has_global_access ()) {
713
- return $ result ;
714
- }
715
-
716
- if (!get_option ('rua_rest_api_access ' , 1 )) {
717
- return $ result ;
718
- }
719
-
720
- //Contributor is the lowest role that should have access,
721
- //since they can see content in admin area
722
- if (current_user_can ('edit_posts ' )) {
723
- return $ result ;
724
- }
725
-
726
- $ restricted = [
727
- '/wp/v2/search ' => true ,
728
- '/wp/v2/users ' => true
729
- ];
730
-
731
- $ ignored_post_types = [
732
- 'nav_menu_item ' => true ,
733
- 'wp_block ' => true ,
734
- 'wp_template ' => true ,
735
- 'wp_template_part ' => true ,
736
- 'wp_navigation ' => true
737
- ];
738
- foreach (get_post_types (['show_in_rest ' => true ], 'objects ' ) as $ post_type ) {
739
- if (empty ($ post_type ->rest_base )) {
740
- continue ;
741
- }
742
- if (isset ($ ignored_post_types [$ post_type ->name ])) {
743
- continue ;
744
- }
745
- $ restricted ['/ ' . $ post_type ->rest_namespace . '/ ' . $ post_type ->rest_base ] = true ;
746
- }
747
- $ ignored_taxonomies = [
748
- 'menu ' => true ,
749
- ];
750
- foreach (get_taxonomies (['show_in_rest ' => true ], 'objects ' ) as $ taxonomy ) {
751
- if (empty ($ taxonomy ->rest_base )) {
752
- continue ;
753
- }
754
- if (isset ($ ignored_taxonomies [$ post_type ->name ])) {
755
- continue ;
756
- }
757
- $ restricted ['/ ' . $ taxonomy ->rest_namespace . '/ ' . $ taxonomy ->rest_base ] = true ;
758
- }
759
-
760
- global $ wp ;
761
-
762
- $ route = $ wp ->query_vars ['rest_route ' ];
763
- $ route = preg_replace ('/(\/\d+)$/ ' , '' , $ route , 1 );
764
-
765
- if (!isset ($ restricted [$ route ])) {
766
- return $ result ;
767
- }
768
-
769
- return new WP_Error (
770
- 'rest_forbidden ' ,
771
- __ ('Sorry, you are not allowed to do that. ' ),
772
- ['status ' => rest_authorization_required_code ()]
773
- );
588
+ return rua ()->get (\RestrictUserAccess \Membership \Automator \AutomatorService::class)
589
+ ->get_level_automators ();
774
590
}
775
591
}
0 commit comments