@@ -23,14 +23,12 @@ public static function bootstrap()
2323 *
2424 * @author Nashwan Doaqan
2525 */
26- static function after_bbPress_setup ()
26+ public static function after_bbPress_setup ()
2727 {
28-
2928 if (function_exists ('is_bbpress ' )) {
3029 add_action ('registered_post_type ' , [__CLASS__ , 'add_post_types_rewrite ' ], 1 , 2 );
3130 add_filter ('post_type_link ' , [__CLASS__ , 'filter_post_type_link ' ], 1 , 2 );
3231 }
33-
3432 }
3533
3634 /**
@@ -40,7 +38,7 @@ static function after_bbPress_setup()
4038 * @param $postType
4139 * @param $args
4240 */
43- static function add_post_types_rewrite ($ postType , $ args )
41+ public static function add_post_types_rewrite ($ postType , $ args )
4442 {
4543 switch ($ postType ) {
4644 case bbp_get_topic_post_type ():
@@ -50,6 +48,7 @@ static function add_post_types_rewrite($postType, $args)
5048 'top '
5149 );
5250 add_permastruct ($ postType , bbp_get_forum_slug ()."%forumnames% " .bbp_get_topic_slug ()."/%postname%/ " , $ args ->rewrite );
51+ static ::flush_rewrite_rules_if_needed ();
5352 break ;
5453 }
5554 }
@@ -64,11 +63,12 @@ static function add_post_types_rewrite($postType, $args)
6463 *
6564 * @return mixed|string|void
6665 */
67- static function filter_post_type_link ($ post_link , $ _post )
66+ public static function filter_post_type_link ($ post_link , $ _post )
6867 {
6968 global $ wp_rewrite ;
70- if (empty ($ _post ) || $ _post ->post_status === 'auto-draft ' || strpos ('post_type ' , $ post_link ))
69+ if (empty ($ _post ) || $ _post ->post_status === 'auto-draft ' || strpos ('post_type ' , $ post_link )) {
7170 return $ post_link ;
71+ }
7272 switch ($ _post ->post_type ) {
7373 case bbp_get_topic_post_type ():
7474 $ post_link = $ wp_rewrite ->get_extra_permastruct ($ _post ->post_type );
@@ -78,20 +78,20 @@ static function filter_post_type_link($post_link, $_post)
7878 break ;
7979 }
8080 return $ post_link ;
81-
8281 }
8382
84- static function get_topic_parent_forums_slug ($ topicId ) {
83+ public static function get_topic_parent_forums_slug ($ topicId )
84+ {
8585 $ forumId = bbp_get_topic_forum_id ($ topicId );
8686 $ forumSlugs = [];
87- if ($ forumId === 0 ) { // means the topic belongs to no forum
87+ if ($ forumId === 0 ) { // means the topic belongs to no forum
8888 return '/no-forum/ ' ;
8989 }
9090 $ forum = get_post ($ forumId );
9191 $ hasParent = true ;
9292 while ($ hasParent ) {
9393 $ forumSlugs [] = $ forum ->post_name ;
94- if ($ forum ->post_parent === 0 ) {
94+ if ($ forum ->post_parent === 0 ) {
9595 $ hasParent = false ;
9696 } else {
9797 $ forum = get_post ($ forum ->post_parent );
@@ -100,8 +100,15 @@ static function get_topic_parent_forums_slug($topicId) {
100100 return '/ ' . implode ('/ ' , array_reverse ($ forumSlugs )) . '/ ' ;
101101 }
102102
103- static function get_topic_name_slug ($ post ) {
103+ public static function get_topic_name_slug ($ post )
104+ {
104105 return empty ($ post ->post_name ) ? sanitize_title_with_dashes ($ post ->post_title ) : $ post ->post_name ;
105106 }
106107
108+ private static function flush_rewrite_rules_if_needed () {
109+ if ( get_option ( Plugin::FLUSH_REWRITE_RULES_FLAG ) ) {
110+ flush_rewrite_rules ();
111+ delete_option ( Plugin::FLUSH_REWRITE_RULES_FLAG );
112+ }
113+ }
107114}
0 commit comments