Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Publicious.org
Plugins
Join Page
Commits
0ecd2795
Commit
0ecd2795
authored
Sep 02, 2016
by
John James Jacoby
Browse files
First pass at a custom `newbloguser` handler.
parent
d643bb4e
Changes
3
Hide whitespace changes
Inline
Side-by-side
includes/actions.php
View file @
0ecd2795
...
...
@@ -63,3 +63,56 @@ function wp_join_page_maybe_do_request() {
wp_safe_redirect
(
$url
);
die
;
}
/**
* Add a new user to a blog by visiting /newbloguser/username/.
*
* This will only work when the user's details are saved as an option
* keyed as 'new_user_x', where 'x' is the username of the user to be
* added, as when a user is invited through the regular WP Add User interface.
*
* @since 0.1.0
*/
function
wp_join_page_maybe_add_existing_user_to_blog
()
{
// "newbloguser" is a hard-coded URL segment, for now
if
(
false
===
strpos
(
$_SERVER
[
'REQUEST_URI'
],
'/newbloguser/'
)
)
{
return
;
}
// Break apart the request
$parts
=
explode
(
'/'
,
$_SERVER
[
'REQUEST_URI'
]
);
$key
=
array_pop
(
$parts
);
// Get username from URL
if
(
empty
(
$key
)
)
{
$key
=
array_pop
(
$parts
);
}
// Clean-up
$option_key
=
"new_user_
{
$key
}
"
;
$details
=
get_option
(
$option_key
);
if
(
!
empty
(
$details
)
)
{
delete_option
(
$option_key
);
}
// Get blog name
$blog_name
=
get_option
(
'blogname'
);
$home_url
=
home_url
();
// Failure
if
(
empty
(
$details
)
||
is_wp_error
(
add_existing_user_to_blog
(
$details
)
)
)
{
wp_die
(
sprintf
(
__
(
'An error occurred adding you to this site. Return to <a href="%s">%s</a>.'
),
$home_url
,
$home_url
),
sprintf
(
__
(
'%s › Error'
),
$blog_name
),
array
(
'response'
=>
500
)
);
}
// Success
wp_die
(
sprintf
(
__
(
'You have been added to this site. Now you can <a href="%s">log in</a> using your username & password.'
),
wp_login_url
(
$home_url
)
),
sprintf
(
__
(
'%s › Success'
),
$blog_name
),
array
(
'response'
=>
200
)
);
}
includes/dictionary.php
View file @
0ecd2795
...
...
@@ -25,8 +25,8 @@ function wp_join_page_get_string( $key = '' ) {
$dictionary
=
array
(
// Errors
'err_username'
=>
esc_html__
(
'Th
is
username is already in use. Do you already have an account?'
,
'wp-join-page'
),
'err_email'
=>
esc_html__
(
'Th
is
email address is already registered. Do you already have an account?'
,
'wp-join-page'
),
'err_username'
=>
esc_html__
(
'Th
at
username is already in use. Do you already have an account?'
,
'wp-join-page'
),
'err_email'
=>
esc_html__
(
'Th
at
email address is already registered. Do you already have an account?'
,
'wp-join-page'
),
'err_unknown'
=>
esc_html__
(
'An unknown error occurred. Please try again with a more unique username.'
,
'wp-join-page'
),
// Success
...
...
includes/hooks.php
View file @
0ecd2795
...
...
@@ -15,6 +15,9 @@ remove_action( 'wpmu_activate_user', 'wpmu_welcome_user_notification', 10, 3 );
remove_action
(
'after_signup_user'
,
'wpmu_signup_user_notification'
,
10
,
4
);
remove_action
(
'init'
,
'maybe_add_existing_user_to_blog'
);
// Custom user invitation acceptance action
add_action
(
'init'
,
'wp_join_page_maybe_add_existing_user_to_blog'
);
// Enqueue assets
add_action
(
'wp_enqueue_scripts'
,
'wp_join_page_enqueue_scripts'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment