示例#1
0
 /**
  * Initialize WR Library.
  *
  * @return  void
  */
 public static function init()
 {
     global $pagenow;
     if ('admin-ajax.php' == $pagenow && isset($_GET['action']) && in_array($_GET['action'], self::$actions)) {
         // Init WordPress Filesystem Abstraction
         WR_Megamenu_Init_File_System::get_instance();
         // Register Ajax actions
         switch ($_GET['action']) {
             case 'wr-addons-management':
                 WR_Megamenu_Product_Addons::hook();
                 break;
         }
     }
     // Add filter to fine-tune uploaded file name
     add_filter('wp_handle_upload_prefilter', array(__CLASS__, 'wp_handle_upload_prefilter'));
     // Do 'wr_megamenu_init' action
     do_action('wr_megamenu_init');
 }
示例#2
0
 /**
  * Post-process product update.
  *
  * @param   boolean  $response    Install response.
  * @param   array    $hook_extra  Extra arguments passed to hooked filters.
  * @param   array    $result      Installation result data.
  *
  * @return  void
  */
 public static function upgrader_post_install($response, $hook_extra, $result)
 {
     if (count(self::$plugins)) {
         foreach (self::$plugins as $plugin) {
             if (!empty($plugin)) {
                 // Get plugin base name
                 $plugin_basename = plugin_basename($plugin['Main_File']);
                 if ($plugin_basename == $hook_extra['plugin']) {
                     // Set new last update time
                     update_option("{$plugin['Item_ID']}_last_update", date('D M d H:i:s O Y'));
                     // Finalize plugin update
                     if ('.tmp' === substr($result['destination_name'], -4)) {
                         // Get WordPress Filesystem Abstraction object
                         $wp_filesystem = WR_Megamenu_Init_File_System::get_instance();
                         // Remove existing plugin directory
                         $name = substr($result['destination_name'], 0, -4);
                         if ($wp_filesystem->exists($result['local_destination'] . '/' . $name)) {
                             $wp_filesystem->delete($result['local_destination'] . '/' . $name, true);
                         }
                         // Rename temporary plugin directory
                         $wp_filesystem->move($result['destination'], $result['local_destination'] . '/' . $name);
                         // Re-activate plugin
                         activate_plugin($result['local_destination'] . '/' . $hook_extra['plugin'], '', is_network_admin(), true);
                     }
                 }
             }
         }
     }
 }
示例#3
0
 /**
  * Detect plugin file of installed add-on and activate plugin.
  *
  * @param   string  $addon   Identified name of add-on (as defined in WooRockets server).
  * @param   string  $action  Last executed action.
  *
  * return  void
  */
 protected static function activate($addon, $action = '')
 {
     // Check capabilities
     if (!current_user_can('activate_plugins')) {
         throw new Exception(__('You do not have sufficient permissions to activate plugins for this site.'));
     }
     // Get WordPress's WordPress Filesystem Abstraction object
     $wp_filesystem = WR_Megamenu_Init_File_System::get_instance();
     // Get plugin slug
     $plugin = self::check($addon, false);
     if (empty($plugin)) {
         throw new Exception(__('Cannot detect plugin to activate.', WR_LIBRARY_TEXTDOMAIN));
     }
     // Activate plugin
     $result = activate_plugin($plugin, '', is_network_admin());
     if (is_wp_error($result)) {
         return array('success' => true, 'addon' => $addon, 'action' => $action, 'message' => $result->get_error_message());
     }
 }