Comments (3)
Hey,
Could elaborate on your use case? Are you rendering a sort of front end app into a WP theme?
I would suggest using query parameters so as not to interfere with the WP routing.
from wp-reactivate.
I created a shortcode using this repo boilerplate which will render full spa. We'd like user of our plugin to be able to add our shortcode to any page in the site; and our plugin should be able to handle all the subroutes from there on. For example, user creates /vehicles
page on his/her wordpress site and wants our plugin to render the content in that page; drops our shortcode to the page and shortcode will handle all the routing from /vehicles route such as /vehicles/personal
, /vehicles/commercial/trucks/18-tires
, etc... The requirement is that the urls should be nice looking html5 style urls means no hashes or query params...
To accomplish that, I've done:
Within the shortcode function just before the line-87, I added a function call such as
global $post;
$this->spa_url_rewrite($post->ID, $post->post_name);
and within spa_url_rewrite
function I have:
function spa_url_rewrite($postID, $postName) {
global $wp_rewrite;
$existingRules = $wp_rewrite->rules;
$spaRegex = '^' . $postName . '\/(.*)\/?$';
if(!array_key_exists($spaRegex , $existingRules)) {
add_rewrite_rule( $spaRegex, "index.php?page_id={$postID}", 'top' );
$wp_rewrite->flush_rules();
}
}
I tried to mitigate the cost of flushing rules on each page load by checking if existing rules already got my rule added before flushing. But not sure whether there is a better way to do this or not. My solution needs to be dynamic though. I mean I can't blindly add my overwrite rule to /vehicles route for example on init hook. My plugin should work whatever page end user has added my shortcode into.
from wp-reactivate.
I think you might run into performance problems with that under load.
I've closed this issue as it is doesn't concern the functionality of wp-reactivate. Best of luck with your project!
from wp-reactivate.
Related Issues (10)
- Accessing the WP Reactivate settings page throws error HOT 1
- Create final build HOT 1
- Heavy prod .js file HOT 1
- React widget not updating with code changes
- Typescript Support
- local changes not showing up in the web app HOT 4
- How to create shortcode for menu item with wp_nav_menu?
- Moving Plugin From Admin Settings to its own Admin Menu Item HOT 1
- Cannot load css file from an external module. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-reactivate.