Changeset 4930
- Timestamp:
- 05/19/2013 06:36:46 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bbpress.php
r4901 r4930 236 236 $this->subs_id = apply_filters( 'bbp_subs_id', 'bbp_subs' ); 237 237 $this->view_id = apply_filters( 'bbp_view_id', 'bbp_view' ); 238 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' ); 239 $this->paged_id = apply_filters( 'bbp_paged_id', 'paged' ); 238 240 $this->search_id = apply_filters( 'bbp_search_id', 'bbp_search' ); 239 $this->edit_id = apply_filters( 'bbp_edit_id', 'edit' );240 241 241 242 /** Queries ***********************************************************/ … … 370 371 'load_textdomain', // Load textdomain (bbpress) 371 372 'add_rewrite_tags', // Add rewrite tags (view|user|edit|search) 372 'generate_rewrite_rules' // Generate rewrite rules (view|edit|search) 373 'add_rewrite_rules', // Generate rewrite rules (view|edit|paged|search) 374 'add_permastructs' // Add permalink structures (view|user|search) 373 375 ); 374 376 … … 855 857 */ 856 858 public static function add_rewrite_tags() { 857 add_rewrite_tag( '% %' . bbp_get_view_rewrite_id() . '%%', '([^/]+)' ); // View Page tag858 add_rewrite_tag( '% %' . bbp_get_edit_rewrite_id() . '%%', '([1]{1,})' ); // Edit Page tag859 add_rewrite_tag( '% %' . bbp_get_search_rewrite_id() . '%%', '([^/]+)' ); // Search Results tag860 add_rewrite_tag( '% %' . bbp_get_user_rewrite_id() . '%%', '([^/]+)' ); // User Profile tag861 add_rewrite_tag( '% %' . bbp_get_user_favorites_rewrite_id() . '%%', '([1]{1,})' ); // User Favorites tag862 add_rewrite_tag( '% %' . bbp_get_user_subscriptions_rewrite_id() . '%%', '([1]{1,})' ); // User Subscriptions tag863 add_rewrite_tag( '% %' . bbp_get_user_topics_rewrite_id() . '%%', '([1]{1,})' ); // User Topics Tag864 add_rewrite_tag( '% %' . bbp_get_user_replies_rewrite_id() . '%%', '([1]{1,})' ); // User Replies Tag865 } 866 867 /** 868 * RegisterbbPress-specific rewrite rules for uri's that are not859 add_rewrite_tag( '%' . bbp_get_view_rewrite_id() . '%', '([^/]+)' ); // View Page tag 860 add_rewrite_tag( '%' . bbp_get_edit_rewrite_id() . '%', '([1]{1,})' ); // Edit Page tag 861 add_rewrite_tag( '%' . bbp_get_search_rewrite_id() . '%', '([^/]+)' ); // Search Results tag 862 add_rewrite_tag( '%' . bbp_get_user_rewrite_id() . '%', '([^/]+)' ); // User Profile tag 863 add_rewrite_tag( '%' . bbp_get_user_favorites_rewrite_id() . '%', '([1]{1,})' ); // User Favorites tag 864 add_rewrite_tag( '%' . bbp_get_user_subscriptions_rewrite_id() . '%', '([1]{1,})' ); // User Subscriptions tag 865 add_rewrite_tag( '%' . bbp_get_user_topics_rewrite_id() . '%', '([1]{1,})' ); // User Topics Tag 866 add_rewrite_tag( '%' . bbp_get_user_replies_rewrite_id() . '%', '([1]{1,})' ); // User Replies Tag 867 } 868 869 /** 870 * Add bbPress-specific rewrite rules for uri's that are not 869 871 * setup for us by way of custom post types or taxonomies. This includes: 870 872 * - Front-end editing … … 873 875 * 874 876 * @since bbPress (r2688) 875 * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in 876 * $wp_rewrite->rules 877 */ 878 public static function generate_rewrite_rules( $wp_rewrite ) { 879 880 // Slugs 877 * @todo Extract into an API 878 */ 879 public static function add_rewrite_rules() { 880 881 /** Setup *************************************************************/ 882 883 // Add rules to top or bottom? 884 $priority = 'top'; 885 886 // Single Slugs 887 $forum_slug = bbp_get_forum_slug(); 888 $topic_slug = bbp_get_topic_slug(); 889 $reply_slug = bbp_get_reply_slug(); 890 $ttag_slug = bbp_get_topic_tag_tax_slug(); 891 892 // Archive Slugs 893 $user_slug = bbp_get_user_slug(); 894 $view_slug = bbp_get_view_slug(); 895 $search_slug = bbp_get_search_slug(); 896 $topic_archive_slug = bbp_get_topic_archive_slug(); 897 $reply_archive_slug = bbp_get_reply_archive_slug(); 898 899 // Tertiary Slugs 900 $feed_slug = 'feed'; 901 $edit_slug = 'edit'; 902 $paged_slug = bbp_get_paged_slug(); 903 $user_favs_slug = bbp_get_user_favorites_slug(); 904 $user_subs_slug = bbp_get_user_subscriptions_slug(); 905 906 // Unique rewrite ID's 907 $feed_id = 'feed'; 908 $edit_id = 'edit'; 909 $view_id = bbp_get_view_rewrite_id(); 910 $paged_id = bbp_get_paged_rewrite_id(); 911 $search_id = bbp_get_search_rewrite_id(); 912 $user_id = bbp_get_user_rewrite_id(); 913 $user_favs_id = bbp_get_user_favorites_rewrite_id(); 914 $user_subs_id = bbp_get_user_subscriptions_rewrite_id(); 915 $user_tops_id = bbp_get_user_topics_rewrite_id(); 916 $user_reps_id = bbp_get_user_replies_rewrite_id(); 917 918 // Rewrite rule matches used repeatedly below 919 $root_rule = '/([^/]+)/?$'; 920 $feed_rule = '/([^/]+)/' . $feed_slug . '/?$'; 921 $edit_rule = '/([^/]+)/' . $edit_slug . '/?$'; 922 $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$'; 923 924 // Search rules (without slug check) 925 $search_root_rule = '/?$'; 926 $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1,})/?$'; 927 928 /** Add ***************************************************************/ 929 930 // User profile rules 931 $tops_rule = '/([^/]+)/' . $topic_archive_slug . '/?$'; 932 $reps_rule = '/([^/]+)/' . $reply_archive_slug . '/?$'; 933 $favs_rule = '/([^/]+)/' . $user_favs_slug . '/?$'; 934 $subs_rule = '/([^/]+)/' . $user_subs_slug . '/?$'; 935 $tops_paged_rule = '/([^/]+)/' . $topic_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; 936 $reps_paged_rule = '/([^/]+)/' . $reply_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; 937 $favs_paged_rule = '/([^/]+)/' . $user_favs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; 938 $subs_paged_rule = '/([^/]+)/' . $user_subs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$'; 939 940 // Edit Forum|Topic|Reply|Topic-tag 941 add_rewrite_rule( $forum_slug . $edit_rule, 'index.php?' . bbp_get_forum_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority ); 942 add_rewrite_rule( $topic_slug . $edit_rule, 'index.php?' . bbp_get_topic_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority ); 943 add_rewrite_rule( $reply_slug . $edit_rule, 'index.php?' . bbp_get_reply_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority ); 944 add_rewrite_rule( $ttag_slug . $edit_rule, 'index.php?' . bbp_get_topic_tag_tax_id() . '=$matches[1]&' . $edit_id . '=1', $priority ); 945 946 // User Pagination|Edit|View 947 add_rewrite_rule( $user_slug . $tops_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 948 add_rewrite_rule( $user_slug . $reps_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 949 add_rewrite_rule( $user_slug . $favs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 950 add_rewrite_rule( $user_slug . $subs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1&' . $paged_id . '=$matches[2]', $priority ); 951 add_rewrite_rule( $user_slug . $tops_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1', $priority ); 952 add_rewrite_rule( $user_slug . $reps_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1', $priority ); 953 add_rewrite_rule( $user_slug . $favs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1', $priority ); 954 add_rewrite_rule( $user_slug . $subs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1', $priority ); 955 add_rewrite_rule( $user_slug . $edit_rule, 'index.php?' . $user_id . '=$matches[1]&' . $edit_id . '=1', $priority ); 956 add_rewrite_rule( $user_slug . $root_rule, 'index.php?' . $user_id . '=$matches[1]', $priority ); 957 958 // Topic-View Pagination|Feed|View 959 add_rewrite_rule( $view_slug . $paged_rule, 'index.php?' . $view_id . '=$matches[1]&' . $paged_id . '=$matches[2]', $priority ); 960 add_rewrite_rule( $view_slug . $feed_rule, 'index.php?' . $view_id . '=$matches[1]&' . $feed_id . '=$matches[2]', $priority ); 961 add_rewrite_rule( $view_slug . $root_rule, 'index.php?' . $view_id . '=$matches[1]', $priority ); 962 963 // Search All 964 add_rewrite_rule( $search_slug . $search_paged_rule, 'index.php?' . $paged_id .'=$matches[1]', $priority ); 965 add_rewrite_rule( $search_slug . $search_root_rule, 'index.php?' . $search_id, $priority ); 966 } 967 968 /** 969 * Add permalink structures for new archive-style destinations. 970 * 971 * - Users 972 * - Topic Views 973 * - Search 974 * 975 * @since bbPress (r4930) 976 */ 977 public static function add_permastructs() { 978 979 // Get unique ID's 980 $user_id = bbp_get_user_rewrite_id(); 981 $view_id = bbp_get_view_rewrite_id(); 982 $search_id = bbp_get_search_rewrite_id(); 983 984 // Get root slugs 985 $user_slug = bbp_get_user_slug(); 881 986 $view_slug = bbp_get_view_slug(); 882 987 $search_slug = bbp_get_search_slug(); 883 $user_slug = bbp_get_user_slug(); 884 885 // Unique rewrite ID's 886 $edit_id = bbp_get_edit_rewrite_id(); 887 $view_id = bbp_get_view_rewrite_id(); 888 $search_id = bbp_get_search_rewrite_id(); 889 $user_id = bbp_get_user_rewrite_id(); 890 $favs_id = bbp_get_user_favorites_rewrite_id(); 891 $subs_id = bbp_get_user_subscriptions_rewrite_id(); 892 $tops_id = bbp_get_user_topics_rewrite_id(); 893 $reps_id = bbp_get_user_replies_rewrite_id(); 894 895 // Rewrite rule matches used repeatedly below 896 $root_rule = '/([^/]+)/?$'; 897 $edit_rule = '/([^/]+)/edit/?$'; 898 $feed_rule = '/([^/]+)/feed/?$'; 899 $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$'; 900 901 // Search rules (without slug check) 902 $search_root_rule = '/?$'; 903 $search_page_rule = '/page/?([0-9]{1,})/?$'; 904 905 // User profile rules 906 $tops_rule = '/([^/]+)/topics/?$'; 907 $reps_rule = '/([^/]+)/replies/?$'; 908 $favs_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/?$'; 909 $subs_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/?$'; 910 $tops_page_rule = '/([^/]+)/topics/page/?([0-9]{1,})/?$'; 911 $reps_page_rule = '/([^/]+)/replies/page/?([0-9]{1,})/?$'; 912 $favs_page_rule = '/([^/]+)/' . bbp_get_user_favorites_slug() . '/page/?([0-9]{1,})/?$'; 913 $subs_page_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/page/?([0-9]{1,})/?$'; 914 915 // New bbPress specific rules to merge with existing that are not 916 // handled automatically by custom post types or taxonomy types 917 $bbp_rules = array( 918 919 // Edit Forum|Topic|Reply|Topic-tag 920 bbp_get_forum_slug() . $edit_rule => 'index.php?' . bbp_get_forum_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', 921 bbp_get_topic_slug() . $edit_rule => 'index.php?' . bbp_get_topic_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', 922 bbp_get_reply_slug() . $edit_rule => 'index.php?' . bbp_get_reply_post_type() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', 923 bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', 924 925 // User Pagination|Edit|View 926 $user_slug . $tops_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), 927 $user_slug . $reps_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), 928 $user_slug . $favs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), 929 $user_slug . $subs_page_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ), 930 $user_slug . $tops_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1', 931 $user_slug . $reps_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1', 932 $user_slug . $favs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1', 933 $user_slug . $subs_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1', 934 $user_slug . $edit_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1', 935 $user_slug . $root_rule => 'index.php?' . $user_id . '=' . $wp_rewrite->preg_index( 1 ), 936 937 // Topic-View Pagination|Feed|View 938 $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ), 939 $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed=' . $wp_rewrite->preg_index( 2 ), 940 $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ), 941 942 // Search All 943 $search_slug . $search_page_rule => 'index.php?paged=' . $wp_rewrite->preg_index( 1 ), 944 $search_slug . $search_root_rule => 'index.php?' . $search_id, 945 ); 946 947 // Merge bbPress rules with existing 948 $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules ); 949 950 // Return merged rules 951 return $wp_rewrite; 988 989 // User Permastruct 990 add_permastruct( $user_id, $user_slug . '/%' . $user_id . '%', array( 991 'with_front' => false, 992 'ep_mask' => EP_NONE, 993 'paged' => false, 994 'feed' => false, 995 'forcomments' => false, 996 'walk_dirs' => true, 997 'endpoints' => false, 998 ) ); 999 1000 // Topic View Permastruct 1001 add_permastruct( $view_id, $view_slug . '/%' . $view_id . '%', array( 1002 'with_front' => false, 1003 'ep_mask' => EP_NONE, 1004 'paged' => false, 1005 'feed' => false, 1006 'forcomments' => false, 1007 'walk_dirs' => true, 1008 'endpoints' => false, 1009 ) ); 1010 1011 // Search Permastruct 1012 add_permastruct( $user_id, $search_slug . '/%' . $search_id . '%', array( 1013 'with_front' => false, 1014 'ep_mask' => EP_NONE, 1015 'paged' => true, 1016 'feed' => false, 1017 'forcomments' => false, 1018 'walk_dirs' => true, 1019 'endpoints' => false, 1020 ) ); 952 1021 } 953 1022 }
Note: See TracChangeset
for help on using the changeset viewer.