激活插件按钮不执行任何操作

时间:2019-03-21 作者:Oliver

我写了一个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();

1 个回复
最合适的回答,由SO网友:Oliver 整理而成

好吧,问题出在我的主机上,更多的是我的愚蠢,生产中使用的php版本错误。。。

相关推荐

Testing Plugins for Multisite

我最近发布了一个WordPress插件,它在单个站点上非常有效。我被告知该插件在多站点安装上不能正常工作,我理解其中的一些原因。我已经更新了代码,现在需要一种方法来测试更新后的代码,然后才能转到实时客户的多站点安装。我有一个用于测试的WordPress安装程序的单站点安装,但需要在多站点安装上进行测试。根据我所能找到的唯一方法是在网络上至少有两个站点来安装整个多站点安装,以测试我的插件。设置WordPress的整个多站点安装是插件开发人员的唯一/首选方式,还是有更快的测试环境可用。