(WP) Override Plugin Function In Theme Functions - wordpress

How to override function inside plugin and put in theme functions.php file? I've try using remove_filter and add_filter, apply_filter, add_action etc, but still not worked.
https://github.com/mikejolley/WP-Job-Manager/blob/master/wp-job-manager-template.php#L72
I want to override function on line 72. How can I done this? I don't want to edit plugin files because I just want this function replaced only when this theme activated. If not activated, function will be as the original function.

This function used by plugin. And no any filters or actions inside. So, my sorry, you can't solve this issue.

Related

woocommerce_checkout_create_order_line_item not overriding

woocommerce_checkout_create_order_line_item
This hook is already overridden in WooCommerce subscriptions but I want to make a few changes in it. so, I added the same hook in function file but not able to override the same. Is it even possible?
I tried the same in function file but didn't work.

Woocommerce template not overriding

I am trying to override a woocommerce plugin but somehow it wont work.
In my custom theme I added the following in functions.php
function add_theme_wc_support() {
add_theme_support('woocommerce');
add_theme_support('woocommerce-composite-products');
}
add_action('after_setup_theme', 'add_theme_wc_support');
The directory for my template:
theme\templates\woocommerce-composite-products\single-product\template-file.php
I edited the template but nothing happened. I also tried to change the folder "woocommerce-composite-products" to just "woocommerce" but nothing.
My functions.php only contains the "add_theme_wc_support" function, so there cant be any conflicts.
How can I make this work?
Going by the comment you provided about how the plugin wants you to override the template your file path should look like this

Theme Action to hook for one time only function

I am developing a custom theme. After my theme is activated/installed I need to run a one time only function that will set some options. What is the best action to hook for this?
Should I use after_setup_theme? My understanding is that this event/action fires on each page load so I don't think I should use this action correct?
*Ps: is it best to place this code in my functions.php file or somewhere else? (I am using the underscores theme template).
You should look at after_switch_theme action. It'll fired only on your theme activation( just one time ). So, your one time function will look:
add_action('after_switch_theme', 'my_one_time_function');
function my_one_time_function () {
//Your code
}
Code goes to functions.php file.
P.S. If you want to run some function before deactivating theme, you can use switch_theme hook. It has same use as after_switch_theme.

Where to put add_action() in WordPress

I am new to WordPress. I was referring to code of WordPress theme. I am confused about where to put our function and add_action() for that function.
I want to know whether it is right to define function and add_action in one PHP file and put it anywhere in our theme folder.
"functions.php" is the file where you want to put your custom functions, hooks and actions. If your theme doesn't have a functions.php just create it. Wordpress will get the contents of it automatically, so you will have access to defined functions anywhere in your theme.

I can't seem to override a function using template.php

I'm trying to alter the comment links in my Drupal output, and I think I have found the function I want to influence, which is function comment_node_view($node, $view_mode).
It is in the Comment module. The problem is I can't seem to effect it, when I try to override it by putting it in my Template.php file and add my theme_ to the function name? In my template.php it looks like this now:
function themename_comment_node_view($node, $view_mode)
if I take off the themename_ it causes an error saying I can't redeclare it. I can copy the comment module and edit it directly but I thought this was how I theme something?
Drupal themes can only implement theme functions (which include template preprocess and process functions) or alter hooks.
comment_node_view() is a hook, but it's not an alter hook (differently the hook name would end with "_alter").
Why cannot themes implement hook_node_view()?
Because hook_node_view() is invoked in comment_build_comment() using the following code:
// Allow modules to make their own additions to the comment.
module_invoke_all('comment_view', $comment, $view_mode, $langcode);
module_invoke_all('entity_view', $comment, 'comment', $view_mode, $langcode);
As it is also highlighted from the comment, module_invoke_all() invokes the hooks implemented in modules, not themes.
If you want to change how a comment is rendered, from a theme, you should create the comment.tpl.php template file for your theme.
The name spacing is 'hook_node_view' so you need to replace 'comment' (the name spacing used by the comment module) with your theme name:
function mytheme_node_view($node, $view_node)
Hooks:
http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7
hook_node_view:
http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_node_view/7
Hope that helps :)

Resources