I am looking for a function that will fire a php file when a category is updated. I don't really want to use a plugin, just want a function to go in functions.php. Can anyone point me in the right direction?
Thanks in advance.
Seems there was a function called "edited_category" but this seems to have been renamed to edited_{$taxonomy} .But I can find no documentation on how to use this. Anyone got any Ideas?
You can use edit_category hook
Runs when a category is updated/edited, including when a post or
blogroll link is added/deleted or its categories are updated (which
causes the count for the category to update). Action function
arguments: category ID.
You can add the hook in your functions.php file as given below
add_action ( 'edited_category', 'update_category_function');
function update_category_function( $category_id )
{
// ...
}
Related
I'm using "Advanced Scripts plugin" to modify a function of other plugin, the fuction I'm trying to modify is wrappd with if( !function_exists('some_function') ).
the function inside the plugins is like this
if( !function_exists('send-invoice') ){
function send-invoice(){
//The Plugin Invoice
}
}
This is what I did
function send-invoice(){
//My Custom Invoice
}
add_action('init', 'send-invoice');
How can I make sure that my code runs before the plugin codes?
The plugin load before the theme, I tried plugin-loaded hook but nothing changed
You can to use the anonymous function for example:
add_action('init', function() {
//code here
});
More detail is here
Or use another hook muplugins_loaded:
function send-invoice(){
//My Custom Invoice
}
add_action('muplugins_loaded', 'send-invoice');
If nothing else work for you you can create a custom plugin, name it something like "aaamyplugin" and just insert there a single .php file with the function you are trying to override. This is the easiest (not cleanest) way to make sure your code overrides the plugin functions.
The reason for this is because Wordpress plugin loading order is simply alphabetical, that means that everything named before the plugin you are trying to override, get loaded first.
The cleanest way would be to look into the source code of the plugin to understand how it does what it does. Like: when does it load that file that contains the function you are trying to override? That's the important question to answer if you want to go with clean way
I wrote an "autocomplete" field in archive.php - typing in it calls a function defined in functions.php. Here is a sample of the code:
function ajax_search_archive() {
$term = get_queried_object();
if (!$term) return;
(... continued...)
}
I tried that in a "tag" archive page, then in a "category" archive page. Each time, the function was called, then returned 0 at the second line because the retrieved "get_queried_object" was null - though I expected it wasn't.
Please, what did I wrong?
Thanks again for the comments, which showed me the way to solve my own problem.
The function get_queried_object() seems to work when called in archive.php itself, but not when called from a function defined in another file - even if that other function is called in archive.php. That realization led me to do some updates:
a) in archive.php: retrieving the get_queried_object(), storing its id into a hidden field (e.g. "archive_id)";
b) the Ajax "autocomplete" call in its script: sending the object id as another argument (value retrieved using jQuery - e.g. "$('#archive_id').val()");
c) the function ajax_search_archive in functions.php: retrieving the object id from the POST request.
i'm working on Open Cart 3.0.2.0.
I want to call my own function after someone buy a product from my store. Where i can call this function? I tried to put the test code in catalog/model/checkout/order.php in addOrder and addOrderHistory methods, also in catalog/controller/chekout/confirm.php but it doesn't work.. Can anyone know in which file and method i should put my own code?
There is piece of my test code:
<?php
class ModelCheckoutOrder extends Model {
public function addOrder($data) {
//TEST
file_put_contents('my_directory/test.txt', 'test');
...
Edit: I know that in older versions was Confirm method i Checkout Model, and there u could pass your code, but it disappeared in new versions.
I can put my code in catalog/controller/success.php, but i need to get and pass informations about all ordered products. Any ideas?
Best regards.
I found the answer few days ago. The first option is get order id from session in "success.php" file and work with it.
Or (second option) you can edit files in the system/storage/modification !
I need to delete a transient for all shortcodes located on a post/page when that page is updated. So the page update should delete the transient just for the shortcodes located on that page. If that isn't possible it would help if all shortcode transients are deleted on any page update.
I tried using the save_post action but nothing happens, so I must be doing something wrong.
Also, the problem is that I'm generating a shortcode ID, based on post ID and incrementation of a static variable.
So, only when I call the method to delete a transient in shortcode-template.php I have access to the current page's ID and then I can delete a transient related to page ID/Shortcode ID combination. But then the transient is deleted every time the shortcode is loaded. And if I don't call the delete_transient function, it seems like it is not hooked to save_post action, because nothing happens. I guess that is because the current page ID can't be fetched in a Class but only when used somewhere on the page. But I have no idea how to go around that.
Here is my Class:
class MainClass {
private static $shortcode_increment = 0;
private function __construct() {
add_action( 'save_post', array( $this, 'update_page_delete_transient') );
}
public static function increment_id() {
global $post;
self::$shortcode_increment++;
return 'shortcode_' . $post->ID . "_" . self::$shortcode_increment;
}
// delete the shortcode cache on page update
public function update_page_delete_transient() {
delete_transient( 'weather_'.self::increment_id() );
}
}
Any help is appreciated. Thanks.
UPDATE: I'm not sure how actions should work, as I understand it, the funcion added to the action should be activated when that action occurs, so there is no need to call that function? Or is there? Will the function be added to the action be activated automatically after the Class is instantiated in shortcode-template.php for example, since the action itself is in the construct?
Or do I need to call the delete_transient function in shortcode-template.php in order for it to work? But when I do that, it just runs every time widget is loaded, and not on save post/page.
UPDATE 2: So, if I remove the post ID from the increment ID function, I can badly resolve the issue from update 1 above. Delete_transient function is activated when I create an instance of an object and it is called on page/post save. Now the problem that remains is how do I pass the unique Shortcode ID to delete_transient function, if the ID is increased only in the shortcode-template.php when a new shortcode is created. Or it would be even better if I could somehow pass the Page ID and Shortcode ID somehow to the delete_transient function in the Main Class, so I could delete a specific transient for a specific shortcode on update. Is there a way to pass the data from the shortcode-template.php back to the Object method?
I am not very old on Wordpress.
I am developing a website which has a Third party plugin having class Plugin_Class and there are some filters in the construct of it. I want to hook my additional function to filter Plugin_filter_1 from functions.php.
I have tried with the syntax add_filter( 'Plugin_filter_1', array('Plugin_Class', 'my_function_defined_in_functions_php' ) );,
it gives me error even if the class is visible ( checked with get_declared_classes() )
The detailed answer will be appreciated
Thanks for your help
Regards
Possibly the issue is that your second parameter for add_filter is an array with Plugin_Class as the first element- this means wordpress will try to fire PluginClass::my_function_defined_in_functions_php, which doesn't exist.
Instead, just pass it a string of 'my_function_defined_in_functions_php'.
If this doesn't work with just this edit, show us the code in the plugin class- including the class name and entire construct method. There are more possible issues.