public function load_first()
 {
     $plugin_dir = AvadaRedux_Helpers::cleanFilePath(WP_PLUGIN_DIR) . '/';
     $self_file = AvadaRedux_Helpers::cleanFilePath(__FILE__);
     $path = str_replace($plugin_dir, '', $self_file);
     $path = str_replace('class.avadaredux-plugin.php', 'avadaredux-framework.php', $path);
     if ($plugins = get_option('active_plugins')) {
         if ($key = array_search($path, $plugins)) {
             array_splice($plugins, $key, 1);
             array_unshift($plugins, $path);
             update_option('active_plugins', $plugins);
         }
     }
 }
Ejemplo n.º 2
0
 public static function init()
 {
     $dir = AvadaRedux_Helpers::cleanFilePath(dirname(__FILE__));
     // Windows-proof constants: replace backward by forward slashes. Thanks to: @peterbouwmeester
     self::$_dir = trailingslashit($dir);
     self::$wp_content_url = trailingslashit(AvadaRedux_Helpers::cleanFilePath(is_ssl() ? str_replace('http://', 'https://', WP_CONTENT_URL) : WP_CONTENT_URL));
     // See if AvadaRedux is a plugin or not
     if (strpos(AvadaRedux_Helpers::cleanFilePath(__FILE__), AvadaRedux_Helpers::cleanFilePath(get_stylesheet_directory())) !== false || strpos(AvadaRedux_Helpers::cleanFilePath(__FILE__), AvadaRedux_Helpers::cleanFilePath(get_template_directory_uri())) !== false || strpos(AvadaRedux_Helpers::cleanFilePath(__FILE__), AvadaRedux_Helpers::cleanFilePath(WP_CONTENT_DIR . '/themes/')) !== false) {
         self::$_is_plugin = false;
     } else {
         // Check if plugin is a symbolic link, see if it's a plugin. If embedded, we can't do a thing.
         if (strpos(self::$_dir, ABSPATH) === false) {
             if (!function_exists('get_plugins')) {
                 require_once ABSPATH . 'wp-admin/includes/plugin.php';
             }
             $is_plugin = false;
             foreach (get_plugins() as $key => $value) {
                 if (is_plugin_active($key) && strpos($key, 'avadaredux-framework.php') !== false) {
                     self::$_dir = trailingslashit(AvadaRedux_Helpers::cleanFilePath(WP_CONTENT_DIR . '/plugins/' . plugin_dir_path($key) . 'AvadaReduxCore/'));
                     $is_plugin = true;
                 }
             }
             if (!$is_plugin) {
                 self::$_is_plugin = false;
             }
         }
     }
     if (self::$_is_plugin == true || self::$_as_plugin == true) {
         self::$_url = plugin_dir_url(__FILE__);
     } else {
         if (strpos(AvadaRedux_Helpers::cleanFilePath(__FILE__), AvadaRedux_Helpers::cleanFilePath(get_template_directory())) !== false) {
             $relative_url = str_replace(AvadaRedux_Helpers::cleanFilePath(get_template_directory()), '', self::$_dir);
             self::$_url = trailingslashit(get_template_directory_uri() . $relative_url);
         } else {
             if (strpos(AvadaRedux_Helpers::cleanFilePath(__FILE__), AvadaRedux_Helpers::cleanFilePath(get_stylesheet_directory())) !== false) {
                 $relative_url = str_replace(AvadaRedux_Helpers::cleanFilePath(get_stylesheet_directory()), '', self::$_dir);
                 self::$_url = trailingslashit(get_stylesheet_directory_uri() . $relative_url);
             } else {
                 $wp_content_dir = trailingslashit(AvadaRedux_Helpers::cleanFilePath(WP_CONTENT_DIR));
                 $wp_content_dir = trailingslashit(str_replace('//', '/', $wp_content_dir));
                 $relative_url = str_replace($wp_content_dir, '', self::$_dir);
                 self::$_url = trailingslashit(self::$wp_content_url . $relative_url);
             }
         }
     }
     self::$_url = apply_filters("avadaredux/_url", self::$_url);
     self::$_dir = apply_filters("avadaredux/_dir", self::$_dir);
     self::$_is_plugin = apply_filters("avadaredux/_is_plugin", self::$_is_plugin);
 }
 public function do_action($action, $file = '', $params = '')
 {
     if (!empty($params)) {
         extract($params);
     }
     global $wp_filesystem;
     if (!isset($params['chmod']) || isset($params['chmod']) && empty($params['chmod'])) {
         if (defined('FS_CHMOD_FILE')) {
             $chmod = FS_CHMOD_FILE;
         } else {
             $chmod = 0644;
         }
     }
     $res = false;
     if (!isset($recursive)) {
         $recursive = false;
     }
     //$target_dir = $wp_filesystem->find_folder( dirname( $file ) );
     // Do unique stuff
     if ($action == 'mkdir') {
         if (defined('FS_CHMOD_DIR')) {
             $chmod = FS_CHMOD_DIR;
         } else {
             $chmod = 0755;
         }
         $res = $wp_filesystem->mkdir($file);
         if (!$res) {
             wp_mkdir_p($file);
             $res = file_exists($file);
             if (!$res) {
                 mkdir($file, $chmod, true);
                 $res = file_exists($file);
             }
         }
     } elseif ($action == 'rmdir') {
         $res = $wp_filesystem->rmdir($file, $recursive);
     } elseif ($action == 'copy' && !isset($this->filesystem->killswitch)) {
         if (isset($this->parent->ftp_form) && !empty($this->parent->ftp_form)) {
             $res = copy($file, $destination);
             if ($res) {
                 chmod($destination, $chmod);
             }
         } else {
             $res = $wp_filesystem->copy($file, $destination, $overwrite, $chmod);
         }
     } elseif ($action == 'move' && !isset($this->filesystem->killswitch)) {
         $res = $wp_filesystem->copy($file, $destination, $overwrite);
     } elseif ($action == 'delete') {
         $res = $wp_filesystem->delete($file, $recursive);
     } elseif ($action == 'rmdir') {
         $res = $wp_filesystem->rmdir($file, $recursive);
     } elseif ($action == 'dirlist') {
         if (!isset($include_hidden)) {
             $include_hidden = true;
         }
         $res = $wp_filesystem->dirlist($file, $include_hidden, $recursive);
     } elseif ($action == 'put_contents' && !isset($this->filesystem->killswitch)) {
         // Write a string to a file
         if (isset($this->parent->ftp_form) && !empty($this->parent->ftp_form)) {
             self::load_direct();
             $res = self::$direct->put_contents($file, $content, $chmod);
         } else {
             $res = $wp_filesystem->put_contents($file, $content, $chmod);
         }
     } elseif ($action == 'chown') {
         // Changes file owner
         if (isset($owner) && !empty($owner)) {
             $res = $wp_filesystem->chmod($file, $chmod, $recursive);
         }
     } elseif ($action == 'owner') {
         // Gets file owner
         $res = $wp_filesystem->owner($file);
     } elseif ($action == 'chmod') {
         if (!isset($params['chmod']) || isset($params['chmod']) && empty($params['chmod'])) {
             $chmod = false;
         }
         $res = $wp_filesystem->chmod($file, $chmod, $recursive);
     } elseif ($action == 'get_contents') {
         // Reads entire file into a string
         if (isset($this->parent->ftp_form) && !empty($this->parent->ftp_form)) {
             self::load_direct();
             $res = self::$direct->get_contents($file);
         } else {
             $res = $wp_filesystem->get_contents($file);
         }
     } elseif ($action == 'get_contents_array') {
         // Reads entire file into an array
         $res = $wp_filesystem->get_contents_array($file);
     } elseif ($action == 'object') {
         $res = $wp_filesystem;
     } elseif ($action == 'unzip') {
         $unzipfile = unzip_file($file, $destination);
         if ($unzipfile) {
             $res = true;
         }
     }
     if (!$res) {
         if ($action == 'dirlist') {
             if (empty($res) || $res == false || $res == '') {
                 return;
             }
             if (is_array($res) && empty($res)) {
                 return;
             }
             if (!is_array($res)) {
                 if (count(glob("{$file}*")) == 0) {
                     return;
                 }
             }
         }
         $this->killswitch = true;
         $this->parent->admin_notices[] = array('type' => 'error', 'msg' => '<strong>' . __('File Permission Issues', 'avadaredux-framework') . '</strong><br/>' . sprintf(__('We were unable to modify required files. Please ensure that <code>%1s</code> has the proper read-write permissions, or modify your wp-config.php file to contain your FTP login credentials as <a href="%2s" target="_blank">outlined here</a>.', 'avadaredux-framework'), AvadaRedux_Helpers::cleanFilePath(trailingslashit(WP_CONTENT_DIR)) . '/uploads/', 'https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants'), 'id' => 'avadaredux-wp-login', 'dismiss' => false);
         //add_action( "avadaredux/page/{$this->parent->args['opt_name']}/form/before", array(
         //    $this,
         //    'ftp_form'
         //) );
     }
     return $res;
 }