Skip to content

Remove unnecessary file_exists() checks from plugin builds #2670

@westonruter

Description

@westonruter

In order to help guide users to properly install the plugin when it has been cloned from GitHub, the plugin includes this code:

amp-wp/amp.php

Lines 148 to 157 in cb0c7e3

if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) || ! file_exists( __DIR__ . '/vendor/sabberworm/php-css-parser' ) || ! file_exists( __DIR__ . '/assets/js/amp-block-editor.js' ) ) {
$_amp_load_errors->add(
'build_required',
sprintf(
/* translators: %s: composer install && npm install && npm run build */
__( 'You appear to be running the AMP plugin from source. Please do %s to finish installation.', 'amp' ), // phpcs:ignore WordPress.Security.EscapeOutput
'<code>composer install &amp;&amp; npm install &amp;&amp; npm run build</code>'
)
);
}

As potentially discovered on the support forum, the file_exists() check may return stale results that necessitate calling clearstatcache().

Nevertheless, this entire if statement is irrelevant from being included in plugin builds distributed from WordPress.org because we already know that those files exist at build time. So we can potentially prevent a bug from happening and improve performance a tiiiiiiny bit by just removing it entirely from amp.php during a build.

Metadata

Metadata

Assignees

Labels

InfrastructureChanges impacting testing infrastructure or build toolingTaskTasks which do not involve engineering

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions