WHMCS has a feature for providing downloads to clients. The feature can be found in their admin area at /admin/supportdownloads.php
Is there any action hook for when files are uploaded via the admin area? The only related hook I can find is for when files are downloaded.
What I want do to is add a hook so any file I upload is added to the list of Associated Downloads for each of my products. With all the hook options they have, I'm surprised I can't find one for this...
While I have not done exactly what you are trying to do, I can tell you that anything you put in the /includes/hooks folder gets executed, regardless of whether it is actually hooked into a specific point. This is incredibly useful for those moments where there aren't any hook points available (or they are documented as being present but not on certain page renders).
So in a php file in the /includes/hooks folder, I start by echoing out the globals variable. WHMCS stores a lot of information in the globals variable that easily permits you to deduce which page you are on. For example, in one of my hooks, I have a function that determines what the file name is that I am on simply by calling up get_filename(); That function checks the request URI and finds the php file being called. If the filename is one I'm looking for (for example 'dologin') I can isolate the code being executed. You continue to isolate based on the page you are looking for (for example, if each request has a certain variable, or requires being logged in you look for those variables).
Once you are sure you have to be on the page in order for the code to fire, then you can write your PHP to grab the form posted data and store it how you like in a secondary table. The only catch is if the form must first be stored into the database, so you need a unique identifier, but that can be gotten around also.
Hope that is of help...
Related
In a website I'm working on, a javascript file (and a css too) gets downloaded even if the feature it's related with is not present on the page. Since that plugin doesn't allow to load the files only when needed, I wanted to use a wordpress hook to dequeue them when not necessary.
To know if this scripts are needed, I could check inside the html code if a specific element is present (using regex or another method), but I don't know which hook to use and how to get the html data. Could anyone show me how to do it or even just point me to some documentation about it?
I'm creating a feature for a game and came up with a problem I can't solve on my own. I made an image generator to show the top dogs of guilds from a JS based Discord bot, the script which generates the image is made with PHP and it's on my server. I'd like to be able to call this script, without the resulting URL showing all the details - at the moment it looks like this after a call:
http://www.scam.fi/aow/im.php?m=NBA_-_TOP_3&b=ArkA&c=lenipeni&d=Sandwich&1=7334&2=6978&3=6682
(Don't be afraid of the domain name, I named my Internet storage unit badly). While all those variables are visible, that creates a problem for me since the results are pretty easily modified by anyone. Is there some way I could hide the variables with MOD rewrite or is there some other way?
Is there some way I could hide the variables with MOD rewrite
No. The data, with the approach you are taking, needs to get into the script from the browser.
or is there some other way?
Store the data in a database. Associate it with an ID. Put the ID in the URL.
I am creating a Wordpress plugin for the admin area. It needs to set options and write to a file and database based on the options that are saved.
I have tried creating a "Create File" button which sends POST data back to itself. I now need to create a file and add a column to the database based on a hidden boolean filed.
I'm struggling because I can't do what I want because the form needs to have a different action. Any advice on how to so this?
What a different action? Without any code examples that show what you're doing and what exactly is not working, we only can imagine and give you general info. In Wordpress, you don't have to care about naked url options cause the core will do this for you. Its enough to register the required hooks, read the passed data here and do what is required with them. Simple storing settings wouldn't require to extend the database scheme, since Wordpress already have a table for this. You could use the Wordpress functions here.
See the article of the Wordpress developers page: https://codex.wordpress.org/Creating_Options_Pages
Using the hooks, its no big deal to create a file too. Simple write your PHP code after saving the settings in the database. How you concretely do this depends on the requirements: Is the data passed as form field? Is it fetched from an external source (like api)? Depending on the requirements this should be done with relatively less work using a search engine, cause enough sample codes exists for those scenarios.
I have a website made with WP (a customer passed me). He want to see in one of the pages, a list of product categories, and to get the list of this product categories, I have to send a request to an API in another website. The site will response with an XML that contain the categories. To make the request I will use some PHP library. After the response is arrived, I want to show those categories in the page of my site of my customer.
I have followed the first answer here to call a php file before rendering a template, but imagine that I want to pass a variable (product categories) from the php to to the template. How can I do that?
You will probably want to cache the results of the XML that comes back to you (unless it is truely dynamic), and possibly store it in a table. You can decide how often you need to refresh the cache. (This will protect your site and their API from DOS attacks, or even just high volume).
Once you have your data stored in a table, your template can simply retrieve it.
This pattern will reduce the coupling between the two parts of your solution, and make things a bit easier to build / debug.
I have created a snippet that takes specified code and minifies it, but I'm looking to turn this into a plugin to streamline the process. I'm looking to have the code minify when I save a file, and create a new file in that directory with a new name. I have this working as a snippet, but I don't want to be writing files every time the page is loaded.
Is there a way to check when a file (in the Files Tab/Assets) is saved in ModX, and then execute a plugin? I looked through the existing System Events, and didn't find anything.
Looks like you have 3 system events that may work for you: OnFileManagerUpload, OnFileEditFormPrerender & OnFileCreateFormPrerender. My guess would be OnFileManagerUpload.
Docs here:
http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/plugins/system-events/onfilemanagerupload
Though it's important to note [the last time I checked] that even if a system event is listed in the manager and/or documented, they are not all implemented [i.e. won't work] - best to check on this in the modx forums or dig through the code to see if it actually exists.
Now, you are trying to do this from the manager or some front end form?
In the manager attaching a plugin to the OnFileManagerUpload hopefully works. In the front end you may have to attach your plugin to one of the page rendering events either read the file's time/date or append/prepend a timestamp within the file itself.
[or if you are using formit, you can probably use a custom hook to get the job done as well]