Symfony backend to Wordpress frontend - wordpress

is there a way to send Symfony’s data from its action to Wordpress page?
For example Symfony’s action returns an array and in a Wordpress page I could iterate it?

Wordpress use template that are basic php file.
So you can make request to any rest api you want you using php. You can use your symfony rest api if you want.
Simply go in wordpress create pages and create template that will make your request to Symfony and display what you need.
It's really not recommanded but for a special case it could be possible.
You maybe should take the time to simply move your data in the wordpress DB.

Related

Wordpress plugin service page

have spent hours of researching understanding the correct approach for developing plugin for wordpress which does have custom "service" URL.
So far done:
plugin registers custom capabilities and role
inits the db and entries using $wpdb
create rest-api hook that could be used with JS
Should do:
Only the users with custom role "service" shall have access to a service dashboard.
the service dashboard shall make use of $wpdb to query data from the db.
I am looking badly for a simple example to learn from which shows a custom page that isn't integrated into WP posts or the admin panel.
Something that does check current user and allow access for given role to e.g. "www.awesome-wp-page.com/myplugin/main" and load some further data later as e.g. "www.awesome-wp-page.com/myplugin/stats/1234"
Originally I wanted WP to query the data via its own custom restapi, but also did not find any examples that query rest-api within WP (providing nonce etc) as simple example.
I found a lot examples for admin panels, adding links to post etc, but to my surprise not really some examples which do load simple (form) page or do a quick custom DB query and show the results on a static link.
Any help is appreciated

Get recent wordpress posts in Laravel

I have a Wordpress site and a Laravel site and I want to display recent wordpress posts in the footer of Laravel site. How can I do this without having my wordpress database information in my config/database.php file and using it in the models? Can I get them using RSS?
Recent WordPress was released with a huge thing called REST API – earlier it was possible only with external plugins. So now we can query WordPress database from external projects. Including Laravel.
set up a local WordPress website, and after installation you got that usual dashboard.
we can already make API calls after installation. No need to configure anything, we just launch the URL in the browser:
we’ve received a JSON with a list of posts – by default, WordPress creates one dummy post.
Basically, URL structure for the API calls is simple:
/wp-json/wp/v2/[endpoint]?[parameters]
Yes, you’ve read it right, we can get posts, categories, tags and other things that are publicly available, so we don’t need any authentication here.
And we also can filter the data with GET parameters, like this:
/wp-json/wp/v2/posts?per_page=2&orderby=title
For more details open link:- Using WordPress REST API in Laravel
You can get the posts by calling an API endpoint:
yoursiteurl/wp-json/wp/v2/posts
It will return all the posts in a json format. You can also see the reference from here.

Headless CMS: Wordpress Rest-API – Add links to existing posts/pages

We want to use the Wordpress Rest-API to build a page decoupled from the backend. A few things still bother us though:
Within the wordpress backend one can add links in the content editor of a page or a post and one gets normally a list of all existing pages and posts of the same page to link to them. By decoupling the backend it does not know the exact urls to other pages and we need to provide this. Is there a possibility to tell wordpress what links are available?
Thanks in advance.
Cheers
For those looking for the answer:
There are two URL settings under Settings > General.
WordPress Address (URL) should be the URL for your api site. Like api.whatever.com.
Site Address (URL) should be the URL for the frontend. Like www.whatever.com.
This allows the internal linking to work properly in the Editor while keeping the backend site on a separate URL from a headless frontend.
I'm not sure what you're trying to ask. The WordPress REST API just provides a way to access posts, etc. from somewhere else part from the web site side (e.g. themes, etc). Pages would still be accessible from the admin backend and the JSON/REST API: https://developer.wordpress.org/rest-api/reference/pages/
Specifically with WordPress you could ensure that you're not rewriting the permalinks. That way they are all still site.com/?p=post-id
That way it's easy to parse fetch the new pages. Then replace the hrefs with whatever your frontend needs.
You could use the ID to fetch the slug of the new post immediately.
Or you could even keep a mapping in your presentation layer of IDs to your own slugs.
Changing the site_url doesn't work for me.
Since I also have a wordpress theme with custom rest controllers
Plus the wp-json breaks if I change the site url
My backend is hosted at digital ocean app
My frontend is hosted at vercel
I fixed it by using a wordpress plugin called make-paths-relative
But since my backend doesnt know where my frontend is I added one change within the plugin at:
frontend/class-make-paths-relative.php line 123
I added a constant FRONTEND_URL which i define in the wp-config
$relative_link = FRONTEND_URL.$link;
This changes both the permalink within my backend of a post, page or cpt
And changes internal links as wel, links within the content editor
I made a request to the plugin author as well

Wordpress retrieving data from Cakephp

I run a website where I have both Wordpress and Cakephp installed in the same domain.
Cakephp is the administrative backend to maintain and create business listings (like the yellow pages).
Wordpress is the front end for the public website.
I'm creating custom Wordpress templates to display the business listings from Cakephp, but am not sure how Wordpress is going to retrieve data from Cakephp.
I already have a bunch of Controller Actions that return json array with data that I would like to call from Wordpress. I don't want to duplicate in Wordpress data retrieval code that I've already written in Cakephp. But i'm not sure how in Wordpres would i make calls to these Cakephp Controller / Actions.
What is the recommended / best way to have Wordpress retrieve data from the Cakephp backend given at they are on the same domain? What other options do i have?
What is the recommended / best way to have Wordpress retrieve data
from the Cakephp backend given at they are on the same domain? What
other options do i have?
Access the DB directly, I'm not sure how to do that with Wordpress fugly API and code, but I'm pretty sure you can instantiate a new DB object with a connection to the CakePHP apps database. The WP API documentation will tell you how to do it I guess, if not it sucks more than I thought.
An alternative would be to expose the data via a RESTful service and consume it from Wordpress. If you return JSON you could even simply use a JS widget on a WP page to retrieve and render the data with pure JS.
As burzum suggested you have 2 real options.
WordPress does have a class for interacting with a DB called WPDB and will give you access to a few ways of querying the data in your CakePHP app. WordPress WPDB Class. It is by no means perfect but will do the job.
However you much better creating a custom WordPress plugin to parse and format the JSON as burzum suggested interacting via your own API. You could then if needed make this a 2 way communication allowing your WordPress install to make changes as necessary to yoru Cake app.

How is the URL routing handled in Wordpress?

I am trying to understand how URL dispatching in Wordpress backend occurs? I asked a related question: How to find php file or function that generates a wordpress admin page?
One answer said that I need to search in the code for some unique text that is rendered in the output. I was expecting some logical mechanism such as the url dispatching or routing mechanism in Rails or Django. Isn't there a similar mechanism in Wordpress?

Resources