This document outlines the development steps for the Setlist Player WordPress plugin.
- 1.1. Initialize Git Repository: Set up the project directory as a Git repository.
- 1.2. Scaffold Plugin with WP-CLI: Use
wp scaffold plugin setlist-playerto create the basic plugin structure. - 1.3. Initialize NPM: Create a
package.jsonfile to manage frontend dependencies and build scripts. - 1.4. Install Node Dependencies: Install
@wordpress/scriptsfor block development (which includes React, Webpack, Babel, ESLint, Prettier, and Jest). - 1.5. Configure
package.jsonScripts: Add scripts forstart,build,lint, andtest. - 1.6. Initialize Composer: Create a
composer.jsonfile for PHP dependencies. - 1.7. Install PHP Dependencies: Install
phpcsand the WordPress Coding Standards for linting and formatting PHP. - 1.8. Configure
composer.jsonScripts: Add scripts forlintandformat. - 1.9. Create
.gitignore: Add a comprehensive.gitignorefile for WordPress plugin development.
Technical approach: Use WordPress HTTP API (wp_remote_get()) for YouTube Data API v3 calls. Create separate classes in includes/ directory following WordPress standards. Extend WP_REST_Controller for REST endpoints.
- 2.1. Create YouTube API Wrapper Class: Build
class-setlist-player-youtube-api.phpto handle YouTube Data API v3 calls (search, video details, key validation). - 2.2. Register Settings Page: Create
class-setlist-player-settings.phpwith settings page under "Settings" menu usingadd_options_page. - 2.3. Implement Settings API: Use WordPress Settings API (
register_setting,add_settings_section,add_settings_field) to create the API key input field. - 2.4. Implement API Key Validation: On settings save, perform a server-side test call to YouTube Data API v3 using the YouTube API wrapper class.
- 2.5. Handle Validation Response: Display success or error notices to the admin based on the API call result. Prevent saving an invalid key.
- 2.6. Create REST Controller: Build
class-setlist-player-rest-controller.phpextendingWP_REST_Controllerwith endpoints for video search and metadata retrieval. - 2.7. Initialize Classes: Update main plugin file to require and initialize all new classes.
- 3.1. Scaffold Block: Use
@wordpress/create-blockto scaffold the block with necessary files (block.json,index.js,edit.js,save.js,style.scss,editor.scss). - 3.2. Register Block Type: Register the
setlist-playerblock on the server side withregister_block_type. - 3.3. Build Editor UI: In the
edit.jscomponent, create the sidebar panel using@wordpress/components(e.g.,PanelBody,TextControl,Button). - 3.4. Manage State with Attributes: Define block attributes in
block.jsonto store the playlist (an array of video objects). - 3.5. Implement "Add by URL/ID": Write a function to parse a YouTube URL or ID, fetch video details, and add it to the playlist attribute.
- 3.6. Implement "Add by Search":
- 3.6.1. On button click, call the custom REST endpoint created in Step 2.5.
- 3.6.2. Display the top 5 search results below the search bar.
- 3.6.3. On result click, add the selected video to the playlist attribute.
- 3.7. Implement Reordering: Use a library or built-in HTML5 drag-and-drop APIs to allow reordering of videos in the playlist.
- 3.8. Implement UI Details: Add the dynamic panel title and tooltips for video details on hover.
- 3.9. Create Editor Placeholder: Design a simple, non-functional placeholder for the block's appearance in the main editor canvas.
- 4.1. Use
render.phpfor Dynamic Rendering: Specify therenderproperty inblock.jsonto point to arender.phpfile. The block'ssave.jswill returnnull. - 4.2. Enqueue Frontend Scripts: Enqueue the YouTube IFrame Player API and a custom frontend JavaScript file for player interactivity.
- 4.3. Implement
render.php: In therender.phpfile, use the block's attributes to generate the necessary HTML structure for the player and the playlist on the server side. - 4.4. Implement Player Logic: In the frontend JavaScript:
- 4.4.1. Initialize the YouTube player.
- 4.4.2. Load the first video without autoplaying.
- 4.4.3. Implement the "click to play" functionality for the playlist items, including scrolling to the player.
- 4.5. Implement Custom Controls:
- 4.5.1. Hook the speed control
<select>to the player'ssetPlaybackRate()method. - 4.5.2. Add event listeners for all specified keyboard shortcuts (
Spacebar,r,n,p,i,d), plushfor hide video toggle.
- 4.5.1. Hook the speed control
- 5.1. PHPUnit Tests:
- 5.1.1. Set up the PHPUnit testing environment for WordPress using
wp-cli. - 5.1.2. Write tests for the API key validation logic.
- 5.1.3. Write tests for the REST API endpoint.
- 5.1.1. Set up the PHPUnit testing environment for WordPress using
- 5.2. Jest Unit Tests:
- 5.2.1. Write unit tests for utility functions (
utils.js).
- 5.2.1. Write unit tests for utility functions (
- 5.3. Linting and Formatting:
- 5.3.1. Set up
npm run lintandnpm run formatscripts for JavaScript and CSS files. - 5.3.2. Set up
composer lintandcomposer formatscripts for PHP files.
- 5.3.1. Set up
- 6.1. Review and Refactor: Clean up code and ensure all requirements are met.
- 6.2. Create
readme.txt: Write a comprehensive, WordPress.org-compliantreadme.txtfile. - 6.3. Add Inline Documentation: Ensure functions, classes, and complex code blocks are well-commented.
- 6.4. Build for Production: Run
npm run buildto generate minified production assets. - 6.5. Create Distribution Package: Implement npm script using
@wordpress/scripts plugin-zipto generate a WordPress.org-ready distribution zip file. - 6.6. Final Test: Perform a final manual test of the entire plugin workflow.
These items can be implemented as the plugin matures:
- React Component Tests: Write unit tests for the
edit.jscomponent, mocking@wordpresspackages and testing state changes, user interactions (adding/searching for videos), and component rendering. - End-to-End (E2E) Tests: Configure
@wordpress/e2e-tests-playwrightand write E2E tests to simulate adding the block, building a playlist, and verifying the frontend player's functionality.