Skip to content

Commit e720f9f

Browse files
committed
First template
0 parents  commit e720f9f

14 files changed

Lines changed: 1072 additions & 0 deletions

%plugin_name%.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Plugin Name: %plugin_name%
4+
* Plugin URI: %plugin_uri%
5+
* Description: %plugin_description%
6+
* Version: %plugin_version%
7+
* Author: %plugin_author%
8+
* Author URI: %plugin_author_uri%
9+
* Text Domain: %plugin_slug%
10+
* Domain Path: /languages
11+
* Requires at least: 5.0
12+
* Tested up to: 6.3
13+
* Requires PHP: 8.1
14+
* Network: false
15+
* License: GPL v2 or later
16+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
// Prevent direct access
22+
if (! defined('ABSPATH')) {
23+
exit;
24+
}
25+
26+
// Define plugin constants
27+
define('%PLUGIN_NAME%_VERSION', '%plugin_version%');
28+
define('%PLUGIN_NAME%_PLUGIN_FILE', __FILE__);
29+
define('%PLUGIN_NAME%_PLUGIN_DIR', plugin_dir_path(__FILE__));
30+
define('%PLUGIN_NAME%_PLUGIN_URL', plugin_dir_url(__FILE__));
31+
32+
// Register the plugin with Pollora framework
33+
if (class_exists('Pollora\\Plugin\\Application\\Services\\PluginRegistrar')) {
34+
$registrar = app('Pollora\\Plugin\\Application\\Services\\PluginRegistrar');
35+
$registrar->register('%plugin_name%', __DIR__);
36+
}
37+
38+
/**
39+
* Initialize the plugin.
40+
*/
41+
function %plugin_function_name%_init(): void
42+
{
43+
// Load plugin textdomain for translations
44+
load_plugin_textdomain(
45+
'%plugin_slug%',
46+
false,
47+
dirname(plugin_basename(__FILE__)) . '/languages'
48+
);
49+
50+
// Initialize plugin functionality
51+
if (class_exists('Plugin\\%plugin_namespace%\\%plugin_namespace%Plugin')) {
52+
$plugin = new Plugin\%plugin_namespace%\%plugin_namespace%Plugin();
53+
54+
// Register activation/deactivation hooks through the plugin class
55+
register_activation_hook(__FILE__, [$plugin, 'activate']);
56+
register_deactivation_hook(__FILE__, [$plugin, 'deactivate']);
57+
register_uninstall_hook(__FILE__, [Plugin\%plugin_namespace%\%plugin_namespace%Plugin::class, 'uninstall']);
58+
}
59+
}
60+
add_action('plugins_loaded', '%plugin_function_name%_init');
61+
62+
/**
63+
* Admin notices for missing dependencies.
64+
*/
65+
function %plugin_function_name%_admin_notices(): void
66+
{
67+
if (! class_exists('Pollora\\Plugin\\Application\\Services\\PluginManager')) {
68+
echo view('admin-notice');
69+
}
70+
}
71+
add_action('admin_notices', '%plugin_function_name%_admin_notices');

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# %plugin_name%
2+
3+
%plugin_description%
4+
5+
## Description
6+
7+
This plugin is built using the Pollora Framework, which provides a modern development experience by bridging Laravel and WordPress.
8+
9+
## Installation
10+
11+
1. Upload the plugin files to the `/wp-content/plugins/%plugin_slug%` directory
12+
2. Activate the plugin through the 'Plugins' screen in WordPress
13+
3. Use the Settings -> %plugin_name% screen to configure the plugin
14+
15+
## Features
16+
17+
- Modern PHP 8.1+ codebase
18+
- Laravel-style architecture with Pollora Framework
19+
- PSR-4 autoloading
20+
- Service provider pattern
21+
- Attribute-driven configuration
22+
- Comprehensive testing suite
23+
24+
## Requirements
25+
26+
- WordPress 5.0 or higher
27+
- PHP 8.1 or higher
28+
- Pollora Framework
29+
30+
## Configuration
31+
32+
The plugin can be configured through the WordPress admin interface or by modifying the configuration files in the `config/` directory.
33+
34+
## Development
35+
36+
### Directory Structure
37+
38+
```
39+
%plugin_slug%/
40+
├── app/ # Application code (PSR-4 autoloaded)
41+
│ ├── Providers/ # Service providers
42+
│ └── %plugin_namespace%Plugin.php # Main plugin class
43+
├── assets/ # CSS, JS, and image files
44+
├── config/ # Configuration files
45+
├── languages/ # Translation files
46+
├── views/ # Blade templates
47+
├── routes/ # Route definitions
48+
└── %plugin_name%.php # Main plugin file
49+
```
50+
51+
### Service Providers
52+
53+
The plugin uses Laravel-style service providers for dependency injection and service registration. The main service provider is located at `app/Providers/PluginServiceProvider.php`.
54+
55+
### Autoloading
56+
57+
The plugin follows PSR-4 autoloading standards with the namespace `Plugin\%plugin_namespace%\`.
58+
59+
### Hooks and Filters
60+
61+
WordPress hooks and filters can be registered using PHP 8 attributes or traditional WordPress functions.
62+
63+
## Support
64+
65+
For support and documentation, please visit [%plugin_uri%](%plugin_uri%).
66+
67+
## Contributing
68+
69+
Contributions are welcome! Please feel free to submit a Pull Request.
70+
71+
## License
72+
73+
This plugin is licensed under the GPL v2 or later.
74+
75+
## Changelog
76+
77+
### %plugin_version%
78+
- Initial release
79+
80+
## Credits
81+
82+
- Developed by [%plugin_author%](%plugin_author_uri%)
83+
- Built with [Pollora Framework](https://pollora.dev)

app/%plugin_namespace%Plugin.stub

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Plugin\%plugin_namespace%;
6+
7+
use Pollora\Attributes\Action;
8+
use Pollora\Hook\Domain\Contracts\Hooks;
9+
10+
/**
11+
* Main plugin class for %plugin_name%.
12+
*
13+
* This class serves as the entry point for the plugin and handles
14+
* the initialization of plugin components, hooks, and services.
15+
*
16+
* Uses Pollora's attribute-based hook system for cleaner code organization.
17+
*/
18+
class %plugin_namespace%Plugin implements Hooks
19+
{
20+
/**
21+
* Plugin version.
22+
*
23+
* @var string
24+
*/
25+
protected string $version = '%plugin_version%';
26+
27+
/**
28+
* Plugin slug.
29+
*
30+
* @var string
31+
*/
32+
protected string $slug = '%plugin_slug%';
33+
34+
/**
35+
* Plugin constructor.
36+
*/
37+
public function __construct()
38+
{
39+
// Plugin initialization happens through attribute-based hooks
40+
// Service providers, routes, migrations, etc. are automatically handled by the Modules system
41+
}
42+
43+
/**
44+
* Plugin activation callback.
45+
*
46+
* @return void
47+
*/
48+
public function activate(): void
49+
{
50+
// Plugin activation logic
51+
// Example:
52+
// - Create database tables
53+
// - Set default options
54+
// - Schedule cron events
55+
56+
// Flush rewrite rules
57+
flush_rewrite_rules();
58+
}
59+
60+
/**
61+
* Plugin deactivation callback.
62+
*
63+
* @return void
64+
*/
65+
public function deactivate(): void
66+
{
67+
// Plugin deactivation logic
68+
// Example:
69+
// - Clear scheduled cron events
70+
// - Clean up temporary data
71+
72+
// Flush rewrite rules
73+
flush_rewrite_rules();
74+
}
75+
76+
/**
77+
* Plugin uninstall callback.
78+
*
79+
* @return void
80+
*/
81+
public static function uninstall(): void
82+
{
83+
// Plugin uninstall logic
84+
// Example:
85+
// - Remove database tables
86+
// - Delete plugin options
87+
// - Clean up all plugin data
88+
}
89+
90+
/**
91+
* WordPress init hook callback.
92+
*
93+
* This method is automatically called on the 'init' WordPress hook
94+
* thanks to the Action attribute.
95+
*
96+
* @return void
97+
*/
98+
#[Action('init', priority: 10)]
99+
public function onInit(): void
100+
{
101+
// Initialize plugin functionality that requires WordPress to be fully loaded
102+
// Example:
103+
// - Register post types
104+
// - Register taxonomies
105+
// - Load text domain
106+
107+
load_plugin_textdomain(
108+
$this->slug,
109+
false,
110+
dirname(plugin_basename(%PLUGIN_NAME%_PLUGIN_FILE)) . '/languages'
111+
);
112+
}
113+
114+
115+
/**
116+
* Example of multiple hooks on the same method.
117+
*
118+
* This method will be called on both 'wp_loaded' and 'template_redirect' hooks.
119+
*/
120+
#[Action('wp_loaded', priority: 20)]
121+
#[Action('template_redirect', priority: 10)]
122+
public function onWordPressLoaded(): void
123+
{
124+
// Code that runs when WordPress is fully loaded
125+
// This demonstrates how to use multiple Action attributes
126+
}
127+
128+
/**
129+
* Example admin initialization.
130+
*
131+
* This method is automatically called on the 'admin_init' WordPress hook
132+
* thanks to the Action attribute.
133+
*/
134+
#[Action('admin_init', priority: 10)]
135+
public function onAdminInit(): void
136+
{
137+
// Initialize admin-specific functionality
138+
// Example:
139+
// - Register settings
140+
// - Add admin pages
141+
// - Handle admin-only features
142+
}
143+
144+
/**
145+
* Example admin menu setup.
146+
*
147+
* This method is automatically called on the 'admin_menu' WordPress hook
148+
* thanks to the Action attribute.
149+
*/
150+
#[Action('admin_menu', priority: 10)]
151+
public function addAdminMenu(): void
152+
{
153+
// Add admin menu items
154+
// Example:
155+
// add_options_page(
156+
// '%plugin_name% Settings',
157+
// '%plugin_name%',
158+
// 'manage_options',
159+
// $this->slug,
160+
// [$this, 'renderSettingsPage']
161+
// );
162+
}
163+
164+
/**
165+
* Get plugin version.
166+
*
167+
* @return string Plugin version
168+
*/
169+
public function getVersion(): string
170+
{
171+
return $this->version;
172+
}
173+
174+
/**
175+
* Get plugin slug.
176+
*
177+
* @return string Plugin slug
178+
*/
179+
public function getSlug(): string
180+
{
181+
return $this->slug;
182+
}
183+
}

0 commit comments

Comments
 (0)