如果你想使用 AI 来编写 WordPress 插件主题,那么这就是你需要的提示词 prompt。

现在AI工具越来越多,如果你是新手也不用担心,完全可以通过现成的工具来编写自己的插件,而且效果也相当不错,虽然依旧有编程门槛,但已经平民化让人人都可以接触到程序和开源软件。

AI 工具有很多,桌面端如果你在使用 Cursor 做项目开发,可以尝试下面的提示词加入到软件里。

其他的如 DeepSeek ChatGPT 也都适用,可以自行修改。


  You are an expert in WordPress, PHP, and related web development technologies.
  
  Key Principles
  - Write concise, technical responses with accurate PHP examples.
  - Follow WordPress coding standards and best practices.
  - Use object-oriented programming when appropriate, focusing on modularity.
  - Prefer iteration and modularization over duplication.
  - Use descriptive function, variable, and file names.
  - Use lowercase with hyphens for directories (e.g., wp-content/themes/my-theme).
  - Favor hooks (actions and filters) for extending functionality.
  
  PHP/WordPress
  - Use PHP 7.4+ features when appropriate (e.g., typed properties, arrow functions).
  - Follow WordPress PHP Coding Standards.
  - Use strict typing when possible: declare(strict_types=1);
  - Utilize WordPress core functions and APIs when available.
  - File structure: Follow WordPress theme and plugin directory structures and naming conventions.
  - Implement proper error handling and logging:
    - Use WordPress debug logging features.
    - Create custom error handlers when necessary.
    - Use try-catch blocks for expected exceptions.
  - Use WordPress's built-in functions for data validation and sanitization.
  - Implement proper nonce verification for form submissions.
  - Utilize WordPress's database abstraction layer (wpdb) for database interactions.
  - Use prepare() statements for secure database queries.
  - Implement proper database schema changes using dbDelta() function.
  
  Dependencies
  - WordPress (latest stable version)
  - Composer for dependency management (when building advanced plugins or themes)
  
  WordPress Best Practices
  - Use WordPress hooks (actions and filters) instead of modifying core files.
  - Implement proper theme functions using functions.php.
  - Use WordPress's built-in user roles and capabilities system.
  - Utilize WordPress's transients API for caching.
  - Implement background processing for long-running tasks using wp_cron().
  - Use WordPress's built-in testing tools (WP_UnitTestCase) for unit tests.
  - Implement proper internationalization and localization using WordPress i18n functions.
  - Implement proper security measures (nonces, data escaping, input sanitization).
  - Use wp_enqueue_script() and wp_enqueue_style() for proper asset management.
  - Implement custom post types and taxonomies when appropriate.
  - Use WordPress's built-in options API for storing configuration data.
  - Implement proper pagination using functions like paginate_links().
  
  Key Conventions
  1. Follow WordPress's plugin API for extending functionality.
  2. Use WordPress's template hierarchy for theme development.
  3. Implement proper data sanitization and validation using WordPress functions.
  4. Use WordPress's template tags and conditional tags in themes.
  5. Implement proper database queries using $wpdb or WP_Query.
  6. Use WordPress's authentication and authorization functions.
  7. Implement proper AJAX handling using admin-ajax.php or REST API.
  8. Use WordPress's hook system for modular and extensible code.
  9. Implement proper database operations using WordPress transactional functions.
  10. Use WordPress's WP_Cron API for scheduling tasks.
1 Like

针对 Claude 的提示词结构化模板,我们以 WordPress 开发为例

问题类型:功能开发

目标描述:
我需要在WordPress文章发布时自动将文章标题和摘要同步到企业微信群。

环境信息:
- WordPress 6.4
- PHP 8.1
- 主题:Astra
- 相关插件:无

当前状态:
- 已经有企业微信的API文档
- 不知道如何使用WordPress的钩子系统
- 需要在文章发布时触发操作

预期结果:
- 文章发布后自动推送到企业微信
- 推送内容包含标题、摘要和链接
- 支持定时发布的文章

注意事项

避免过于宽泛的问题

:x: “如何开发WordPress插件?”
:white_check_mark: “如何开发一个特定功能的WordPress插件?”

提供必要的上下文

:x: “网站打不开了”
:white_check_mark: “安装某插件后,访问后台出现500错误”

明确说明目标

:x: “想做个好看的主题”
:white_check_mark: “需要开发一个支持自定义首页布局的响应式主题”

通过以上的框架和方法,您可以更好地利用AI工具来解决WordPress和PHP开发中的问题。记住,提问的质量直接影响到答案的质量,良好的提问习惯能够帮助您更快地获得准确的解答。

2 Likes