Polycms Cover 1280x720 1

Building a Custom Plugin for PolyCMS: Scaffold Guide

Hacking custom lead workflows, third-party API syncs, or custom shortcodes directly into PolyCMS core files breaks upgradeability and makes debugging regressions across Perfex CRM deployments slow. Mixing business logic into frontend theme folders creates the same maintenance trap whenever you refresh branding.

Building an isolated PolyCMS plugin packages your controllers, database migrations, admin settings, and hooks into one portable, toggleable extension inside Perfex CRM.

Planning which extension points to target before coding? Bookmark PolyCMS Hooks & Filters – Complete Reference for exact action and filter signatures.

Plugin ComponentCore ResponsibilityPerfex CRM Guardrail
plugin.json & BootstrapDeclares name, version, author, and entry fileGuarded with BASEPATH check on line 1
Activation / Install HookCreates prefixed tables and default option keysIdempotent DDL checks preventing duplicate errors
Admin Controllers & ViewsRenders plugin settings inside Perfex adminVerifies staff capabilities and CSRF tokens
Hooks & ShortcodesAlters content, adds head tags, registers widgetsUses unique prefixes to avoid symbol collisions
Uninstall RoutineOptional cleanup of plugin tables and optionsPreserves data on deactivate; cleans on uninstall

1. Structure the Plugin Manifest and Lifecycle Hooks

Place your extension inside modules/poly_cms/plugins/<your-plugin-slug>/ with a clear metadata manifest and main bootstrap file. Separate activation logic (creating prefixed tables and default settings) from deactivation (pausing cron tasks or hooks without deleting user data) and full uninstall cleanup. If your plugin interacts with storefront schemas or catalog feeds, review E-Commerce SEO & GEO in Perfex CRM: PolyStore Variant URLs, Sitemaps & Schema so structured metadata stays consistent.

  • Prefix every database table, option key, function name, and CSS class uniquely to avoid clashes with Perfex modules.
  • Guard all plugin PHP files with defined('BASEPATH') or exit('No direct script access allowed'); and ship blank index.html directory guards.
  • Store plugin configuration inside centralized PolyCMS options rather than writing mutable config files inside plugin folders.

2. Register Admin Settings, Shortcodes, and Safe Queries

Once the plugin bootstrap activates cleanly, attach admin menu items, shortcodes, or frontend content filters using PolyCMS hook registrations. Validate and sanitize every request payload using CodeIgniter input helpers and parameterized query bindings. When testing custom shortcodes inside editorial workflows, verify rendering directly against a real article following Quick Start: Your First Blog Post in PolyCMS.

  • Check Perfex staff permissions (has_permission() or admin guards) before exposing plugin settings or write actions.
  • Escape all admin and frontend output with html_escape() and keep Perfex CSRF validation enabled on every POST form.
  • Load plugin JavaScript and CSS conditionally only on routes or pages where your plugin widgets actually render.

Common Pitfalls and Quick Fixes

  • Activation fails with PHP fatal redeclare error: Wrap helper functions in function_exists() checks or move logic into uniquely namespaced classes.
  • Plugin settings form returns HTTP 419 or CSRF mismatch: Use Perfex form_open() helpers or include the active CSRF token field inside custom AJAX payloads.
  • Database table creation breaks on re-activation: Add CREATE TABLE IF NOT EXISTS or CodeIgniter db->table_exists() checks inside your install routine.

Frequently Asked Questions

How does a PolyCMS plugin differ from a standard Perfex CRM module?

A Perfex CRM module integrates with the core CRM lifecycle inside modules/, whereas a PolyCMS plugin lives inside the PolyCMS plugin ecosystem and hooks specifically into PolyCMS page rendering, shortcodes, MTBuilder blocks, SEO tags, and CMS admin tabs.

Should deactivating a PolyCMS plugin delete its database tables?

No. Deactivation should simply stop loading the plugin runtime hooks while keeping saved settings and database tables intact so administrators can re-enable the plugin safely. Reserve destructive table or option deletion strictly for the explicit uninstall step.

Can a PolyCMS plugin communicate directly with native Perfex CRM models?

Yes. Because PolyCMS runs inside the Perfex CRM CodeIgniter application context, authorized plugins can access CodeIgniter get_instance() models to log leads, attach client metadata, or trigger CRM notifications using parameterized queries and strict permission checks.

How do I package a custom PolyCMS plugin for multiple client installs?

Ensure your manifest version, install migration script, language files, and directory guard files are self-contained inside the plugin folder without hardcoded URLs or local paths, then compress the plugin directory into a clean ZIP archive for deployment.


Comments

Leave a Reply

Your email address will not be published.Required fields are marked *