Skip to content

Commit

Permalink
Added ability to pass 'request_callback' to hm_add_rewrite_rule, fixe…
Browse files Browse the repository at this point in the history
…d issue with author_name on edit profile
  • Loading branch information
joehoyle committed Feb 7, 2012
1 parent 7fa8d6d commit 14627c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions hm-accounts/hm-accounts.rewrite.php
Expand Up @@ -28,8 +28,21 @@ function hma_rewrite_rules() {
hm_add_rewrite_rule( '^' . hma_get_register_inline_rewrite_slug() . '/?$', 'is_register=1', $register_inline, array( 'post_query_properties' => array( 'is_home' => false, 'is_404' => false, 'is_register' => true ), 'permission' => 'logged_out_only' ) );

if ( file_exists( $edit_profile = hma_get_edit_profile_template() ) )
hm_add_rewrite_rule( '^' . hma_get_edit_profile_rewrite_slug() . '/?$', 'author_name=$matches[1]&is_profile=1', $edit_profile, array( 'post_query_properties' => array( 'is_home' => false, 'is_edit_profile' => true ), 'permission' => 'displayed_user_only' ) );

hm_add_rewrite_rule(
'^' . hma_get_edit_profile_rewrite_slug() . '/?$',
'author_name=$matches[1]&is_profile=1',
$edit_profile,
array(
'post_query_properties' => array( 'is_home' => false, 'is_edit_profile' => true ),
'permission' => 'displayed_user_only',
'request_callback' => function( $request ) {

if ( is_user_logged_in() )
$request->query_vars['author'] = get_current_user_id();
}
)
);

if ( file_exists( $profile = hma_get_user_profile_template() ) )
hm_add_rewrite_rule( '^' . hma_get_user_profile_rewrite_slug() . '/([^\/]*)(/page/([\d]*))?/?$', 'author_name=$matches[1]&paged=$matches[3]', $profile, array( 'post_query_properties' => array( 'is_home' => false, 'is_user_profile' => true ) ) );

Expand Down
5 changes: 4 additions & 1 deletion hm-core.rewrite.php
Expand Up @@ -97,7 +97,10 @@ function hm_set_custom_rewrite_rule_current_page( $request ) {
if ( isset( $hm_rewrite_rules ) && array_key_exists( $request->matched_rule, (array) $hm_rewrite_rules ) ) {

$hm_current_rewrite_rule = $hm_rewrite_rules[$request->matched_rule];


if ( ! empty( $hm_current_rewrite_rule[3]['request_callback'] ) && is_callable( $hm_current_rewrite_rule[3]['request_callback'] ) )
call_user_func( $hm_current_rewrite_rule[3]['request_callback'], $request );

do_action_ref_array( 'hm_parse_request_' . $request->matched_rule, array( &$request ) );

$hm_current_rewrite_rule[4] = $request->query_vars;
Expand Down

0 comments on commit 14627c5

Please sign in to comment.