Undefined variable when activating plugin in Localhost ( mamp server )
-
There is an error in plugin main file. You are relying on $_SERVER[‘REQUEST_SCHEME’] to check if it is a secure URL, which is wrong because $_SERVER[‘REQUEST_SCHEME’] might not exists. As such, there is an HTTP ERROR 500 when enabling the plugin in localhost servers ( I tested in mamp ).
To fix this, please replace this code :
if( $_SERVER['REQUEST_SCHEME'] == "https" ){ define ( 'PTPDF_URL', str_replace( "https://", "https://", WP_PLUGIN_URL . '/wp-advanced-pdf' ) ); } else { define ( 'PTPDF_URL', WP_PLUGIN_URL . '/wp-advanced-pdf' ); }
by this ( optimize if required ) :
if ( isset( $_SERVER['REQUEST_SCHEME'] ) ) { if( $_SERVER['REQUEST_SCHEME'] == "https" ){ define ( 'PTPDF_URL', str_replace( "https://", "https://", WP_PLUGIN_URL . '/wp-advanced-pdf' ) ); } else { define ( 'PTPDF_URL', WP_PLUGIN_URL . '/wp-advanced-pdf' ); } } else { if ( ( ! empty($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ) || $_SERVER['SERVER_PORT'] == 443 ) { define ( 'PTPDF_URL', str_replace( "https://", "https://", WP_PLUGIN_URL . '/wp-advanced-pdf' ) ); } else { define ( 'PTPDF_URL', WP_PLUGIN_URL . '/wp-advanced-pdf' ); } }
Basically I am checking first if the variable $_SERVER[‘REQUEST_SCHEME’] is set and if not, it uses $_SERVER[‘HTTPS’] . In case it is empty then it checks if port 443 is being used ( this can be tricky, so I would recommend to optimize this code by plugin author ). Anyway using the code above it fixes the error and makes the plugin work in localhost. Please fix it in the future releases. Thanks.
- The topic ‘Undefined variable when activating plugin in Localhost ( mamp server )’ is closed to new replies.