[paths] Store relative paths instead of absolute paths to the storage.#198
Conversation
includes/class-freemius.php
Outdated
| return; | ||
| } | ||
|
|
||
| if ( version_compare( $sdk_prev_version, '1.2.2.11', '<' ) && |
There was a problem hiding this comment.
@fajardoleo the upcoming version is 1.2.3, not 1.2.2.11. This is also relevant for all comments.
includes/class-freemius.php
Outdated
| * | ||
| * @return string | ||
| */ | ||
| private function get_absolute_path( $path, $module_type = false ) { |
There was a problem hiding this comment.
@fajardoleo you're using tabs instead of spaces. Please modify your settings to use 4 spaces instead of tabs and realign all the changes.
includes/class-freemius.php
Outdated
| get_theme_root() ); | ||
|
|
||
| if ( 0 !== strpos( $path, $module_root_dir ) ) { | ||
| $path = ( $module_root_dir . '/' . $path ); |
There was a problem hiding this comment.
@fajardoleo I'd recommend using $path = trailingslashit( $module_root_dir ) . $path; instead to avoid situations where some environments may already have a trailing slash at the end of the plugin/theme path variable.
| ) { | ||
| if ( file_exists( $this->_storage->plugin_main_file->prev_path ) ) { | ||
| return $this->_storage->plugin_main_file->prev_path; | ||
| $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path ); |
There was a problem hiding this comment.
@fajardoleo I noticed that you've forgot to migrate $this->_storage->plugin_main_file->prev_path to the relative path structure (in the migration logic, not here).
includes/class-freemius.php
Outdated
| if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) { | ||
| $module_type = WP_FS__MODULE_TYPE_THEME; | ||
| $caller_file_candidate = $caller_file_path; | ||
| $caller_file_candidate = basename( dirname( $caller_file_path ) ) . |
There was a problem hiding this comment.
@fajardoleo I'll add a comment that this calculates the relative path of the theme + also add an inline example in the comment.
includes/class-freemius.php
Outdated
| * @return string | ||
| */ | ||
| function get_plugin_basename() { | ||
| function get_plugin_basename( $plugin_main_file_path = false ) { |
There was a problem hiding this comment.
@fajardoleo you've added $plugin_main_file_path as an argument, but I don't see any call to this method with an argument.
includes/class-freemius.php
Outdated
| * | ||
| * @return string | ||
| */ | ||
| private function get_relative_path( $path ) { |
There was a problem hiding this comment.
@fajardoleo this method is confusing. It gets a $path argument but it doesn't really work for any path beside the path of the current context module.
includes/class-freemius.php
Outdated
| $this->is_plugin() : | ||
| ( WP_FS__MODULE_TYPE_PLUGIN === $module_type ); | ||
|
|
||
| $module_root_dir = fs_normalize_path( $is_plugin ? |
There was a problem hiding this comment.
@fajardoleo I suggest creating a helper method to calculate the get_module_root_dir_path( $module_type = false ) since you have it here and in get_relative_path().
No description provided.