Exemple #1
0
 /**
  * Initialize WR Library.
  *
  * @return  void
  */
 public static function init()
 {
     global $pagenow;
     // Register Ajax actions
     if ('admin-ajax.php' == $pagenow && isset($_GET['action']) && in_array($_GET['action'], self::$actions)) {
         // Init WordPress Filesystem Abstraction
         WR_Pb_Init_File_System::get_instance();
         // Register Ajax actions
         switch ($_GET['action']) {
             case 'wr-addons-management':
                 WR_Pb_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_init' action
     do_action('wr_pb_init');
     // Register 'wr_sample_settings_url' filter
     add_filter('wr_pagebuilder_settings_url', array(__CLASS__, 'settings_url'));
 }
 /**
  * Get all available data converters.
  *
  * @return  array
  */
 public static function get_converters()
 {
     global $post;
     // Initialize WordPress Filesystem Abstraction
     $wp_filesystem = WR_Pb_Init_File_System::get_instance();
     // Get available data converter
     $files = $wp_filesystem->dirlist(dirname(__FILE__));
     $converters = array();
     foreach ($files as $file) {
         if ('converter.php' != $file['name']) {
             $converter = substr($file['name'], 0, -4);
             // Generate data converter class name
             $class = explode('-', $converter);
             $class = array_map('ucfirst', $class);
             $class = 'WR_Pb_Converter_' . implode('_', $class);
             if (class_exists($class, true)) {
                 // Check if there is data to convert
                 if (call_user_func(array($class, 'check'), $post)) {
                     $converters[$converter] = ucwords(str_replace('-', ' ', substr($file['name'], 0, -4)));
                 }
             }
         }
     }
     // Allow 3rd-party plugin to hook into data conversion
     $converters = apply_filters('wr_pb_get_data_converters', $converters);
     return $converters;
 }
Exemple #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_Pb_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());
     }
 }