So I have a view called "export-spreadsheets". When an admin goes to this page, I want a function to be called so that it basically runs a long SQL query and exports its results to a CSV.
I was wondering where I would add this function to be called?
Thanks.
Make a custom module, add on to the *_menu() hook, make it call the function when you go to a certain url. Have it output the .csv file and die()
Related
I have customized some wp-option return values with the dynamic pre_option_{option} hook and for completeness would like to also override these option values when they are returned via wp_load_alloptions(). This function has a hook that is available to allow for this customization: pre_cache_alloptions.
However, although the hook exists there doesn't appear to be any way to call add_filter("pre_cache_alloptions", ...) early enough for it to take effect before the first call to wp_load_alloptions(). Since wp_load_alloptions() is called very early when loading WordPress, and since the values are cached on first-call, I haven't been able to register the hook in time for it to take effect. I have tried calling add_filter("pre_cache_alloptions", ...) during a mu-plugin load and also in a custom theme functions.php file, but neither of those places appear to hook in early enough for this to work.
The only solution I have found so far is to hack the actual wp-includes\plugin.php file and add in the add_filter("pre_cache_alloptions", ...) call right after the require of class-wp-hook.php at the top. This does work as expected when registered at that code point... but I'm searching for a way to register this filter so that it works without altering the core WordPress code.
Since this hook must be registered after the add_filter() function is declared in plugin.php, but before the first call to wp_load_alloptions(), the only user-customizable code point that appears to work is the optional custom db.php file, which is loaded in wp-settings via require_wp_db(). Adding a custom wp-content/db.php file with the necessary add_filter("pre_cache_alloptions", ...) reference at the top works as a means to register this customization in time for it to be useful. After much searching, this appears to be the only way to handle this without mucking with the core itself.
How to execute a PHP script after saving a form data from Joomla 3x Banner component?
What I want to achieve is to run a push notification after saving ads in Joomla banner component. The push works well when I run it off Joomla platform, but I don't know where to place the code so that it can execute upon saving the form.
You will need to override the save method of the banner's model. Here's how you can override the model: https://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core
Once you override the model, you will need to modify the save method of the overridden file to suit your requirements.
I am new to plugin development/editing with Wordpress. I am using a famous plugin called Polylang for multilingual support.
And I am using another plugin called Clean and Simple contact form for creating an AJAX based contact form.
Now, looking into the documentation for Polylang I have found the following function:
Register String
Allows plugins to add their own strings in the “strings translation” panel. The function must be called on admin side (the functions.php file is OK for themes).
Usage:
pll_register_string($name, $string, $multiline);
As it says, function must be called on admin side. I am unable to figure out what that means ...
I intend to add a few custom strings to the strings translation tab. Calling this function from functions.php in the theme worked but didn't translate strings from the plugin. The plugin doesn't yet support Japanese so I am having to take this path.
Can you tell me where exactly am I supposed to call this function. I tried to call it in class.view.php and the file with the name: clean-and-simple-contact-form-by-meg-nicholas.php
But, both ended up giving a fatal error saying that the function is undefined. What's the exact meaning of "The function must be called on admin side of a plugin..."
Thanks and Regards !
You might need to adjust your ajax plugin, so the function gets called in the admin. (I don't really know the ajax plugin but I am sure that there is some configuration part, which will be called somewhere in the admin panel)
Another way would be to create another plugin, which is just taking care of that function call. Just be sure, that this new plugin has some link you can call from the admin, so it is run in the right userspace.
I'd like to include a script to detect $_GET values on certain pages of the site. If I use the script in header.tpl, it will add the script on all pages. If I use it as a template file and display it as Layout in the Extensions > Modules, it gets added to all the pages within that Layout. Is there a way to include this only on certain selected pages? I'm sure this will have to done programatically. Just wanted to find out if there is an elegant way to do this.
You can access the $_GET files using the correct method of $this->request->get in any of the controller, model or view files. As for an elegant solution, that really depends on which pages you want it to show on and also what region of the page. For example, if you only want to use code on the product pages, but want to have the code placed in the header, you would need to check for the route to be product/product in your header.php controller in the index() method, then pass the data to the template using $this->data['your-variable'] = $some_data;. Similarly, this would be almost the same on a product page using the product.php controller and skipping the route check since that controller will only be called on product pages
Due to some custom modifications in the hierarchical_select module I need to be able to override the the taxonomy_field_validate function in the core taxonomy module.
I've tried creating a function in a custom module called MYMODULE_taxonomy_field_validate which it doesn't pick up on and I tried changing the field settings, but that changes how the data is stored in the database and it needs to be kept as a taxonomy term.
Any other ideas?
You need to unset this function on form validation.
In your module, write a hook_form_alter implementation and write this code inside
unset($form['#validate']['taxonomy_field_validate']);
Hope this works.