Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/php-style-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,27 @@
runs-on: ubuntu-latest

steps:
- name: Skip
run: echo 'workflow broke - skip for PR checks'
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'PHP Style Linting' step
Uses Step
uses 'shivammathur/setup-php' with ref 'v2', not a pinned commit hash
with:
php-version: "8.4"
tools: composer

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: |
~/.composer/cache
vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run PHPCS
run: composer run php:lint:report
26 changes: 23 additions & 3 deletions app/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{
private string $menuSlug = 'pantheon-content-publisher';
private string $title = 'Pantheon Content Publisher';
// phpcs:ignore Generic.Files.LineLength.TooLong
private const CPUB_ICON_BASE64 = 'PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxwYXRoIGQ9Ik00LjcxNjkxIDFMNi4xNTA3MSA0LjQ1NDE4SDQuMzI1ODdMNC45MTI0MiA1Ljk1MzE2SDguNjI3MjlMNC43MTY5MSAxWiIgZmlsbD0id2hpdGUiLz4KICAgIDxwYXRoIGQ9Ik05LjU3MjI5IDEzLjU0NThMOC45NTMxNCAxMi4wNDY5SDguM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MzNMOC41NjIxIDguODg1OTVaIgogICAgICAgICAgZmlsbD0id2hpdGUiLz4KICAgIDxwYXRoIGQ9Ik01Ljc1OTY3IDguODg1OTVMNS4yMDU3IDcuNDg0NzNINi40NzY1OEw3LjA2MzE0IDguODg1OTVIOC4yNjg4NEw3LjE5MzQ4IDYuMzExNjFINC41NTM5N0M0LjM1ODQ1IDYuMzExNjEgNC4yMjgxMSA2LjMxMTYxIDQuMTMwMzUgNi42MDQ4OUM0LjAzMjU5IDYuOTYzMzUgNCA3LjY0NzY2IDQgOC45ODM3MUM0IDEwLjMxOTggNCAxMS4wMDQxIDQuMTMwMzUgMTEuMzYyNUM0LjIyODExIDExLjY1NTggNC4zMjU4NyAxMS42NTU4IDQuNTUzOTcgMTEuNjU1OEg2Ljg2NzYyTDUuNzU5NjcgOC44ODU5NVoiCiAgICAgICAgICBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4=';

public function __construct()
Expand Down Expand Up @@ -86,8 +87,20 @@
$clientHandle = $handle . '-client';
$preambleHandle = $handle . '-react-refresh-preamble';
wp_enqueue_script_module($clientHandle, "$protocol://localhost:5173/@vite/client", [], null, true);
wp_enqueue_script_module($preambleHandle, "$protocol://localhost:5173/src/scripts/react-refresh-preamble.js", [$clientHandle], null, true);
wp_enqueue_script_module($handle, "$protocol://localhost:5173/src/admin/main.tsx", [$clientHandle, $preambleHandle], null, true);
wp_enqueue_script_module(
$preambleHandle,
"$protocol://localhost:5173/src/scripts/react-refresh-preamble.js",
[$clientHandle],
null,
true
);
wp_enqueue_script_module(
$handle,
"$protocol://localhost:5173/src/admin/main.tsx",
[$clientHandle, $preambleHandle],
null,
true
);

$this->addBootstrap();
}
Expand All @@ -96,31 +109,38 @@
{
$manifestPath = CPUB_PLUGIN_DIR . 'assets/dist/build/.vite/manifest.json';
if (!file_exists($manifestPath)) {
error_log('Manifest file not found');

Check warning on line 112 in app/Admin.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.PHP.DevelopmentFunctions.error_log_error_log

error_log() found. Debug code should not normally be used in production.
return;
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$manifest = json_decode((string) file_get_contents($manifestPath), true);
$entry = reset($manifest) ?? null;
if (!$entry) {
error_log('Entry not found');

Check warning on line 119 in app/Admin.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.PHP.DevelopmentFunctions.error_log_error_log

error_log() found. Debug code should not normally be used in production.
return;
}

$jsFile = $entry['file'] ?? null;
$cssFiles = $entry['css'] ?? [];
if ($jsFile) {
wp_enqueue_script_module($handle, CPUB_PLUGIN_DIR_URL . 'assets/dist/build/' . $jsFile, [], null, ['in_footer' => true]);
wp_enqueue_script_module(
$handle,
CPUB_PLUGIN_DIR_URL . 'assets/dist/build/' . $jsFile,
[],
null,
['in_footer' => true]
);
$this->addBootstrap();
}
foreach ($cssFiles as $css) {
wp_enqueue_style($handle, CPUB_PLUGIN_DIR_URL . 'assets/dist/build/' . $css, [], null);

Check warning on line 136 in app/Admin.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.WP.EnqueuedResourceParameters.MissingVersion

Resource version not set in call to wp_enqueue_style(). This means new versions of the style may not always be loaded due to browser caching.
}
}

private function addAdminPageStyles(): void
{
$styleHandle = 'pcc-admin-page-styles';
wp_register_style($styleHandle, '', [], null);

Check warning on line 143 in app/Admin.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.WP.EnqueuedResourceParameters.MissingVersion

Resource version not set in call to wp_register_style(). This means new versions of the style may not always be loaded due to browser caching.
wp_enqueue_style($styleHandle);

$slug = $this->menuSlug;
Expand Down Expand Up @@ -166,7 +186,7 @@
}
}

