-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The class `PMXI_Plugin` and the function `wp_all_import_pro_updater()` are "hidden" behind a `if` statement: ``` if ( is_plugin_active( 'wp-all-import/plugin.php' ) ) { ``` This prevents the php parser to do its job. A new script has been added to remove the `if` statement, allowing the parser to find these nodes.
- Loading branch information
1 parent
0d83716
commit 58bee48
Showing
5 changed files
with
471 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* The class `PMXI_Plugin` and the function `wp_all_import_pro_updater()` are "hidden" behind a `if` statement: | ||
* `if ( is_plugin_active( 'wp-all-import/plugin.php' ) ) {` | ||
* This prevents the php parser to do its job. | ||
* This script removes the `if` statement, allowing the parser to find these nodes. | ||
*/ | ||
namespace Polylang\WP_All_Import_Pro_Stubs; | ||
|
||
use Symfony\Component\Console\Input\ArgvInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { | ||
require __DIR__ . '/vendor/autoload.php'; | ||
} | ||
|
||
function remove_if_else_statement() { | ||
$rel_path = "wp-all-import-pro/wp-all-import-pro.php"; | ||
$full_path = __DIR__ . '/' . $rel_path; | ||
$io = new SymfonyStyle( new ArgvInput(), new ConsoleOutput() ); | ||
|
||
$io->title( 'Replacements in original main file' ); | ||
|
||
if ( ! file_exists( $full_path ) ) { | ||
$io->error( "Failed to locate file $rel_path." ); | ||
return; | ||
} | ||
|
||
try { | ||
$contents = file_get_contents( $full_path ); | ||
|
||
if ( ! is_string( $contents ) ) { | ||
$io->error( "Failed to open file $rel_path." ); | ||
return; | ||
} | ||
} catch( Exception $e ) { | ||
$io->error( "Failed to open file $rel_path." ); | ||
return; | ||
} | ||
|
||
$pattern = "@if\s*\(\s*is_plugin_active\(\s*'wp-all-import/plugin.php'\s*\)\s*\)\s*\{.+\}\s*else\s*\{(?<code>.*)\}\s*$@Us"; | ||
|
||
if ( ! preg_match( $pattern, $contents, $matches ) ) { | ||
$io->error( "Could not find the part to remove in file $rel_path." ); | ||
return; | ||
} | ||
|
||
$contents = str_replace( $matches[0], $matches['code'] . "\n", $contents ); | ||
$result = file_put_contents( $full_path, $contents ); | ||
|
||
if ( false === $result ) { | ||
$io->error( "Failed to perform replacements in file $rel_path." ); | ||
} else { | ||
$io->success( "Replacements done in file $rel_path." ); | ||
} | ||
} | ||
|
||
remove_if_else_statement(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,3 +79,5 @@ download_plugin() { | |
|
||
# Download WP All Import Pro | ||
download_plugin wp-all-import-pro | ||
|
||
php fix-main-file.php |
Oops, something went wrong.