M
M
Masha Vorontsova2020-04-19 14:29:45
PHP
Masha Vorontsova, 2020-04-19 14:29:45

How to write code for such a task?

I have a wordpress site.
I want to write a plugin that will perform the following functions:

1 block is displayed on the page (by a shortcode, for example), it displays:

3 buttons - only one of them gives the user 1 point (random)
If the user "guessed" the button, he "gets 1 point ", then this block changes to the next one, where the buttons will be of a different color, the principle is the same.

The task for the user is to guess 3 times and collect 3 points.

I know PHP at the level of intuition and small code changes in WP. Can't figure out where to start? Is it easy to write such code, do you need a framework, and so on.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Sarvarov, 2020-04-19
@megakor

You need to look towards Ajax (using jQuery). In WordPress, jQuery works natively.
After pressing the button, a request is sent to the server, where the server returns a positive or negative result (using (wp_send_json_success/wp_send_json_error).
Depending on this response, jQuery then changes these blocks as you need. Google how to
do it all.

W
WP Panda, 2020-04-19
@wppanda5

On the server side, when you go to the page, generate a hash for the visitor that will be equal to true, save it as you like. When generating on the page, randomly assign it to any of the buttons, 2 more hashes from the same algorithm to 2 others, when sending the button, compare it with the saved one, if it matches then ++, reload the buttons, repeat the process
How to use ajax - https:/ /benmarshall.me/wordpress-ajax-frontend-backend/ tirivial
task 15-20 minutes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question