Skip to content

Commit fc25072

Browse files
committed
Merge branch 'release/2.6.1'
2 parents 1bd5b4d + c4c132b commit fc25072

File tree

21 files changed

+652
-57
lines changed

21 files changed

+652
-57
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
description: Rules for the JavaScript/React codebase of the Content Control Plugin
3+
globs: ["packages/**/*.{js,jsx,ts,tsx}"]
4+
alwaysApply: false
5+
---
6+
7+
# Content Control Plugin - JavaScript/React Codebase Rules
8+
9+
These rules are specific to the JavaScript/React codebase of the Content Control plugin, providing guidance for AI agents working with the frontend logic and user interface components.
10+
11+
## JavaScript/React Architecture Overview
12+
13+
The Content Control plugin utilizes React and WordPress's `@wordpress/scripts` build tooling for its admin user interface. The frontend codebase is located within the `packages/` directory and is structured as a monorepo managed by NX.
14+
15+
### Key Packages
16+
17+
- **`packages/block-editor/`**: Contains code related to Block Editor (Gutenberg) integration.
18+
- **`src/block-extensions/`**: Extends existing blocks with Content Control settings.
19+
- **`src/components/`**: Reusable React components specific to the block editor integration.
20+
- **`src/contexts/`**: React Contexts for managing state within the block editor UI.
21+
- **`packages/components/`**: Contains reusable React components used throughout the plugin's admin UI (Settings Page, Block Editor, etc.). These are general-purpose components.
22+
- **`packages/core-data/`**: Implements Redux-like data stores using `@wordpress/data` for managing client-side application state. Stores are organized by feature (license, restrictions, settings, url-search).
23+
- **`packages/data/`**: A wrapper around `@wordpress/data`, potentially for custom extensions or utilities.
24+
- **`packages/fields/`**: React components for rendering various form field types used in settings and rule configurations.
25+
- **`packages/icons/`**: Custom SVG icons used in the React UI.
26+
- **`packages/query-builder/`**: Contains React components, contexts, and reducers for building the visual rule query builder UI.
27+
- **`packages/settings-page/`**: The main React application for the plugin's settings page.
28+
- **`src/restrictions-view/`**: Components for managing and displaying restrictions within the settings page.
29+
- **`src/settings-view/`**: Components for displaying and managing general plugin settings.
30+
- **`src/upgrades-view/`**: Components related to plugin upgrades and license management.
31+
- **`packages/utils/`**: General JavaScript utility functions used across packages.
32+
- **`packages/widget-editor/`**: Code for integration with the legacy widget editor (if applicable).
33+
34+
### Important JavaScript/React Components and Modules
35+
36+
- **`packages/settings-page/src/App.tsx`**: The main entry point for the Settings Page React application.
37+
- **`packages/block-editor/src/block-extensions/block-controls/edit.tsx`**: The main component that adds Content Control UI to the Block Editor inspector controls.
38+
- **`packages/core-data/src/*/index.ts`**: Entry points for each data store slice (e.g., `restrictions`, `settings`, `license`).
39+
- **`packages/components/src/entity-select-control/`**: Reusable component for selecting WordPress entities (posts, terms, users) with search and multi-select capabilities.
40+
- **`packages/query-builder/src/components/`**: Components that make up the rule query builder UI (groups, rules, operators, etc.).
41+
- **`packages/components/src/controlled-tab-panel/`**: Reusable tab panel component used in the settings page.
42+
43+
### Coding Standards and Best Practices (JavaScript/React)
44+
45+
- **React Best Practices:** Follow established React best practices for component design, state management, and performance.
46+
- Use functional components and hooks where appropriate.
47+
- Keep components small, focused, and reusable.
48+
- Optimize component rendering and avoid unnecessary re-renders.
49+
- Use keys for lists of components.
50+
- **WordPress JavaScript Coding Standards:** Adhere to WordPress JavaScript coding standards.
51+
- Use spaces for indentation (typically 2 spaces).
52+
- Use single quotes for strings.
53+
- Avoid long lines of code.
54+
- Document components and functions with JSDoc-style comments.
55+
- **TypeScript:** The codebase uses TypeScript. Write type-safe code and utilize TypeScript features effectively.
56+
- Define clear interfaces and types for components, data structures, and API interactions.
57+
- Use type checking to catch errors early in development.
58+
- **`@wordpress/scripts` Build Tooling:** Utilize the tools and configurations provided by `@wordpress/scripts` for building, linting, and testing JavaScript code.
59+
- Use `npm run start` for development with hot reloading.
60+
- Use `npm run build` for production builds.
61+
- Use `npm run lint:js` for JavaScript linting.
62+
- Use `npm run format:js` for code formatting.
63+
- **State Management with `@wordpress/data`:** Understand and utilize `@wordpress/data` for managing application state.
64+
- Use `useSelect` to access data from stores.
65+
- Use `useDispatch` to dispatch actions to stores.
66+
- Define clear selectors and actions for data store interactions.
67+
- **Component Reusability:** Design and build reusable components in the `packages/components/` directory to promote code sharing and consistency across the UI.
68+
- **Context API for State Management:** Utilize React Context API for managing component-level or feature-specific state, especially within the Block Editor and Query Builder packages.
69+
70+
### Important JavaScript/React Functions and Hooks
71+
72+
- **React Hooks:** Utilize common React hooks like `useState`, `useEffect`, `useContext`, `useCallback`, `useMemo`.
73+
- **`@wordpress/data` Hooks:**
74+
- `useSelect`: Hook to select data from WordPress data stores.
75+
- `useDispatch`: Hook to dispatch actions to WordPress data stores.
76+
- `withSelect`: Higher-order component for connecting components to data stores (less common in modern React).
77+
- `withDispatch`: Higher-order component for connecting components to dispatch actions (less common in modern React).
78+
- **WordPress Components (`@wordpress/components`):** Utilize pre-built WordPress components from the `@wordpress/components` library for UI elements (buttons, inputs, selects, modals, etc.).
79+
- **WordPress Block Editor APIs (`@wordpress/block-editor`, `@wordpress/blocks`):** When working with Block Editor integration, use APIs from `@wordpress/block-editor` and `@wordpress/blocks` to extend blocks, register block attributes, and interact with the editor.
80+
- **REST API Interactions:** Use `wp.apiFetch` (or standard `fetch` API) for making requests to WordPress REST API endpoints.
81+
82+
### Debugging JavaScript/React Code
83+
84+
- **Browser Developer Tools:** Use browser developer tools (Chrome DevTools, Firefox Developer Tools) extensively for debugging JavaScript code.
85+
- **Console:** Use `console.log()`, `console.warn()`, `console.error()` for logging messages.
86+
- **Debugger:** Set breakpoints in the code and step through execution.
87+
- **React Developer Tools Extension:** Use the React Developer Tools browser extension to inspect React component trees, props, and state.
88+
- **Network Tab:** Inspect network requests to REST API endpoints.
89+
- **`WP_DEBUG` (WordPress):** Enabling `WP_DEBUG` in `wp-config.php` can sometimes provide additional JavaScript error information in the browser console.
90+
- **Source Maps:** Ensure source maps are enabled in development builds to debug against the original source code instead of bundled code.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
description: Rules for the PHP codebase of the Content Control Plugin
3+
globs: ["**/*.php"]
4+
alwaysApply: false
5+
---
6+
# Content Control Plugin - PHP Codebase Rules
7+
8+
These rules are specific to the PHP codebase of the Content Control plugin and provide guidance for AI agents working with the backend logic.
9+
10+
## PHP Architecture Overview
11+
12+
The Content Control plugin's backend is primarily written in PHP, following WordPress coding standards and best practices. The architecture is modular and object-oriented, with a clear separation of concerns.
13+
14+
### Key Directories
15+
16+
- **`classes/`**: Contains the core PHP logic of the plugin, organized into subdirectories based on functionality.
17+
- **`Base/`**: Abstract base classes and the dependency injection container.
18+
- **`Controllers/`**: Handles specific areas of functionality (Admin, Frontend, Compatibility, REST API).
19+
- **`Installers/`**: Classes for plugin installation and upgrades.
20+
- **`Interfaces/`**: Defines interfaces for controllers and upgrades.
21+
- **`Models/`**: Data models representing plugin entities (Restriction, Rule, Group).
22+
- **`Plugin/`**: Core plugin classes (Core, Autoloader, License, Connect, etc.).
23+
- **`QueryMonitor/`**: Integration with the Query Monitor plugin.
24+
- **`RestAPI/`**: REST API endpoint implementations.
25+
- **`RuleEngine/`**: Classes related to the Rule Engine logic.
26+
- **`Services/`**: Reusable services and utilities.
27+
- **`Upgrades/`**: Classes for specific upgrade routines (data migrations).
28+
- **`inc/`**: Contains utility functions, organized into subdirectories.
29+
- **`functions/`**: Various function files (compatibility, content, developers, options, rules, etc.).
30+
- **`deprecated/`**: Deprecated classes and functions.
31+
- **`bin/`**: Utility scripts, including stub generation scripts.
32+
- **`tests/`**: PHPUnit tests for the plugin.
33+
34+
### Important PHP Classes
35+
36+
- **`classes/Plugin/Core.php`**: The main plugin class, responsible for initialization, service registration, and defining plugin paths.
37+
- **`classes/RuleEngine/RuleEngine.php`**: (Note: Class name might be `Handler.php` or `Rules.php`) The core Rule Engine class that evaluates rules and restrictions.
38+
- **`classes/Models/Restriction.php`**: The data model for a Restriction, handling loading settings, checking rules, and providing access to restriction data.
39+
- **`classes/Controllers/Admin/*.php`**: Controllers for admin-related functionality (Settings Page, Upgrades, Reviews).
40+
- **`classes/Controllers/Frontend/*.php`**: Controllers for frontend restriction logic (Main Query, Post Content, REST API).
41+
- **`classes/RestAPI/*.php`**: REST API endpoint controllers.
42+
- **`classes/Services/*.php`**: Service classes like `Restrictions.php`, `Options.php`, `Logging.php`, `UpgradeStream.php`.
43+
- **`classes/Base/Container.php`**: Dependency injection container (Pimple).
44+
45+
### Coding Standards and Best Practices (PHP)
46+
47+
- **WordPress Coding Standards for PHP:** Strictly adhere to the WordPress PHP coding standards.
48+
- Use spaces for indentation, not tabs.
49+
- Follow WordPress PHPDoc standards for documentation.
50+
- Use lowercase with hyphens for function names.
51+
- Use underscores for class and method names (in many legacy parts, but new code should aim for camelCase).
52+
- Sanitize and escape data properly to prevent security vulnerabilities.
53+
- Use nonces for form submissions and AJAX requests.
54+
- **Object-Oriented Programming (OOP):** Utilize OOP principles for code organization and reusability.
55+
- **Dependency Injection (DI):** Leverage the simple DI container (`classes/Base/Container.php`) for managing services and dependencies.
56+
- **Modularity and Separation of Concerns:** Keep code modular and separate concerns into different classes and functions.
57+
- **Code Documentation:** Write clear and comprehensive PHPDoc comments for all classes, methods, and functions.
58+
- **Performance Optimization:** Write efficient code, optimize database queries, and use caching where appropriate.
59+
- **Error Handling and Logging:** Implement proper error handling and use the `Logging` service for logging important events and errors.
60+
- **Security Best Practices:** Follow WordPress security best practices to prevent vulnerabilities.
61+
62+
### Important PHP Functions and Hooks
63+
64+
- **WordPress Options API:** Use `get_option()`, `update_option()`, `delete_option()` for managing plugin settings.
65+
- **WordPress Custom Post Types API:** Use `register_post_type()` to register the `cc_restriction` custom post type.
66+
- **WordPress REST API Functions:** Use `register_rest_route()` to register REST API endpoints.
67+
- **WordPress Filters and Actions:** Utilize WordPress action and filter hooks for extending plugin functionality and integrating with WordPress core and other plugins.
68+
- `the_content` filter: Used to filter post content and apply restrictions.
69+
- `pre_get_posts` action: Used to modify the main query and apply restrictions to content listings.
70+
- `rest_api_init` action: Used to register REST API endpoints.
71+
- Numerous custom action and filter hooks within the plugin codebase.
72+
- **Plugin API Functions (in `inc/functions/developers.php`):**
73+
- `content_has_restrictions()`: Checks if content has any restrictions applied.
74+
- `user_can_view_content()`: Checks if the current user can view specific content.
75+
- `content_is_restricted()`: Checks if content is currently restricted for the current user.
76+
- `get_applicable_restriction()`: Gets the most applicable restriction for the current context.
77+
- `get_all_applicable_restrictions()`: Gets all applicable restrictions for the current context.
78+
79+
### Debugging PHP Code
80+
81+
- **`error_log()`:** Use `error_log()` to write debug messages to the PHP error log.
82+
- **`WP_DEBUG`:** Enable `WP_DEBUG` in `wp-config.php` for more detailed error reporting.
83+
- **`Logging` Service:** Use the `plugin('logging')->log()` method to log messages using the plugin's logging service.
84+
- **Xdebug:** Consider using Xdebug for step-by-step debugging and code inspection.
85+
- **Query Monitor Plugin:** Use the Query Monitor plugin to inspect database queries, PHP errors, hooks, and other aspects of WordPress execution.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
description: Rules for the Content Control Plugin
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Content Control Plugin - AI Agent Rules
7+
8+
These rules provide context and guidance for AI agents working with the Content Control plugin codebase.
9+
10+
## Plugin Description
11+
12+
Content Control is a WordPress plugin designed to provide fine-grained control over content visibility. It allows administrators to restrict access to various parts of their WordPress site based on a flexible rule engine. Restrictions can be applied based on user roles, login status, specific dates/times, device types, and custom rules.
13+
14+
The plugin is built with a modular architecture, utilizing both PHP for the backend and React for the admin user interface. It leverages WordPress best practices and coding standards, aiming for performance, security, and extensibility.
15+
16+
## Key Features
17+
18+
- **Rule-Based Restrictions:** Define complex rules using a combination of conditions and logical operators (AND/OR).
19+
- **Multiple Restriction Types:** Restrict content based on user roles, login status, date/time, device type, and more.
20+
- **Flexible Protection Methods:** Choose how restricted content is handled: redirect to another page, replace content with a message, or hide content entirely.
21+
- **Block-Level Control:** Apply restrictions directly to individual Gutenberg blocks within post content.
22+
- **Widget Restrictions:** Control the visibility of WordPress widgets based on rules.
23+
- **REST API Control:** Secure WordPress REST API endpoints by applying content restrictions.
24+
- **Extensibility:** Developers can extend the plugin by creating custom rules and integrations.
25+
- **Settings Page:** A comprehensive settings page built with React for managing plugin options and restrictions.
26+
- **Developer-Friendly:** Well-documented codebase with clear architecture, making it easy for developers to understand and contribute.
27+
28+
## Architecture Overview
29+
30+
The plugin follows a modular architecture with distinct components for the backend (PHP) and frontend (React).
31+
32+
### PHP Backend
33+
34+
- **Rule Engine:** Core logic for evaluating rules and applying restrictions (`classes/RuleEngine/`).
35+
- **Restrictions CPT:** Restrictions are stored as a custom post type (`cc_restriction`).
36+
- **Controllers:** Handle specific functionalities like admin settings, frontend restrictions, and REST API endpoints (`classes/Controllers/`).
37+
- **Models:** Represent data structures like `Restriction` and `Rule` (`classes/Models/`).
38+
- **Services:** Provide reusable business logic and utilities (`classes/Services/`).
39+
- **REST API Endpoints:** Expose plugin functionality via WordPress REST API (`classes/RestAPI/`).
40+
41+
### React Admin UI
42+
43+
- **Settings Page:** React application for managing plugin settings and restrictions (`packages/settings-page/`).
44+
- **Block Editor UI:** Integrations with Gutenberg block editor for block-level restrictions (`packages/block-editor/`).
45+
- **Data Stores:** Uses `@wordpress/data` for client-side state management (`packages/core-data/`).
46+
- **Reusable Components:** React components used across the admin UI (`packages/components/`).
47+
- **Query Builder UI:** React-based UI for building complex rule queries (`packages/query-builder/`).
48+
49+
## Key Concepts
50+
51+
- **Restrictions:** Saved configurations that combine rules and protection settings to control content access.
52+
- **Rules:** Individual conditions evaluated by the Rule Engine (e.g., "User Role is Administrator").
53+
- **Rule Engine:** The system that processes restrictions and determines if they should be applied.
54+
- **Contexts:** Define the environment in which rules are evaluated (e.g., 'main', 'blocks', 'restapi').
55+
- **Protection Methods:** Actions taken when a restriction's rules are met (e.g., redirect, replace content).
56+
57+
## Coding Standards and Best Practices
58+
59+
- **WordPress Coding Standards:** Adheres to WordPress PHP and JavaScript coding standards.
60+
- **Security:** Implements security best practices, including data sanitization, validation, and nonce verification.
61+
- **Performance:** Optimized for performance with efficient queries and asset management.
62+
- **Accessibility:** Follows WCAG guidelines for accessible user interfaces.
63+
- **Internationalization:** Uses WordPress internationalization functions for translatable strings.
64+
- **Modular Design:** Code is organized into modules with clear separation of concerns.
65+
- **Object-Oriented Programming (PHP):** Utilizes OOP principles in PHP codebase.
66+
- **React and `@wordpress/scripts` (JavaScript):** Uses modern React practices and WordPress `@wordpress/scripts` build tooling for JavaScript development.
67+
68+
## Important File Locations
69+
70+
- **Plugin Entry Point:** `content-control.php`
71+
- **Main Plugin Class:** `classes/Plugin/Core.php`
72+
- **Rule Engine Classes:** `classes/RuleEngine/`
73+
- **Restriction Model:** `classes/Models/Restriction.php`
74+
- **Settings Page React App:** `packages/settings-page/src/App.tsx`
75+
- **Block Editor Integration:** `packages/block-editor/src/`
76+
- **Core Data Stores:** `packages/core-data/src/`
77+
- **Reusable Components:** `packages/components/src/`
78+
- **Documentation Files:** `docs/`

0 commit comments

Comments
 (0)