Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API no registering if you use a non-standard API Prefix #582

Open
EneMarine opened this issue Nov 29, 2024 · 1 comment
Open

API no registering if you use a non-standard API Prefix #582

EneMarine opened this issue Nov 29, 2024 · 1 comment

Comments

@EneMarine
Copy link

Hello,

We just found out your plugin doesn't work if you edit the Wordpress Rest Prefix for security reasons.
Your method LP_Helper::isRestApiLP() use a hard coded value instead of using rest_get_url_prefix()

return strpos( self::getUrlCurrent(), '/wp-json/lp/' ) || strpos( self::getUrlCurrent(), '/wp-json/learnpress/' );

I would assume there is 2 solutions :

  • Using rest_get_url_prefix
public static function isRestApiLP(): bool {
+       $restPrefix = rest_get_url_prefix();
-	return strpos( self::getUrlCurrent(), '/wp-json/lp/' ) || strpos( self::getUrlCurrent(), '/wp-json/learnpress/' );
+	return strpos( self::getUrlCurrent(), '/' . $restPrefix . '/lp/' ) || strpos( self::getUrlCurrent(), '/' . $restPrefix . '/learnpress/' );
}
  • Adding a filter so developers can't edit this check
public static function isRestApiLP(): bool {
+       $isRestApiLP = strpos( self::getUrlCurrent(), '/wp-json/lp/' ) || strpos( self::getUrlCurrent(), '/wp-json/learnpress/' );
-	return strpos( self::getUrlCurrent(), '/wp-json/lp/' ) || strpos( self::getUrlCurrent(), '/wp-json/learnpress/' );
+	return apply_filters('learn_press_is_rest_api_lp', $isRestApiLP, self::getUrlCurrent());
}

Thanks

@tungnxt89
Copy link
Collaborator

tungnxt89 commented Feb 21, 2025

Hi EneMarine

Thank you for you feedback, we don't know that before. We'll apply that.

Thanks.
Best regard!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants