我写了一个Wordpress插件,它在我的本地网站上离线运行得很好,但当我把它投入生产时就不行了?安装效果很好,但激活按钮不起作用。。。是否有人知道如何解决此问题?
感谢您的回答!
更多信息可能,插件使用composer和PhpSpreadReader,我知道它需要一些特定的php库,我在OVH托管!也许服务器上没有安装库?
if (!defined(\'EXCELREADER_TEMPLATE_URL\')) define(\'EXCELREADER_TEMPLATE_URL\', dirname(FILE) . "/templates");
if (!defined(\'EXCELREADER_URL\')) define(\'EXCELREADER_URL\', plugin_dir_url(FILE));
if (!defined(\'EXCELREADER_COMPOSER_URL\')) define(\'EXCELREADER_COMPOSER_URL\', dirname(FILE) . "/vendor");
ini_set(\'max_execution_time\', 300);
include \'vendor/autoload.php\'; require \'includes/class-php-spread-reader.php\'; require \'includes/widget-excel-reader.php\';
add_action(\'plugins_loaded\', \'excelreader\');
add_filter(\'admin_init\', \'check_if_we_should_change_upload_dir\', 999);
//This goes inside Plugin A. //When A is activated. activate B. register_activation_hook(FILE, \'excelreader_activate\'); function excelreader_activate() { $dependent = \'excelreader.php\'; if (is_plugin_inactive($dependent)) { add_action(\'update_option_active_plugins\', \'my_activate_dependent_excelreader\'); } }
function my_activate_dependent_excelreader() { $dependent = \'excelreader.php\'; activate_plugin($dependent); }
// Register and load the widget function wpb_load_widget() { register_widget(\'excelreader_widget\'); }
add_action(\'widgets_init\', \'wpb_load_widget\');
class ExcelReader { /** * * Chemin du dossier où sont sauvegarder les xlsx déja entrée * */ private $dirfxlxs;
/**
* * Instance de la classe PhpSpreadReader * */ private $phpspread;
protected static $instance; public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; } /**
* * Constructeur * */ public function construct() { // Admin page calls: sql_install(); add_action(\'admin_menu\', array(&$this, \'addAdminMenu\')); add_action(\'wp_ajax_store_admin_data\', array(&$this, \'storeAdminData\')); add_action(\'admin_enqueue_scripts\', array(&$this, \'addAdminScripts\')); register_activation_hook(__FILE, array(&$this, \'plugin_activate\')); //add_action( \'init\', array($this,\'load_translation\') ); }
public function plugin_activate() { if (version_compare(get_bloginfo(\'version\'), \'1.0\', \' < \')) { deactivate_plugins(basename(__FILE__)); } else { $rlm_rsvplus_options = array( \'db_version\' => \'1.0\', \'event_name\' => \'\', \'end_date\' => \'\', ); update_option(\'rlm_myplugin_options\', $rlm_myplugin_options); } } /**
* * Display the Plugin on admin menu panel * @return void * **/ public function addAdminMenu() { add_menu_page( __(\'ExcelReader\', \'excelreader\'), __(\'ExcelReader\', \'excelreader\'), \'manage_options\', \'excelreader\', array($this, \'adminLayout\'), \'\' ); }
/**
* Outputs the Admin Dashboard layout containing the form with all its options * Display on Admin Page * @return void */
public function adminLayout() { $this->display_enter_a_file(); /*if(isset($this->phpspread)) $this->phpspread->display_excelfile();*/ // $this->display_wc_categories(); } /**
* * Affichage du formulaire pour le fichier * @return void **/
public function display_enter_a_file() {
// SOME CODE HERE NOT IMPORTANT CAUSE ALL IS WORKING AT THIS LVL }
/** * * Date pour le fichier XLS Sauvegarde * @return string **/
public function getDateAndTime() { $now = new DateTime(); return $now->getTimestamp(); }
/** * * Sauvergarde du fichier dans wp-content/uploads * @return true **/
public function upload_user_file(array $file) { // Check that the nonce is valid, and the user can edit this post. if ( isset($_POST[\'my_image_upload_nonce\'], $_POST[\'post_id\']) && wp_verify_nonce($_POST[\'my_image_upload_nonce\'], \'my_image_upload\') ) { // Let WordPress handle the upload. // Remember, \'my_image_upload\' is the name of our file input in our form above. $this->clean_folder(); $attachment_id = media_handle_upload(\'my_image_upload\', $_POST[\'post_id\']);
if (is_wp_error($attachment_id)) { // There was an error uploading the image. echo "Une erreur est survenu a l\'upload"; ?><br><?php } else { echo "Fichier Upload"; ?><br><?php $this->phpspread = new PhpSpreadReader(); $this->phpspread->read_file_php_spread(); } } else { echo "Probleme durant l\'upload "; ?><br><?php
// The security check failed, maybe show the user an error. } }
/** * * Nettoyer le répertoire du dossier wordpress * @return void **/ public function clean_folder() { $files = glob(wp_upload_dir()[\'path\'] . "/*"); // get all file names foreach ($files as $file) { // iterate files if (is_file($file)) unlink($file); // delete file } }
/** * * Appel des fonctions dans le panel admin * @return void **/ public function addAdminScripts() { } }
ExcelReader::get_instance();