Exemple #1
0
/**
 * Retrieve delete posts link for post.
 *
 * Can be used within the HiveQueen loop or outside of it, with any post type.
 *
 * @since 0.0.1
 *
 * @param int    $id           Optional. Post ID.
 * @param string $deprecated   Not used.
 * @param bool   $force_delete Whether to bypass trash and force deletion. Default is false.
 * @return string|void The delete post link URL for the given post.
 */
function get_delete_post_link($id = 0, $deprecated = '', $force_delete = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '3.0');
    }
    if (!($post = get_post($id))) {
        return;
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('delete_post', $post->ID)) {
        return;
    }
    $action = $force_delete || !EMPTY_TRASH_DAYS ? 'delete' : 'trash';
    $delete_link = add_query_arg('action', $action, admin_url(sprintf($post_type_object->_edit_link, $post->ID)));
    /**
     * Filter the post delete link.
     *
     * @since 0.0.1
     *
     * @param string $link         The delete link.
     * @param int    $post_id      Post ID.
     * @param bool   $force_delete Whether to bypass the trash and force deletion. Default false.
     */
    return apply_filters('get_delete_post_link', hq_nonce_url($delete_link, "{$action}-post_{$post->ID}"), $post->ID, $force_delete);
}
/**
 * Returns the Log Out URL.
 *
 * Returns the URL that allows the user to log out of the site.
 *
 * @since 0.0.1
 *
 * @param string $redirect Path to redirect to on logout.
 * @return string A log out URL.
 */
function hq_logout_url($redirect = '')
{
    $args = array('action' => 'logout');
    if (!empty($redirect)) {
        $args['redirect_to'] = urlencode($redirect);
    }
    $logout_url = add_query_arg($args, site_url('hq-login.php', 'login'));
    $logout_url = hq_nonce_url($logout_url, 'log-out');
    /**
     * Filter the logout URL.
     *
     * @since 0.0.1
     *
     * @param string $logout_url The Log Out URL.
     * @param string $redirect   Path to redirect to on logout.
     */
    return apply_filters('logout_url', $logout_url, $redirect);
}
Exemple #3
0
/**
 * Outputs the form used by the importers to accept the data to be imported
 *
 * @since 0.0.1
 *
 * @param string $action The action attribute for the form.
 */
function hq_import_upload_form($action)
{
    /**
     * Filter the maximum allowed upload size for import files.
     *
     * @since 0.0.1
     *
     * @see hq_max_upload_size()
     *
     * @param int $max_upload_size Allowed upload size. Default 1 MB.
     */
    $bytes = apply_filters('import_upload_size_limit', hq_max_upload_size());
    $size = size_format($bytes);
    $upload_dir = hq_upload_dir();
    if (!empty($upload_dir['error'])) {
        ?>
<div class="error"><p><?php 
        _e('Before you can upload your import file, you will need to fix the following error:');
        ?>
</p>
		<p><strong><?php 
        echo $upload_dir['error'];
        ?>
</strong></p></div><?php 
    } else {
        ?>
<form enctype="multipart/form-data" id="import-upload-form" method="post" class="hq-upload-form" action="<?php 
        echo esc_url(hq_nonce_url($action, 'import-upload'));
        ?>
">
<p>
<label for="upload"><?php 
        _e('Choose a file from your computer:');
        ?>
</label> (<?php 
        printf(__('Maximum size: %s'), $size);
        ?>
)
<input type="file" id="upload" name="import" size="25" />
<input type="hidden" name="action" value="save" />
<input type="hidden" name="max_file_size" value="<?php 
        echo $bytes;
        ?>
" />
</p>
<?php 
        submit_button(__('Upload file and import'), 'button');
        ?>
</form>
<?php 
    }
}
Exemple #4
0
/**
 * Remove directory and files of a plugin for a list of plugins.
 *
 * @since 0.0.1
 *
 * @global HQ_Filesystem_Base $hq_filesystem
 *
 * @param array  $plugins    List of plugins to delete.
 * @param string $deprecated Deprecated.
 * @return bool|null|HQ_Error True on success, false is $plugins is empty, HQ_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_plugins($plugins, $deprecated = '')
{
    global $hq_filesystem;
    if (empty($plugins)) {
        return false;
    }
    $checked = array();
    foreach ($plugins as $plugin) {
        $checked[] = 'checked[]=' . $plugin;
    }
    ob_start();
    $url = hq_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins');
    if (false === ($credentials = request_filesystem_credentials($url))) {
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'hq-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'hq-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!HQ_Filesystem($credentials)) {
        request_filesystem_credentials($url, '', true);
        //Failed to connect, Error and request again
        $data = ob_get_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'hq-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'hq-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($hq_filesystem)) {
        return new HQ_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_hq_error($hq_filesystem->errors) && $hq_filesystem->errors->get_error_code()) {
        return new HQ_Error('fs_error', __('Filesystem error.'), $hq_filesystem->errors);
    }
    // Get the base plugin folder.
    $plugins_dir = $hq_filesystem->hq_plugins_dir();
    if (empty($plugins_dir)) {
        return new HQ_Error('fs_no_plugins_dir', __('Unable to locate HiveQueen Plugin directory.'));
    }
    $plugins_dir = trailingslashit($plugins_dir);
    $plugin_translations = hq_get_installed_translations('plugins');
    $errors = array();
    foreach ($plugins as $plugin_file) {
        // Run Uninstall hook.
        if (is_uninstallable_plugin($plugin_file)) {
            uninstall_plugin($plugin_file);
        }
        $this_plugin_dir = trailingslashit(dirname($plugins_dir . $plugin_file));
        // If plugin is in its own directory, recursively delete the directory.
        if (strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir) {
            //base check on if plugin includes directory separator AND that it's not the root plugin folder
            $deleted = $hq_filesystem->delete($this_plugin_dir, true);
        } else {
            $deleted = $hq_filesystem->delete($plugins_dir . $plugin_file);
        }
        if (!$deleted) {
            $errors[] = $plugin_file;
            continue;
        }
        // Remove language files, silently.
        $plugin_slug = dirname($plugin_file);
        if ('.' !== $plugin_slug && !empty($plugin_translations[$plugin_slug])) {
            $translations = $plugin_translations[$plugin_slug];
            foreach ($translations as $translation => $data) {
                $hq_filesystem->delete(HQ_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po');
                $hq_filesystem->delete(HQ_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo');
            }
        }
    }
    // Remove deleted plugins from the plugin updates list.
    if ($current = get_site_transient('update_plugins')) {
        // Don't remove the plugins that weren't deleted.
        $deleted = array_diff($plugins, $errors);
        foreach ($deleted as $plugin_file) {
            unset($current->response[$plugin_file]);
        }
        set_site_transient('update_plugins', $current);
    }
    if (!empty($errors)) {
        return new HQ_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)));
    }
    return true;
}