This document provides coding agent guidelines for working with the Pinterest for WooCommerce plugin. It contains information that may be difficult for agents to discover independently and follows industry best practices for agent instruction files.
Pinterest for WooCommerce is an official WordPress plugin that integrates WooCommerce stores with Pinterest. It enables:
- Product catalog sync to Pinterest
- Pinterest Save Button for products
- Rich Pins support
- Conversion tracking with Pinterest tag
- Pinterest advertising capabilities
Important: This is a public open-source repository maintained by WooCommerce.
- PHP: 7.4+ (minimum supported version)
- WordPress: 5.6+ (minimum), tested up to 6.9
- WooCommerce: 7.0+ (minimum), tested up to 10.5
- Architecture: PSR-4 autoloading for modern code, WordPress conventions for legacy code
- Dependencies:
automattic/jetpack-autoloader- Version resolution for shared dependencieswoocommerce/action-scheduler-job-framework- Background job processingdefuse/php-encryption- Secure data encryptionwoocommerce/grow- Shared utilities and compatibility checker
- JavaScript: React-based admin interface
- Build System: @wordpress/scripts with webpack
- UI Framework: @woocommerce/components, @wordpress/components
- State Management: @wordpress/data
- Node: 14.16 (pinned via
.nvmrc) - npm: 6.14.10 to <7
- Build Tools: Gulp (legacy), webpack (modern)
pinterest-for-woocommerce/
├── src/ # Modern PHP code (PSR-4: Automattic\WooCommerce\Pinterest\)
│ ├── Admin/ # Admin interface classes
│ ├── API/ # API integration classes
│ ├── Product/ # Product sync and catalog management
│ ├── Tracking/ # Analytics and conversion tracking
│ ├── Utilities/ # Helper classes and utilities
│ └── ...
├── includes/ # Legacy WordPress-style code
│ └── admin/ # Admin-specific legacy code
├── assets/ # Frontend assets
│ ├── source/ # React source files (JSX, SCSS)
│ ├── build/ # Compiled production assets (gitignored)
│ └── images/ # Static images
├── bin/ # Development scripts
│ ├── install-wp-tests.sh # PHPUnit test setup
│ └── lint-branch.sh # Linting helper
├── tests/ # Test files
│ ├── Unit/ # PHPUnit unit tests
│ ├── Integration/ # PHPUnit integration tests
│ ├── E2e/ # End-to-end tests
│ └── Helpers/ # Test utilities
├── vendor/ # PHP dependencies (gitignored, composer-managed)
├── node_modules/ # JavaScript dependencies (gitignored, npm-managed)
├── i18n/ # Internationalization files
├── composer.json # PHP dependency configuration
├── package.json # JavaScript dependency configuration
├── phpcs.xml # PHP_CodeSniffer configuration
├── pinterest-for-woocommerce.php # Main plugin file
└── class-pinterest-for-woocommerce.php # Main plugin class
# Use correct Node version
nvm use
# Install dependencies
npm install
composer install# Development build with file watching
npm start
# Production build
npm run build
# Build and create distribution zip
npm run build:zip# Run phpcs on all PHP files
composer phpcs
# OR
npm run lint:php
# Fix automatically fixable issues
composer phpcbf
# OR
npm run lint:php:fix
# Lint only changed files
composer lint
# Lint staged changes
composer lint-staged
# Lint current branch vs develop
composer lint-branch# Lint JavaScript files
npm run lint:js
# Fix JavaScript issues automatically
npm run lint:js:fix# Lint CSS/SCSS files
npm run lint:css
# Fix CSS issues automatically
npm run lint:css:fix# Install WordPress test environment
./bin/install-wp-tests.sh wordpress_test root root localhost
# Run tests
vendor/bin/phpunit
# OR
composer test-unit# Run JavaScript unit tests
npm run test:js
# Run tests in watch mode
npm run test:js:watch# Generate .pot file for translations
npm run i18nThis project follows WooCommerce-Core coding standards, which extend WordPress coding standards.
Key Rules:
- PSR-4 naming in
src/directory (e.g.,class ProductSyncin fileProductSync.php) - WordPress naming conventions in
includes/directory (e.g.,class-pinterest-for-woocommerce-admin.php) - Text domain MUST be
pinterest-for-woocommerce - Minimum WordPress version: 5.6
- Minimum PHP version: 7.4
- PHPCompatibility checks enabled
- File comments required (except in
src/andtests/) - Function comments required with proper @param and @return tags
PHPCS Configuration: See phpcs.xml for complete ruleset.
CRITICAL: ALWAYS run vendor/bin/phpcs before committing code. CI will fail if code doesn't pass phpcs checks.
- Follows
@woocommerce/eslint-pluginrecommended configuration - Uses WordPress code style conventions
- React hooks and modern JavaScript (ES6+) patterns
- Proper PropTypes or TypeScript types for components
- Follows
@wordpress/stylelint-config/scssconfiguration - BEM-like naming conventions preferred
- Mobile-first responsive design
MUST follow WordPress coding standards in all code.
- Spaces inside parentheses:
if ( condition ),function_name( $arg ) - Spaces inside brackets:
array( 'key' => 'value' ),[ 1, 2, 3 ](PHP 5.4+ syntax) - Spaces inside braces:
{ 'key': 'value' }(JavaScript) - Function calls:
__( 'text', 'pinterest-for-woocommerce' ) - Control structures:
if ( condition ) {(space before opening brace) - Indentation: Tabs (4-space width), not spaces (per
.editorconfig) - Line length: 120 columns max (WordPress standard)
<?php
/**
* Example function demonstrating WordPress code style
*
* @param string $merchant_id The merchant identifier.
* @param array $args Configuration arguments.
* @return array
*
* @throws Exception When merchant creation fails.
*/
public static function update_or_create_merchant( $merchant_id, $args ) {
$config = array(
'merchant_domains' => get_home_url(),
'feed_location' => $args['feed_url'],
'feed_format' => 'XML',
);
if ( empty( $merchant_id ) ) {
throw new Exception(
__( 'Merchant ID is required.', 'pinterest-for-woocommerce' ),
400
);
}
try {
$response = Base::update_or_create_merchant( $config );
} catch ( Throwable $th ) {
throw new Exception( $th->getMessage(), $th->getCode() );
}
return $response;
}Key style elements shown:
- Spaces inside parentheses and array brackets
- Tab indentation (shown as spaces in this example, but use actual tabs)
- Array alignment for readability
- Proper docblock with
@param,@return, and@throws - Text domain in translation function
- Exception handling pattern
ALWAYS create feature branches from develop:
# Create new feature branch
git checkout develop
git pull origin develop
git checkout -b feature/your-feature-name
# Create bugfix branch
git checkout -b fix/bug-descriptionNEVER branch from or merge directly to main or master. The main development branch is develop.
Format: <prefix>/<short-description>
Allowed prefixes:
feature/- New functionality or enhancementsfix/- Bug fixesupdate/- Dependency updates or version bumpsrefactor/- Code refactoring without changing functionalitychore/- Maintenance tasks, build config changes
Naming conventions:
- Use imperative mood (e.g.,
add,fix,update, notadding,fixed,updated) - Use lowercase
- Use hyphens (not underscores or spaces)
- Keep descriptions short and descriptive
- Do NOT include issue/ticket numbers in branch names
Good examples:
feature/add-catalog-retry-logic
fix/product-attribute-mapping
update/bump-min-woocommerce-version
refactor/simplify-merchant-creation
chore/update-phpcs-config
Bad examples:
Feature/AddRetryLogic # Wrong: capitalized
fix_bug # Wrong: too vague, uses underscore
feature/PINT-123-add-feature # Wrong: includes ticket number
updateDependencies # Wrong: missing prefix, camelCase
Follow these commit guidelines:
- Concise, one-line commit messages preferred
- Incremental commits - break changes into logical, self-contained commits
- Present tense, imperative mood (e.g., "Add feature" not "Added feature")
- Run phpcs before committing - CRITICAL
- Do NOT use
--no-verifyto skip git hooks unless absolutely necessary - Do NOT commit without testing - at minimum, ensure code passes linting
Good commit message examples:
Add Pinterest catalog sync retry logic
Fix product attribute mapping for variations
Update API error handling for rate limits
Refactor admin settings validation
When creating PRs:
- Target the
developbranch - Provide clear description of changes
- Include test instructions
- Reference related issues
- Ensure all CI checks pass (phpcs, PHPUnit, JS tests)
| Pitfall | Why |
|---|---|
| Edit WordPress core files | Only modify plugin code |
| Edit WooCommerce plugin files | Only modify this plugin's code |
Commit without running vendor/bin/phpcs first |
CI will fail |
Modify changelog.txt |
Unless explicitly requested |
Commit node_modules/ or vendor/ directories |
These are gitignored |
Commit .env files or credentials |
Security risk |
Use --no-verify or --no-gpg-sign |
Unless explicitly required |
| Skip running tests before pushing to remote | May break production |
| Use Node versions outside 12.20.1 to <15 | Check with nvm use |
| Best Practice | Why |
|---|---|
| Follow WooCommerce coding standards | Enforced by phpcs |
Use text domain pinterest-for-woocommerce |
Required for translations |
Branch from develop, not main/master |
Main development branch |
| Run linting before commits | vendor/bin/phpcs, npm run lint:js, npm run lint:css |
| Write PHPUnit tests for new PHP functionality | Ensure code quality and prevent regressions |
Use PSR-4 naming in src/ directory |
Modern PHP autoloading standard |
Use WordPress naming conventions in includes/ |
Legacy code compatibility |
| Check minimum version requirements | When using WordPress/WooCommerce APIs |
Run composer install after pulling |
Autoloader must be regenerated |
Run npm install after pulling if package.json changed |
Ensure dependency consistency |
1. Wrong namespace in src/ files:
// ❌ WRONG
namespace Pinterest\Product;
// ✅ CORRECT
namespace Automattic\WooCommerce\Pinterest\Product;2. Wrong text domain:
// ❌ WRONG
__( 'Hello', 'pinterest' )
// ✅ CORRECT
__( 'Hello', 'pinterest-for-woocommerce' )3. Wrong file naming in src/:
// ❌ WRONG - WordPress style in PSR-4 directory
// File: class-product-sync.php
class Product_Sync {}
// ✅ CORRECT - PSR-4 naming
// File: ProductSync.php
class ProductSync {}4. Editing compiled files:
# ❌ WRONG - editing compiled output
vim assets/build/index.js
# ✅ CORRECT - edit source files
vim assets/source/index.js
npm start # recompileReason: The plugin is transitioning from WordPress conventions to modern PHP standards. New code goes in src/ with PSR-4 autoloading for better maintainability and IDE support. Legacy code remains in includes/ for backward compatibility.
Reason: When multiple plugins bundle the same dependencies (e.g., Guzzle), version conflicts can occur. Jetpack Autoloader resolves these conflicts by loading the latest compatible version across all installed plugins.
Reason: WordPress cron is unreliable for critical tasks (depends on site traffic). Action Scheduler provides robust background job processing with retries, error handling, failure logging, and admin UI for monitoring scheduled actions.
Reason: WordPress and WooCommerce release independently. We support recent versions of each to balance feature availability with user adoption:
| Platform | Support Policy | Current Minimum |
|---|---|---|
| WordPress | Last 2 major versions | 5.6+ |
| WooCommerce | Last several major versions | 7.0+ |
Always check the plugin header in pinterest-for-woocommerce.php for current requirements.
Reason: The build toolchain and dependencies have proven difficult to update without breaking changes. Updating Node and related packages (webpack, @wordpress/scripts, etc.) requires significant testing and potential code changes. The current pinned version (v14.16, specified in .nvmrc) works reliably, so we maintain it until a coordinated update effort can be planned. Always use nvm use to ensure you're on the correct version.
Unit Tests (PHPUnit):
- Business logic in
src/classes - API integration methods
- Data transformation and validation
- Utility functions
Integration Tests (PHPUnit):
- WordPress/WooCommerce API interactions
- Database operations
- Plugin activation/deactivation
- Settings and option handling
JavaScript Tests (Jest):
- React component rendering
- State management logic
- API data transformations
- Utility functions
Aim for high coverage of business logic. Test files should mirror the structure of source files:
src/Product/ProductSync.php → tests/Unit/Product/ProductSyncTest.php
The plugin integrates with Pinterest Marketing API v5. Key concepts:
- Merchant ID: Unique identifier for the merchant's Pinterest account
- Catalog ID: ID of the product catalog synced to Pinterest
- Feed ID: ID of the product feed within a catalog
- Access Token: OAuth2 token for API authentication (stored encrypted)
The plugin uses standard WordPress/WooCommerce hooks:
woocommerce_init- Initialize plugin featureswoocommerce_product_object_updated_props- Detect product changeswoocommerce_update_product- Trigger product sync- Custom action hooks for extensibility (prefixed with
pinterest_for_woocommerce_)
- Product sync runs in background jobs via Action Scheduler
- Rate limiting applies to Pinterest API calls (respect
X-RateLimit-*headers) - Batch operations for large catalogs (up to 1000 products per batch)
- Caching used for settings and API responses where appropriate
- Asset minification in production builds
- API credentials encrypted using defuse/php-encryption
- Nonce verification on all AJAX and form submissions
- Capability checks before admin operations
- Input sanitization on all user-provided data
- Output escaping when rendering data
This is a public open-source repository. NEVER commit:
- API keys, tokens, or credentials
- Customer data or PII
- Internal company information
- Sensitive security details
.envfiles or local configuration
Use .gitignore properly and audit commits before pushing.
// In wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );// Log to debug.log
error_log( print_r( $variable, true ) );
// WooCommerce logger
wc_get_logger()->debug( 'Message', [ 'source' => 'pinterest-for-woocommerce' ] );Product not syncing:
- Check Action Scheduler admin page: WooCommerce → Status → Scheduled Actions
- Search for actions with group
pinterest-for-woocommerce - Check for failed actions and error logs
API errors:
- Check
wp-content/debug.logfor API response errors - Verify credentials in plugin settings
- Check Pinterest API status page
Per WordPress Core Handbook, we support:
- Last 2 versions of Chrome, Firefox, Safari, Edge, Opera
- Last 1 version of ChromeAndroid, Android browser
- Last 2 versions of iOS Safari
- Browsers with >1% usage share
We do NOT support Internet Explorer.
- Pinterest Marketing API Docs
- WooCommerce Developer Docs
- WordPress Developer Handbook
- Action Scheduler
README.md- General development info and setup instructionscomposer.json- PHP dependencies and scriptspackage.json- JavaScript dependencies and scriptsphpcs.xml- Complete phpcs ruleset.editorconfig- Editor formatting rules
- Issue tracker: For bug reports and feature requests (not support)
- Code of conduct: Follow WordPress and WooCommerce community guidelines
- Contributing: Follow the development workflow outlined in this document
Last Updated: 2026-02-25 Maintained by: WooCommerce Team License: GPL-3.0-or-later