59 lines
1.1 KiB
PHP
59 lines
1.1 KiB
PHP
<?php
|
|
namespace CUSTER;
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
* change the current user to the author id of the current object
|
|
* the only option is to force the author
|
|
* -> there is no sens in forcing the logged_in, because it's already the default
|
|
*
|
|
* [custer_change_id] -> default (author)
|
|
* [custer_change_id author] -> author
|
|
* [custer_change_id off] -> reset to logged_in
|
|
*
|
|
*/
|
|
function shortcode_change_id($options) {
|
|
/*
|
|
* set the default value for option
|
|
* currently it can only be author
|
|
*
|
|
*/
|
|
$option = 'author';
|
|
if (is_array($options)) {
|
|
$option = reset($options);
|
|
}
|
|
|
|
if (!is_string($option)) {
|
|
return;
|
|
}
|
|
|
|
|
|
if ($option === 'author') {
|
|
$id = get_author_id();
|
|
Custer::set_current_user_backup();
|
|
wp_set_current_user($id);
|
|
}
|
|
else if ($option === 'off') {
|
|
$id = Custer::reset_current_user_backup();
|
|
wp_set_current_user($id);
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
add_shortcode('custer_change_id', __NAMESPACE__.'\shortcode_change_id');
|
|
|
|
|
|
|
|
|
|
?>
|