S
S
shearlocktm2015-10-28 11:20:05
JavaScript
shearlocktm, 2015-10-28 11:20:05

How to develop the structure of a plugin for Wordpress?

Good day.
It is necessary to write a plugin for WP that uses curl to make a request to a third-party server and receive JSON in response. Then, based on the received data, we display this or that content with a shortcode. For each user, the resulting JSON will be different.
The question is mostly in theory: how to write it correctly, use classes or just functions? How to organize it correctly so that the shortcode is triggered only after receiving the data?
PS I will be glad to all kinds of links and thanks.
PSS I have a version of the plugin that works, but it's pure shitty code, but I want to rewrite everything in feng shui)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2015-10-31
@shearlocktm

I personally use this template for my plugins - wppb.io ( https://tommcfarlin.com/wordpress-plugin-boilerplate/).
For a small plugin, the structure may be too comprehensive, but you can study to understand how to do it.
Classes or functions - it's a matter of scaling, classes require more knowledge, and a little more server resources, but it turns out more beautiful and extensible, but functions for small plugins are quite appropriate.
In addition, the code of the functions themselves is important, because you can sort out the gavncode and classify it.
In addition, consider caching or fetching data in Javascript, because if the external server is dumb and takes a long time to respond, your site will also be dumb.

D
Dmitry, 2015-10-28
@dimasmagadan

1 use the APIs that are in WP, it is more
correct to make a request to a third-party server using the HTTP API
https://codex.wordpress.org/HTTP_API But just functions , the question is from the category "which is better - tabs or spaces." use the approach that you are most familiar with. if you have no idea how to organize the plugin, download any of the google for "wp plugin boilerplate". there is nothing particularly unique there, the approach is approximately the same everywhere. differ in the names of functions/classes, paths and folder names
write a condition in the shortcode function,
if there is data - show, if not - do not show

A
Alexander Taratin, 2015-10-28
@Taraflex

PSS I have a version of the plugin that works, but it's pure shitty code, but I want to rewrite everything in feng shui)

There will be no feng shui in wp.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question