admin管理员组

文章数量:1200423

Assuming that my site uses a database through the web service to fetch content, style and other things for my site. Can we make this connection in a way provided by the CMS? A plugin does that? Should we do it ourselves?

Thanks for answers.

Assuming that my site uses a database through the web service to fetch content, style and other things for my site. Can we make this connection in a way provided by the CMS? A plugin does that? Should we do it ourselves?

Thanks for answers.

Share Improve this question asked Apr 22, 2022 at 7:06 JonathanJonathan 514 bronze badges 9
  • 1 A "web service" could be literally anything. What are you actually trying to do? – Jacob Peattie Commented Apr 22, 2022 at 8:17
  • Hi, I have a database. I have a web service that has database management functions to handle the content and users I have. I would like to use a Wordpress site to display the content. I have tried to program a widget that would do this, but it is not really appropriate. The problem with the widget is its area and the fact that it doesn't affect the content of the site in general but only itself. I would like to know if a widget/plugin can change the structure of the site and its content. If so, how can I do it? – Jonathan Commented Apr 22, 2022 at 8:21
  • 1 Sorry but I'm having trouble understanding what you're trying to do, because if the content and users are external, I don't see what the point of using WordPress is? WordPress has its own database for content and users and isn't designed to work with arbitrary external services. You would have to implement any importing or syncing of that data to WordPress yourself entirely from scratch and doing that would be well beyond the scope of a single question on this site. – Jacob Peattie Commented Apr 22, 2022 at 9:44
  • Maybe you are right, I just saw your profile, how long have you been coding with Wordpress? What can you tell an amateur like me about the possibilities of Wordpress plugins? – Jonathan Commented Apr 22, 2022 at 14:19
  • 2 Plugins can do just about anything. It may help to read up on developer.wordpress.org/plugins/intro and get a basic understanding of the CMS. Sometimes it does make sense to integrate multiple sites, but if you have an existing setup of content and users, it more likely makes sense to either keep that or else migrate everything to WP and have WP manage everything moving forward. What benefits of WP are you trying to gain? – WebElaine Commented Apr 22, 2022 at 18:49
 |  Show 4 more comments

2 Answers 2

Reset to default 2

Yes, you can write php code, potentially in the form of a plugin, to access a remote web service.

Presumably you want to use a web service accessed via https (or http). WordPress provides the wp_remote_request() function to do that. You can call it from your php code (in your plugin). When your server runs that function, it will retrieve a result from your web service. You can then use it as needed. Notice this is server-side code, not client-side.

Or you can use the simpler wp_remote_post() or wp_remote_get() functions if they work for your web service.

Edit You can write a plugin, but that takes software-engineering work to make it integrate cleanly with your site.

You can use the Code Snippets plugin to insert a little chunk of php. That's ok for development and experimentation, but a sizable security risk in production (or in dev for that matter).

Some suggest editing your theme's functions.php file to add a bit of code. But I don't suggest that approach: theme updates will make your changes vanish.

You didn't mention what you want to do with the result you get back from your webservice, so it's hard to recommend which hook you should use to invoke your code.

The answer to the current question is found. Thank you all for your answers.

The answer to the question is 'yes'. We can use an external webservice/API in the Wordpress code. We can use for this, wp_remote_request to call through an URL. For my part, I did otherwise because my webservice is a special one, so I created a SoapClient class in the files of my plugin to make the connection and the function calls.

To provide a correct display of the webservice, I decided to use 2 widgets. 1 for the search and 1 for the display. I still have some problems with the display with the web page but that will be another issue. Thanks again.

本文标签: pluginsCan we use a webservice with Wordpress