do_action
creates an action hook, add_action
executes hooked functions when that hook is called.
For example, if you add the following in your theme's footer:
do_action( 'my_footer_hook' );
You can echo content at that location from functions.php or a custom plugin:
add_action( 'my_footer_hook', 'my_footer_echo' );
function my_footer_echo(){
echo 'hello world';
}
You can also pass variables to a hook:
do_action( 'my_footer_hook', home_url( '/' ) );
Which you can use in the callback function:
add_action( 'my_footer_hook', 'my_footer_echo', 10, 1 );
function my_footer_echo( $url ){
echo "The home url is $url";
}
In your case, you're probably trying to filter the value based on a condition. That's what filter hooks are for:
function mainplugin_test() {
echo apply_filters( 'my_price_filter', 50 );
}
add_filter( 'my_price_filter', 'modify_price', 10, 1 );
function modify_price( $value ) {
if( class_exists( 'rs_dynamic' ) )
$value = 100;
return $value;
}
Reference
Edit (updated references links)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…