• Resolved djameswebdesign

    (@djameswebdesign)


    Hi, this may just be me or it could be a bug with the plugin, but for users that don’t have the ‘Edit Post’ capability, the quiz does not get submitted into the results table. My site has custom user roles, of which after some troubleshooting, it appears the user must be an admin, editor, contributor etc. or have the capability ‘edit post’ assigned to them for the plugin to work, and I do not wish for my users to have this capability.

    I wonder if you could advise.

    Thanks in advance,
    Dillon

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    Hi Dillon,
    This addon doesn’t care if you are logged in or not and does not require any permissions at all to save the results. The only related thing is that IF you are logged in, it will also grab the username.

    I’m guessing that you have some system set up that blocks the WordPress admin area (specifically admin-ajax.php) for non-logged-in users and users who do not have the edit post capability. I’d start by checking for any redirection plugins, security plugins, or whatever plugin you are using to manage user capabilities to see if there is anything set that could block this.

    Keep me posted on your findings and I’ll help guide further if I can!

    Thread Starter djameswebdesign

    (@djameswebdesign)

    Thank you very much for your speedy and comprehensive reply.

    You are right, my users are blocked from accessing the wordpress admin dashboard with a plugin, as I didn’t want the users to access this and want them to only access their account through the pages on the website. Would there be a way that you recommend to redirect users away from the /wp-admin whilst not interfering with your plugin?

    Anyway, thanks for the reply and I have found the general functionality of the HD Quiz plugin very useful.

    Plugin Author Harmonic Design

    (@harmonic_design)

    Adding the following PHP to your theme’s functions.php file should do what you need.

    function hdq_redirect_non_adminr()
    {
        // check if the current logged in user is an admin
        // and also make sure that the call isn't an ajax call
        if (!defined('DOING_AJAX') && !current_user_can('administrator')) {
            // if not ajax and not admin, redirect to homepage
    
            wp_redirect(site_url());
            exit;
        }
    }
    add_action('admin_init', 'hdq_redirect_non_admin');
    
    // BONUS: Hide the admin toolbar for non admins
    function hdq_remove_admin_bar()
    {
        if (!current_user_can('administrator') && !is_admin()) {
            show_admin_bar(false);
        }
    }
    add_action('after_setup_theme', 'hdq_remove_admin_bar');

    This will do two things. The first function will redirect any user who is NOT an admin (this includes editors, authors, etc) to the homepage if they try to access to admin backend area. We also check to make sure that it’s not an ajax request so that plugins like HD Quiz can still send data to be saved.

    The second function I’m not sure if you need or want, but it disabled to logged-in toolbar. The black toolbar that appears for logged in users on the top of the page for non-admins. Since you don’t want users to be able to access the backend, I figured you’d also want this toolbar removed for them ??

    Thread Starter djameswebdesign

    (@djameswebdesign)

    WOW. What an amazing response – was not expecting that at all, thank you ever so much. That is perfect – I will most definitely consider purchasing the premium version now!

    I know I have taken up a lot of your time already and I have another slightly unrelated query, so if you can’t this then no problem at all, but I was just quickly wondering where the results are stored? Ie. Are they in a database table (I looked but couldn’t seem to find them)?

    The full solution I am trying to build out is rather complex; I am basically looking to create a module whereby the logged in user is displayed with a table of all their past results, so that they can in essence see their progress over time.

    I am hopong to do this possibly by connecting to the storage database and sorting through the results, and if the user name of the submission and the current logged-in user match, I want these results to print in a table.

    So wonder if you could point me in the right direction as to where you store the responses.

    Again, thank you ever so much for your response, very much appreciated.

    Plugin Author Harmonic Design

    (@harmonic_design)

    The light version just saves a JSON string to the options table (take a look at ./wp-admin/options.php).

    The pro version uses a custom post type to store all of the data. Doing this should be fairly easy with both version, but if you have a lot of results then the pro version would be a LOT better to do something like this with.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Results not submitting for non-admin users’ is closed to new replies.