I am trying to write a script that calls the function clear_single_feed_cache() within a class CFF_Feed_Saver_Manager from a wordpress plugin but cannot get it to work. I am not sure if this is because the function I am trying to call has another class within the function. please help. Here is the class and function I am trying to call and below that is my code trying to call that function.
Class & function:
<?php
namespace CustomFacebookFeedBuilder;
use CustomFacebookFeedAdminTraitsCFF_Feed_Templates_Settings;
use CustomFacebookFeedSB_Facebook_Data_Encryption;
use CustomFacebookFeedSB_Facebook_Data_Manager;
use CustomFacebookFeedCFF_Events_Parser;
class CFF_Feed_Saver_Manager {
use CFF_Feed_Templates_Settings;
public static function hooks() {
add_action( 'wp_ajax_cff_feed_saver_manager_clear_single_feed_cache', array( 'CustomFacebookFeedBuilderCFF_Feed_Saver_Manager', 'clear_single_feed_cache' ) );}
public static function clear_single_feed_cache() {
$feed_id = '12';
$feed_cache = new CustomFacebookFeedCFF_Cache( $feed_id );
$feed_cache->clear( 'all' );
$feed_cache->clear( 'posts' );
}
} ?>
My Code:
add_action( 'run_cff_clear_feed', 'myCFFclearFeed');
function myCFFclearFeed() {
require_once '/var/www/wp-content/plugins/custom-facebook-feed-pro/inc/Builder/CFF_Feed_Saver_Manager.php';
require_once '/var/www/wp-content/plugins/custom-facebook-feed-pro/inc/CFF_Cache.php';
$object = new CFF_Feed_Saver_Manager();
$object->clear_single_feed_cache();
} ?>
6
Thanks @ChrisHaas for figuring it out. The solution was to use the fully qualified class name and since it was a static function the correct code was:
<?php
add_action( 'wp_ajax_nopriv_run_cff_clear_feed', 'myCFFclearFeed');
function myCFFclearFeed() {
require_once '/var/www/wp-content/plugins/custom-facebook-feed-pro/inc/Builder/CFF_Feed_Saver_Manager.php';
require_once '/var/www/wp-content/plugins/custom-facebook-feed-pro/inc/CFF_Cache.php';
CustomFacebookFeedBuilderCFF_Feed_Saver_Manager::clear_single_feed_cache();
}
?>
1