define_constants();
self::$instance->load_dependencies();
self::$instance->init_hooks();
}
return self::$instance;
}
/**
* Define core plugin constants.
* Using constants makes it easy to reference paths and versions throughout
* the rest of our plugin without hardcoding strings, ensuring easy updates.
*/
private function define_constants() {
define( 'TT24_FORMS_VERSION', '1.1.0' );
define( 'TT24_FORMS_FILE', __FILE__ );
// Path constants for requiring PHP files securely
define( 'TT24_FORMS_PATH', plugin_dir_path( __FILE__ ) );
define( 'TT24_FORMS_INC_PATH', TT24_FORMS_PATH . 'includes/' );
define( 'TT24_FORMS_ADMIN_PATH', TT24_FORMS_PATH . 'admin/' );
define( 'TT24_FORMS_PUBLIC_PATH', TT24_FORMS_PATH . 'public/' );
// URL constants for enqueuing CSS and JS securely
define( 'TT24_FORMS_URL', plugin_dir_url( __FILE__ ) );
define( 'TT24_FORMS_ASSETS_URL', TT24_FORMS_URL . 'assets/' );
}
/**
* Load all required plugin files.
* We separate core, admin, and public files to keep the architecture clean.
*/
private function load_dependencies() {
// Core Logic (Required everywhere)
require_once TT24_FORMS_INC_PATH . 'class-24tt-security.php';
require_once TT24_FORMS_INC_PATH . 'class-24tt-db.php';
require_once TT24_FORMS_INC_PATH . 'class-24tt-mailer.php';
require_once TT24_FORMS_INC_PATH . 'class-24tt-export.php';
// Admin Logic (Only load if we are in the WordPress dashboard)
if ( is_admin() ) {
require_once TT24_FORMS_ADMIN_PATH . 'class-24tt-admin-menu.php';
require_once TT24_FORMS_ADMIN_PATH . 'class-24tt-forms-table.php';
require_once TT24_FORMS_ADMIN_PATH . 'class-24tt-form-builder.php';
require_once TT24_FORMS_ADMIN_PATH . 'class-24tt-entries.php';
}
// Frontend Logic (Required for rendering shortcodes and blocks)
require_once TT24_FORMS_PUBLIC_PATH . 'class-24tt-frontend.php';
require_once TT24_FORMS_PUBLIC_PATH . 'class-24tt-submission.php';
}
/**
* Initialize WordPress hooks.
* This sets up the activation routines.
*/
private function init_hooks() {
// Trigger the activation method when the plugin is activated via WP Admin
register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) );
// NEW: Add custom meta links to the WordPress Plugins list page
add_filter( 'plugin_row_meta', array( $this, 'add_plugin_row_meta_links' ), 10, 2 );
}
/**
* Plugin Activation Routine.
* This function runs strictly ONCE when the user clicks "Activate" in WordPress.
* It is responsible for setting up the database and assigning user roles/capabilities.
*/
public function activate_plugin() {
// 1. Create the custom database tables
if ( class_exists( 'TT24_DB' ) ) {
TT24_DB::create_tables();
}
// 2. Assign custom capabilities to the Administrator role
$this->assign_capabilities();
}
/**
* Assign Custom Capabilities for Role-Based Access Control (RBAC).
* This ensures only authorized users can build forms or view entries.
* Later, we can build a UI to let Admins grant these to Editors or Authors.
*/
private function assign_capabilities() {
// Fetch the default WordPress Administrator role
$admin_role = get_role( 'administrator' );
if ( $admin_role ) {
// Capability to create, edit, and delete form structures
$admin_role->add_cap( 'manage_tt24_forms' );
// Capability to view, export, and delete form submissions (data)
$admin_role->add_cap( 'view_tt24_entries' );
}
}
/**
* Add custom meta links below the plugin description on the Plugins page.
* * @since 1.1.0
* @param array $links The array of plugin row meta links.
* @param string $file The core plugin file path.
* @return array Updated array of links.
*/
public function add_plugin_row_meta_links( $links, $file ) {
// Only inject these links on our specific plugin row
if ( plugin_basename( TT24_FORMS_FILE ) === $file ) {
$custom_links = array(
'docs' => '' . esc_html__( 'Documentation', '24tt-unrestricted-forms' ) . '',
'support' => '' . esc_html__( 'Facebook Community', '24tt-unrestricted-forms' ) . '',
'rate' => '' . esc_html__( 'Rate the plugin', '24tt-unrestricted-forms' ) . ' ★★★★★'
);
return array_merge( $links, $custom_links );
}
return $links;
}
}
/**
* Main initialization wrapper function.
* We use this function to boot up the class instead of a global variable.
* This keeps the global namespace perfectly clean.
* @return TT24_Unrestricted_Forms
*/
function tt24_run_unrestricted_forms() {
return TT24_Unrestricted_Forms::instance();
}
// Start the engine!
tt24_run_unrestricted_forms();