Esempio n. 1
0
/**
 * Determine if user is a site admin.
 *
 * @since 0.0.1
 *
 * @param int $user_id (Optional) The ID of a user. Defaults to the current user.
 * @return bool True if the user is a site admin.
 */
function is_super_admin($user_id = false)
{
    if (!$user_id || $user_id == get_current_user_id()) {
        $user = hq_get_current_user();
    } else {
        $user = get_userdata($user_id);
    }
    if (!$user || !$user->exists()) {
        return false;
    }
    if (is_multisite()) {
        $super_admins = get_super_admins();
        if (is_array($super_admins) && in_array($user->user_login, $super_admins)) {
            return true;
        }
    } else {
        if ($user->has_cap('delete_users')) {
            return true;
        }
    }
    return false;
}
Esempio n. 2
0
/**
 * Get the current user's ID
 *
 * @since MU
 *
 * @return int The current user's ID
 */
function get_current_user_id()
{
    if (!function_exists('hq_get_current_user')) {
        return 0;
    }
    $user = hq_get_current_user();
    return isset($user->ID) ? (int) $user->ID : 0;
}
Esempio n. 3
0
 /**
  * Creates a cryptographic token tied to a specific action, user, and window of time.
  *
  * @since 0.0.1
  *
  * @param string|int $action Scalar value to add context to the nonce.
  * @return string The token.
  */
 function hq_create_nonce($action = -1)
 {
     $user = hq_get_current_user();
     $uid = (int) $user->ID;
     if (!$uid) {
         /** This filter is documented in hq-includes/pluggable.php */
         $uid = apply_filters('nonce_user_logged_out', $uid, $action);
     }
     $token = hq_get_session_token();
     $i = hq_nonce_tick();
     return substr(hq_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
 }
Esempio n. 4
0
$screen->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="https://codex.wordpress.org/Dashboard_Screen" target="_blank">Documentation on Dashboard</a>') . '</p>' . '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
include ABSPATH . 'hq-admin/admin-header.php';
?>

<div class="wrap">
	<h1><?php 
echo esc_html($title);
?>
</h1>

<?php 
if (has_action('welcome_panel') && current_user_can('edit_theme_options')) {
    $classes = 'welcome-panel';
    $option = get_user_meta(get_current_user_id(), 'show_welcome_panel', true);
    // 0 = hide, 1 = toggled to show or single site creator, 2 = multisite site owner
    $hide = 0 == $option || 2 == $option && hq_get_current_user()->user_email != get_option('admin_email');
    if ($hide) {
        $classes .= ' hidden';
    }
    ?>

	<div id="welcome-panel" class="<?php 
    echo esc_attr($classes);
    ?>
">
		<?php 
    hq_nonce_field('welcome-panel-nonce', 'welcomepanelnonce', false);
    ?>
		<a class="welcome-panel-close" href="<?php 
    echo esc_url(admin_url('?welcome=0'));
    ?>
Esempio n. 5
0
/**
 * Find out which editor should be displayed by default.
 *
 * Works out which of the two editors to display as the current editor for a
 * user. The 'html' setting is for the "Text" editor tab.
 *
 * @since 0.0.1
 *
 * @return string Either 'tinymce', or 'html', or 'test'
 */
function hq_default_editor()
{
    $r = user_can_richedit() ? 'tinymce' : 'html';
    // defaults
    if (hq_get_current_user()) {
        // look for cookie
        $ed = get_user_setting('editor', 'tinymce');
        $r = in_array($ed, array('tinymce', 'html', 'test')) ? $ed : $r;
    }
    /**
     * Filter which editor should be displayed by default.
     *
     * @since 0.0.1
     *
     * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
     */
    return apply_filters('hq_default_editor', $r);
}
Esempio n. 6
0
 /**
  * Set up the current user.
  *
  * @since 0.0.1
  */
 public function init()
 {
     hq_get_current_user();
 }
Esempio n. 7
0
/**
 * Saves option for number of rows when listing posts, pages, comments, etc.
 *
 * @since 0.0.1
 */
function set_screen_options()
{
    if (isset($_POST['hq_screen_options']) && is_array($_POST['hq_screen_options'])) {
        check_admin_referer('screen-options-nonce', 'screenoptionnonce');
        if (!($user = hq_get_current_user())) {
            return;
        }
        $option = $_POST['hq_screen_options']['option'];
        $value = $_POST['hq_screen_options']['value'];
        if ($option != sanitize_key($option)) {
            return;
        }
        $map_option = $option;
        $type = str_replace('edit_', '', $map_option);
        $type = str_replace('_per_page', '', $type);
        if (in_array($type, get_taxonomies())) {
            $map_option = 'edit_tags_per_page';
        } elseif (in_array($type, get_post_types())) {
            $map_option = 'edit_per_page';
        } else {
            $option = str_replace('-', '_', $option);
        }
        switch ($map_option) {
            case 'edit_per_page':
            case 'users_per_page':
            case 'edit_comments_per_page':
            case 'upload_per_page':
            case 'edit_tags_per_page':
            case 'plugins_per_page':
                // Network admin
            // Network admin
            case 'sites_network_per_page':
            case 'users_network_per_page':
            case 'site_users_network_per_page':
            case 'plugins_network_per_page':
            case 'themes_network_per_page':
            case 'site_themes_network_per_page':
                $value = (int) $value;
                if ($value < 1 || $value > 999) {
                    return;
                }
                break;
            default:
                /**
                 * Filter a screen option value before it is set.
                 *
                 * The filter can also be used to modify non-standard [items]_per_page
                 * settings. See the parent function for a full list of standard options.
                 *
                 * Returning false to the filter will skip saving the current option.
                 *
                 * @since 0.0.1
                 *
                 * @see set_screen_options()
                 *
                 * @param bool|int $value  Screen option value. Default false to skip.
                 * @param string   $option The option name.
                 * @param int      $value  The number of rows to use.
                 */
                $value = apply_filters('set-screen-option', false, $option, $value);
                if (false === $value) {
                    return;
                }
                break;
        }
        update_user_meta($user->ID, $option, $value);
        hq_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), hq_get_referer()));
        exit;
    }
}
Esempio n. 8
0
      *
      * By default, the cookie expires 10 days from creation. To turn this
      * into a session cookie, return 0.
      *
      * @since 0.0.1
      *
      * @param int $expires The expiry time, as passed to setcookie().
      */
     $expire = apply_filters('post_password_expires', time() + 10 * DAY_IN_SECONDS);
     $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
     setcookie('hq-postpass_' . COOKIEHASH, $hasher->HashPassword(hq_unslash($_POST['post_password'])), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure);
     hq_safe_redirect(hq_get_referer());
     exit;
 case 'logout':
     check_admin_referer('log-out');
     $user = hq_get_current_user();
     hq_logout();
     if (!empty($_REQUEST['redirect_to'])) {
         $redirect_to = $requested_redirect_to = $_REQUEST['redirect_to'];
     } else {
         $redirect_to = 'hq-login.php?loggedout=true';
         $requested_redirect_to = '';
     }
     /**
      * Filter the log out redirect URL.
      *
      * @since 0.0.1
      *
      * @param string  $redirect_to           The redirect destination URL.
      * @param string  $requested_redirect_to The requested redirect destination URL passed as a parameter.
      * @param HQ_User $user                  The HQ_User object for the user that's logging out.