admin管理员组

文章数量:1134588

Have a bit of a problem (since no one else has it, seems to be specific to me!:)). I have a WordPress plugin that works fine. So I added a setup wizard to it. Added the relevant steps(files) to a subfolder within the plugin folder (folder/files permissions are correct and tried with 777 also). On activation I get: Sorry, you are not allowed to access this page. When I remove the setup wizard, the plugin gets activated and there are no problems.

There are no errors in WordPress logs (switched on from wp-config.php). Only error I get is in apache access logs - 403.

Following are the relevant snippets:

From the main file:

error_reporting(E_ALL);
ini_set('display_errors', 1);
ob_flush();

    // Add an activation hook
register_activation_hook(__FILE__, 'my_plugin_activate_setup_wizard');

function my_plugin_activate_setup_wizard() {
     $capability = 'manage_options';
    // Redirect the user to the first step of the setup wizard
    wp_safe_redirect(admin_url('admin.php?page=my-plugin-setup-wizard/step1.php&step=1'));
    exit;
}

Step 1. of the wizard:

    <?php
/**
 * Displays the first step of My Plugin Setup Wizard.
 */

defined('ABSPATH') || exit;

function my_plugin_activate_setup_wizard_step1() {
    ?>
    <div class="wrap">
        <!-- Progress Indicator -->
        <div class="setup-wizard-progress">
            <div class="progress-bar" style="width: 25%;"></div>
        </div>

        <h1 class="h4 card-header bg-white border-bottom-0 pt-4 pb-1">
            <?php esc_html_e('Welcome to My Plugin Setup Wizard!', 'my-plugin-wp'); ?>
        </h1>

        <div class="card-body text-muted">
            <p><?php esc_html_e('Thank you for choosing My Plugin - The WordPress Plugin', 'my-plugin-wp'); ?></p>
            <hr class="mt-4 pt-3 pb-0" />
            <p class="small"><?php echo wp_kses_post(__('This quick setup wizard will help you configure the basic settings. It’s completely optional and shouldn’t take longer than five minutes.', 'my-plugin-wp')); ?></p>
        </div>

        <div class="card-footer mb-0 bg-white gp-setup-actions step border-top-0">
            <a href="<?php echo esc_url($next_url); ?>" class="btn btn-primary button-next"><?php esc_html_e("Let's get started!", 'my-plugin-wp'); ?></a>
            <a href="<?php echo esc_url(admin_url('admin.php?page=my-plugin-settings-page')); ?>" class="btn btn-secondary d-block mt-2"><?php esc_html_e('Cancel', 'my-plugin-wp'); ?></a>
        </div>
    </div>
    <?php
}

// Hook this step to your setup wizard
add_action('admin_notices', 'my_plugin_setup_wizard_step1');

Appreciate the help.

本文标签: pluginsSetup Wizard Permission Error on Activation (403)