• We know that we can launch scripts, files of various extensions through scheduling means, with resources such as wp cron, or directly by the linux cron job, where most of the applications are based to take some action.

    ?But I have an old doubt …
    ?
    ??I have a plugin that like most plugins, owns your page in wordpress dashboard

    ??And in this your page, there are elements necessary to execute the action that the plugin was proposed to do:

    ??An import plugin, which has on your page, these 3 elements:

    ??A search bar to promote a search (obviously we must auto fill with the value that refers to the type of content we want to import to each hour),

    ??A search button.

    ??An import button.

    ??Then this page has the name of page.php inside the plugin folder .. how would I do to perform this action in the plugin?

    ?I always modify my preferred plugins, leave checked by default, those questions that I’m used to using on all websites, a form for example, I open the plugin zip and search for the words using grep via command line, and always find in the code, those Plugin options that I usually check or uncheck or leave pre-filled fields by default. How much I install the plugin, it already is how I like it ??

    ?But of course I will not fill the plugin page with a single value, if I want it to fire every hour with a different search, let’s say I want 24 different searches, one for each hour of the day (60 Minutes in cron).

    ??How is this done? Should we create 24 .php files inside the plugin folder, and call the page.php plugin file and have those fields filled with the different word of each subject that we should fetch in each hour? How does this work?

    ??Every 60 minutes, a different file will come with a different keyword in the plugin and click search on the import button? Or will the file call the function of the plugin and to auto-fill these fields from our own files.php? I have no idea how this works!

Viewing 3 replies - 16 through 18 (of 18 total)
  • Moderator bcworkz

    (@bcworkz)

    24 PHP files!? Ugh! Even if that would work (it could), there’s certainly a better way. You need not be too concerned with the form, more where it submits its data. Your script would mimic the form submit. Don’t forget, the form is sitting on the user’s browser, your script is running on the server.

    Ideally you should find the function that processes the submitted data and call that function directly, passing whatever data it needs. This may mean assigning values to certain $_POST elements. While we normally only get data from $_POST, it can be set as well. This ought to work just fine since I believe the search request is sent by Ajax and WP Ajax requires a callback function.

    In the case when the form is submitted to a code page and not a function, and that page actually processes the data, instead of just relaying to a function, then you will need to make an HTTP POST request to that page as if your request came from the form. This is how hackers brute force attack our login forms. They don’t fill out the form, they POST a request like it came from the form. This can be done many dozens of times per second. If they actually filled out the form, only a few requests per second could be accomplished.

    So now we need data to supply as search terms as part of our virtual “form” we are submitting. This is essentially just a list of data that PHP can access to get what terms to search for next. This can be any convenient, persistent form. The most likely places are either a text file or the database. Your script will need to keep track of where it is in the data so in the next hour, it can pick up where it left off. I’m currently leaning towards database storage since we are more familiar with getting and setting data there than in a text file.

    Everything can be stored in one big array. It can be stored in the settings table, or you could even create your own table, in which case individual values make more sense than an array. Your script will also need to save where to pick up again, such as an array or table index. You can add the data by defining a large array of data in PHP, then either saving it as a setting, or writing to your table one row at a time.

    Or if you are making our own table, you could manually create an .sgl import form, then import it into the DB. If you create the table in phpMyAdmin and populate a few rows, then export it, you will have a properly formatted file in which you can add the remaining data in a text editor, then import all the data when you’re done. Be cognizant of how long each INSERT query is, there is a maximum length of characters for any SQL query. I don’t know how long that really is. In examining a backup file, a couple samples were around 40k characters, so I suspect the absolute maximum is 2^16 (around 65k).

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Hi BCWorkz. Thank you so much… I’m taking a long time to answer, because I’m studying for this plugin, I did a chronological summary of his tips, which are very descriptive, and I’m studying to understand them at the level of writing, to start writing the plugin, I confess that I do not have the ability to start writing, I’m studying more PHP, for as long as I have, to understand. Now I am confused, but for simple deficiencies in basic knowledge.

    I’m studying and I’ll call you as soon as I can write something acceptable.
    To 3 days ago, I came to a solution, and with some simple changes, I got my solution. To have the albatross alt in all my images automatically, I found a code and I was able to adapt to my needs, thanks to the base I already have, and a lot of things I learned from you, but I do not understand the points about the auto Rum to script, and I really want to be able to figure out how to work this process, I’m studying and I’m coming back here as soon as I’m able to get something worthy of at least its correction.

    I’m going to study to write a file for each key word, and after the cron job, to have a different script run at different times, it’s something I think is simpler, first I have to think about simpler things, make things happen , When able to make improvements. Thanks all.

    Moderator bcworkz

    (@bcworkz)

    A good approach! I do that all the time when I want to study a particular feature or process. Setup a very basic, simple test page. Depending on what I want to study, even that becomes a learning experience! I include a lot of debugging output so I can see how the data changes as the process proceeds. I then experiment with different inputs to see how different inputs affect output.

    Sometimes the test code is rearranged or altered in different ways so all these variations can be considered. After a while I usually know a lot more about the subject than I initially did. On rare occasions I am just more confused. I guess some things are just not meant for me to know.

    WP Cron is difficult to fully grasp. While I know enough to make use of it, I could not explain in detail how it really works. Like many things WP, it works off action hooks. WP maintains a list of event action hooks and times for execution. Anytime a request is made, this list is checked for event times that have recently come to pass. When any are found, the associated action is fired by calling do_action(). I’m not exactly sure how WP actually manages all of this, but this is all you really need to know about it, aside from writing code to utilize it.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘How to auto run a search plugin, doing a different search every hour?’ is closed to new replies.