Front end Force Refresh Button
-
Hello, awesome plugin! it solved a very specific problem I had.
I am currently building a custom control panel to create/edit a custom_post_type. I need to include a Force Refresh button in this custom control panel (which is in the frontend).
I have been unable to replicate this functionality in my frontend Form. Can you guide me on how I may achive this?Thanks
-
Hey @promtedcoin64,
Force Refresh has supported custom post types since version 2.1. Are you sure you’re on the most recent version of the plugin?
If you are, can you send back a screenshot of the admin section where the Force Refresh button isn’t appearing? Thanks!
Hello @jordanleven, thank you for the quick reply.
Yes it works for custom post types. and I do see it in the WordPress Admin area (when inside “wp-admin”). However I’m trying to place the Force Refresh button in the front-end area (not the dashboard area)…
Is there a function to trigger the Force refresh by sending the Post_ID ?Thank you
P.Initiating refreshes from outside of the admin area isn’t currently a supported feature. This is because initiating a refresh requires a cryptographic nonce which are only issues to authenticated users.
Do you mind going over your use case so I can better understand what you’re trying to accomplish?
Hello @jordanleven, I see. Let me explain a bit: I built an events website that has a lot of other custom posts-types related to each other using ACF plugin.
The process to create one event was a very intricate (you had to go into a lot of different places from the backend to publish One event). So I created a custom Front-end administrative panel where the event can be created and all its ‘child’ custom posts are related automatically to each other (all create/edit functions in ONE place).
I want to bring in the Force Refresh button to this custom administrative panel so that the ‘Polls’ (another post-type) can be Refreshed directly from my Front-end admin panel. Only Admin users have access to this custom admin panel. Is there anyway I could use this cryptographic nonce in the frontend and the force refresh function?
Thanks
Hey @promtedcoin64,
Thanks for sending that over—that helps me better understand your question. I’m afraid that initiating a refresh for all posts of a specific post type from the frontend is not currently a supported feature. Currently, the only supported types of force refreshing are refreshing the entire site or refreshing of a specific post (post, page, or custom post type) directly from the admin section.
It sounds like you’re looking for two things: 1) to request a refresh for all posts of a specific post type, and 2) to allow non-sitewide refreshes from outside of the dedicated admin section. While refreshing the site from outside of the dedicated admin section is currently supported via the Refresh Site action in the menu bar, there isn’t currently support for refreshing all posts of a specific type either in or outside of the admin section.
While this feature could be added in the future, it’s not something that you’d currently be able to do natively out of the box.
Hi @jordanleven , thanks for the reply.
Yes I need to achieve point number 2). But not really number 1).
I don’t want to refresh all posts of a specific post type. Only one post at a time. How can I replicate the Force Refresh current post button that is supposed to show up in the admin bar?
Apologies, I must have misunderstood your previous question regarding refreshing all posts of a specific type. Regarding the refresh button for a post on the front end, I’m afraid that’s not currently a supported feature of this plugin. While this feature could be added in the future, it’s not something that you’d currently be able to do natively out of the box.
@jordanleven, thank you for the quick replies Jordan.
Ok. Would it be possible for me to custom build this button?
I’ve been browsing the plugins code and found that in the admin area we need to enqueue “force-refresh-admin.js” and pass some localData. I echoed these on the page where I need it. I’m passing the nounce and a the ID of the post.I also copied the HTML from the metabox in the backend, but clicking the button doesn’t trigger the force-refresh. Is there a method to make this button work?
While it is technically possible for you to create a button to do this, it would be using what is considered to be a set of private APIs, meaning that I would be unable to provide support for it. Additionally, since private APIs are for internal use only, updates to the plugin might build your custom integration.
Knowing those risks, you could still technically build a button to do this as long as you submit a request that matches this payload. If you want to see what it looks like in practice, open your browser console and look at the XHR network requests when submitting a refresh for a page, post, or custom post type. Additionally, you’d have to generate a cryptographic nonce using the plugin name since you won’t be receiving the nonce through the normal localized data.
Again, this feature is not a supported feature of the plugin, and using private APIs in this way is something that is considered an anti-pattern. Even though it is technically possible, these private APIs are subject to change, which is why I won’t be able to provide support for this in the event this custom functionality doesn’t work or results in other bugs with your site.
- This reply was modified 2 years, 10 months ago by jordanleven.
One other quick thing I forgot to include after re-reading your post:
I echoed these on the page where I need it. I’m passing the nounce and a the ID of the post
Nonces are generated when a user is logged in and expire after being used. You’ll have to regenerate nonces on the backend via the WordPress
wp_create_nonce
API.- This reply was modified 2 years, 10 months ago by jordanleven.
Hey @promtedcoin64,
Since I haven’t heard back from you, I’m going to go ahead and close this request out.
Hey @jordanleven , Thank you. I’m taking my time to go through the resources you share and try to come up with something. I will create another ticket if necessary.
I guess I just have one more question. Since you mentioned this feature could be added in the future. Do you have any plans for it in a near future? Or can you quote me for this custom feature?
Hey @promtedcoin64,
Sounds good. To answer your questions:
Since you mentioned this feature could be added in the future. Do you have any plans for it in a near future?
Good question. When I say that this is something that could be implemented in the future, that means that hypothetically it would be possible and that there isn’t an ideological or technical limitation that would prevent this from being a supported feature in the future. Many factors go into whether or not a feature is implemented in this plugin, like feasibility (how easy it is to implement) and adaptability (how many people are requesting this feature and how many plan to use it). However, as in all feature requests, I don’t make any commitments about when or if they’ll be implemented. I’m afraid there would be no timeline since adding support for this feature is not on the horizon.Or can you quote me for this custom feature?
I don’t currently take on paid custom work for this plugin. However, since this is an open source plugin, PRs are always welcome!
- The topic ‘Front end Force Refresh Button’ is closed to new replies.