wp_register_script('pcc-admin-bootstrap', '', [], null, false);

Check warning on line 189 in app/Admin.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.WP.EnqueuedResourceParameters.MissingVersion

Resource version not set in call to wp_register_script(). This means new versions of the script may not always be loaded due to browser caching.
wp_enqueue_script('pcc-admin-bootstrap');
wp_add_inline_script('pcc-admin-bootstrap', $bootstrap, 'before');
}
Expand Down
6 changes: 3 additions & 3 deletions app/Migrations/PluginUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ private static function runMigrations($from_version)
if (
version_compare($from_version, '1.3.1', '<') &&
version_compare(CPUB_VERSION, '1.3.1', '>=')
) {
Upgrade_131::run();
}
) {
Upgrade131::run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
exit;
}

class Upgrade_131
class Upgrade131
{
/**
* Run all migrations for version 1.3.1
Expand Down
2 changes: 1 addition & 1 deletion app/PccSyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
$args = [
'post_type' => 'any',
'post_status' => 'any',
'meta_key' => CPUB_CONTENT_META_KEY,

Check warning on line 121 in app/PccSyncManager.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.DB.SlowDBQuery.slow_db_query_meta_key

Detected usage of meta_key, possible slow query.
'meta_value' => $value,

Check warning on line 122 in app/PccSyncManager.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.DB.SlowDBQuery.slow_db_query_meta_value

Detected usage of meta_value, possible slow query.
'fields' => 'ids',
'numberposts' => 1,
];
Expand Down Expand Up @@ -200,7 +200,7 @@

if ($yoastActive) {
if (isset($article->metadata['title'])) {
update_post_meta($postId, '_yoast_wpseo_title', $article->metadata['title']);
update_post_meta($postId, '_yoast_wpseo_title', $article->metadata['title']);
}
if (isset($article->metadata['description'])) {
update_post_meta($postId, '_yoast_wpseo_metadesc', $article->metadata['description']);
Expand Down
14 changes: 10 additions & 4 deletions app/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ public function connectCollection(WP_REST_Request $request): WP_REST_Response
} catch (\Throwable $e) {
error_log('PCC connectCollection API error: ' . $e->getMessage());
return new WP_REST_Response(
esc_html__('Failed to connect collection. Ensure your collection ID and access token are correct.', 'pantheon-content-publisher'),
esc_html__(
'Failed to connect collection. Ensure your collection ID and access token are correct.',
'pantheon-content-publisher'
),
400
);
}
Expand All @@ -531,7 +534,10 @@ public function connectCollection(WP_REST_Request $request): WP_REST_Response
if (json_last_error() !== JSON_ERROR_NONE) {
error_log('PCC connectCollection JSON decode error: ' . json_last_error_msg());
return new WP_REST_Response(
esc_html__('Failed to connect collection: Unable to reach Content Publisher API.', 'pantheon-content-publisher'),
esc_html__(
'Failed to connect collection: Unable to reach Content Publisher API.',
'pantheon-content-publisher'
),
500
);
}
Expand All @@ -543,8 +549,8 @@ public function connectCollection(WP_REST_Request $request): WP_REST_Response
return new WP_REST_Response(
sprintf(
// translators: %s: Error message from the Content Publisher API
esc_html__( 'Failed to connect collection: %s', 'pantheon-content-publisher' ),
esc_html( $errorMessage )
esc_html__('Failed to connect collection: %s', 'pantheon-content-publisher'),
esc_html($errorMessage)
),
400
);
Expand Down
20 changes: 16 additions & 4 deletions app/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@
$articlesApi = new ArticlesApi($pccClient);
} catch (Exception $e) {
status_header(500);
wp_die(esc_html__('Content Publisher: Failed to initialize PCC client.', 'pantheon-content-publisher'));
wp_die(
esc_html__('Content Publisher: Failed to initialize PCC client.', 'pantheon-content-publisher')
);
exit;
}

Expand All @@ -313,14 +315,19 @@

if (!$article) {
status_header(403);
wp_die(esc_html__('Content Publisher: Document not found or not connected to your collection', 'pantheon-content-publisher'));
wp_die(
esc_html__(
'Content Publisher: Document not found or not connected to your collection',
'pantheon-content-publisher'
)
);
exit;
}

// Proceed with publish.
$postId = $PCCManager->fetchAndStoreDocument($documentId, PublishingLevel::PRODUCTION);

wp_redirect(add_query_arg('nocache', 'true', get_permalink($postId) ?: site_url()));

Check warning on line 330 in app/Settings.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.Security.SafeRedirect.wp_redirect_wp_redirect

wp_redirect() found. Using wp_safe_redirect(), along with the "allowed_redirect_hosts" filter if needed, can help avoid any chances of malicious redirects within code. It is also important to remember to call exit() after a redirect so that no other unwanted code is executed.
exit;
}

Expand Down Expand Up @@ -352,7 +359,12 @@
try {
$pccClient = (new PccSyncManager())->pccClient($pccGrant);
} catch (Exception $e) {
wp_die(esc_html__('Content Publisher: Failed to initialize PCC client for preview.', 'pantheon-content-publisher'));
wp_die(
esc_html__(
'Content Publisher: Failed to initialize PCC client for preview.',
'pantheon-content-publisher'
)
);
exit;
}

Expand Down Expand Up @@ -394,7 +406,7 @@
esc_html__(
'Content Publisher: Failed to preview this document. Confirm that this document is connected to your collection. Reach out to support if the issue persists.',
'pantheon-content-publisher'
)
)
);
exit;
}
Expand All @@ -415,7 +427,7 @@
$sig = hash_hmac('sha256', $base, $this->previewSecretForTs($ts, 900));
$url = add_query_arg(['ts' => $ts, 'sig' => $sig], $url);

wp_redirect($url);

Check warning on line 430 in app/Settings.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.Security.SafeRedirect.wp_redirect_wp_redirect

wp_redirect() found. Using wp_safe_redirect(), along with the "allowed_redirect_hosts" filter if needed, can help avoid any chances of malicious redirects within code. It is also important to remember to call exit() after a redirect so that no other unwanted code is executed.
exit;
}
} catch (Exception $ex) {
Expand Down Expand Up @@ -559,7 +571,7 @@
// Return the array containing the modified post object
return $posts;
} catch (Exception $e) {
error_log('PCC Preview Error: Failed to fetch article ' . $documentId . ' - ' . $e->getMessage());

Check warning on line 574 in app/Settings.php

View workflow job for this annotation

GitHub Actions / Validate Plugin

WordPress.PHP.DevelopmentFunctions.error_log_error_log

error_log() found. Debug code should not normally be used in production.
return $posts;
}
}
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"pantheon-systems/wpunit-helpers": "^2.0",
"phpunit/phpunit": "^9.6",
"yoast/phpunit-polyfills": "^3.1",
"php-stubs/wordpress-tests-stubs": "^6.8"
"php-stubs/wordpress-tests-stubs": "^6.8",
"pantheon-systems/pantheon-wp-coding-standards": "^3.0"
},
"repositories": [
{
Expand All @@ -41,7 +42,7 @@
],
"scripts": {
"php:lint:autofix": "vendor/bin/phpcbf --ignore=*/vendor/ --standard=./phpcs.xml ",
"php:lint:report": "vendor/bin/phpcs --ignore=*/vendor/ --standard=./phpcs.xml; phpcs --ignore=*/vendor/ --standard=./phpcs.xml --extensions=php --report=source",
"php:lint:report": "vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1 --ignore=*/vendor/ --standard=./phpcs.xml -v; phpcs --runtime-set ignore_warnings_on_exit 1 --ignore=*/vendor/ --standard=./phpcs.xml --extensions=php --report=source",
"php-compatibility": "vendor/bin/phpcs -ps * --ignore=*/vendor/ --extensions=php --standard=PHPCompatibility --runtime-set testVersion 8.1-",
"phpunit": "phpunit --do-not-cache-result",
"test": "@phpunit",
Expand Down
Loading