Git Product home page Git Product logo

Comments (3)

dnusca avatar dnusca commented on July 22, 2024

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.

rockneverdies55 avatar rockneverdies55 commented on July 22, 2024

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.

dnusca avatar dnusca commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.