在执行wp_cron之前从插件中的操作调用导入类时出现问题

时间:2016-05-16 作者:user3037493

我正在使用wp\\u crontrol插件调用函数中添加的操作。php文件,然后调用插件文件中的函数。WP访问了我的函数,但无法调用该类,我遇到以下错误:PHP致命错误:在xxx中找不到类“RSS\\U Import”

我很确定我调用该类的方式不正确,但我不确定在wp\\u cron调用该类之前如何调用该类。

functions.php

add_action( \'my_hookname\', \'my_function_plugin\' );

plugin_file.php

功能。php\'add\\u action(\'my\\u hookname\',\'my\\u function\\u plugin\');\'

plugin\\u文件。php

if ( !defined(\'WP_LOAD_IMPORTERS\') )
return;

// Load Importer API
require_once ABSPATH . \'wp-admin/includes/import.php\';

if ( !class_exists( \'WP_Importer\' ) ) {
 $class_wp_importer = ABSPATH . \'wp-admin/includes/class-wp-importer.php\';
 if ( file_exists( $class_wp_importer ) )
  require_once $class_wp_importer;
}

/**
 * RSS Importer
 *
 * @package WordPress
 * @subpackage Importer
 */

/**
 * RSS Importer
 *
 * Will process a RSS feed for importing posts into WordPress. This is a very
 * limited importer and should only be used as the last resort, when no other
 * importer is available.
 *
 * @since unknown
 */
if ( class_exists( \'WP_Importer\' ) ) {
class RSS_Import extends WP_Importer {

……….

function dispatch(){
error_log("In Dispatch", 0);
$this->header();
$this->get_posts();
$this->import_posts();
$this->footer();
}//dispath

function RSS_Import(){

}//rss_import
} //end class rss importer
error_log("im not called at all", 0);
$rss_import = new RSS_Import();
register_importer(\'rss\', __(\'RSS\', \'rss-importer\'), __(\'Import posts from the Berkeley Blogs RSS feed.\', \'rss-importer\'), array($rss_import, \'dispatch\'));

} // class_exists( \'WP_Importer\' )





function my_function_plugin() {
$rss_import = new RSS_Import();
register_importer(\'rss\', __(\'RSS\', \'rss-importer\'), __(\'Import posts from the Berkeley Blogs RSS feed.\', \'rss-importer\'), array($rss_import, \'dispatch\'));
}

1 个回复
SO网友:user3037493

我通过放弃并使用wordpress的fetch\\u feed函数解决了自己的问题https://codex.wordpress.org/Function_Reference/fetch_feed

这对我来说很好,因为调用参数时我不必担心时间问题。