• I am trying to display some admin-only content (a button to the admin dashboard) on the accounts page, that I only want visible to the admins.

    I have tried several plugins for using php code and tried things like this:

    <?php global $user_ID; if( $user_ID ) : ?>
    <?php if( current_user_can('level_10') ) : ?>
    
    <a href="https://yourdomainurl.com/stats/">Stats</a>
    
    <?php else : ?>
    <?php endif; ?>
    <?php endif; ?>

    But no-one ever mentions where to put this code.

    I don’t want to start modifying WordPress as the second I update this will all be gone, I need something that will work and that I don’t have to redo every update.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Well, it depends on what exactly you are wanting to accomplish. The first step (if you don’t want to have to worry about code being erased when you update) is to create a Child Theme for your currently used theme.

    Once you have a child theme; you can begin to create your own functions in the functions.php file of your child theme.

    Now, where exactly are you wanting to display the button? You mention the “accounts” page. What page specifically are you referring?

    Thread Starter kjgbriggs

    (@kjgbriggs)

    The accounts page is that “My Account” page from WooCommerce.
    The page has a WooCommerce shortcode in, I was hoping to simply run PHP in the page without having to do any snazzy theme work or anything, but every plugin I have tried doesn’t work.

    The button would be displayed like this:

    <a href="/wp-admin"><input class="primaryButton" type="button" value="Administrator Dashboard"></a>

    I just need a way to do this in the page, only shown to admins, but I would like to avoid doing or using anything too complex.

    You can’t really run php from within a WordPress page. You need to use an action hook to “hook” the php code you want to run to it’s desired location.

    Now, since you’re wanting to incorporate this into Woo… it might be better to ask them. The “Woo Accounts page” is not something that is readily accessible to community members… so it’s difficult to offer any suggestions.

    I would be willing to bet Woo has some custom hooks and filters which you can use; it’s just a matter of knowing the correct action hook, and coding accordingly.

    Again, perhaps the Woo support may be able to offer more advanced assistance.

    If you can get it to be loaded through a widget, then this plugin might do the job, to restrict the display of a widget to admins or logged in users only ?
    https://www.ads-software.com/plugins/widget-logic/other_notes/

    Otherwise, with hooks and Woothemes, good luck. I have canvas on a site, and which shortcodes generate the display of something can be customized… but only within the already pre-configured, pre-created list of elements. For instance, I have an [post_edit] placed to be a hook below the posts, showing an edit button only visible for the admin…
    In other words, I don’t think Woothemes is a “cooperative” environment for you to make it, you’ll have to use wordpress, not Woothemes, if you see the idea…

    Thread Starter kjgbriggs

    (@kjgbriggs)

    As the WooCommerce elements were added using a shortcode, and I don’t need anything integrated with WooCommerce, I thought this would be the same as adding php to a regular page (which I don’t know how to do), and it may be, but I can’t find much info on how to do that.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying Admin-Only Content’ is closed to new replies.