diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..3c03207 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +18 diff --git a/README.md b/README.md index 6ae434f..da71b62 100644 --- a/README.md +++ b/README.md @@ -62,5 +62,14 @@ We want to be able to render templates easily, even in Twig. In this step, we ar Links: [WPify Templates](https://packagist.org/packages/wpify/templates) +### 06 - WordPress Scripts, Assets and WPify Plugin Utils -[Next step >>>](https://github.com/wpify/plugin-tutorial/tree/06-assets-utils) +Now we have a plugin with custom block, but we need to add some scripts and styles to the plugin. In this step, we are +adding WordPress Scripts and WPify Plugin Utils. + +Links: +[WordPress Scripts](https://www.npmjs.com/package/@wordpress/scripts), +[WPify Plugin Utils](https://packagist.org/packages/wpify/plugin-utils), +[WPify Asset](https://packagist.org/packages/wpify/asset) + +[Next step >>>](https://gitlab.com/wpify/bedrock-skeleton) diff --git a/assets/scripts/plugin-tutorial.js b/assets/scripts/plugin-tutorial.js new file mode 100644 index 0000000..06e8ad6 --- /dev/null +++ b/assets/scripts/plugin-tutorial.js @@ -0,0 +1,3 @@ +document.addEventListener('DOMContentLoaded', function () { + alert('Plugin Tutorial JS'); +}); diff --git a/assets/styles/plugin-tutorial.scss b/assets/styles/plugin-tutorial.scss new file mode 100644 index 0000000..761a7fb --- /dev/null +++ b/assets/styles/plugin-tutorial.scss @@ -0,0 +1,5 @@ +.book-link { + border: 1px solid red; + border-radius: 5px; + padding: 10px 20px; +} diff --git a/bootstrap.php b/bootstrap.php index adc387f..02cdbbd 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -19,6 +19,7 @@ use WpifyPluginTutorialDeps\DI\NotFoundException; use WpifyPluginTutorial\Plugin; use WpifyPluginTutorialDeps\Wpify\Model\Manager; +use WpifyPluginTutorialDeps\Wpify\PluginUtils\PluginUtils; use WpifyPluginTutorialDeps\Wpify\Templates\TwigTemplates; use WpifyPluginTutorialDeps\Wpify\Templates\WordPressTemplates; @@ -41,6 +42,7 @@ function wpifypt_container(): Container { if ( empty( $container ) ) { $containerBuilder = new ContainerBuilder(); $containerBuilder->addDefinitions( array( + PluginUtils::class => create()->constructor( __FILE__ ), WordPressTemplates::class => create()->constructor( array( plugin_dir_path( __FILE__ ) . 'templates', ) ), diff --git a/composer-deps.json b/composer-deps.json index 0404001..717c578 100644 --- a/composer-deps.json +++ b/composer-deps.json @@ -4,6 +4,8 @@ "php-di/php-di": "^7.0", "wpify/custom-fields": "^3.9", "wpify/model": "^4.0", - "wpify/templates": "^3.0" + "wpify/templates": "^3.0", + "wpify/plugin-utils": "^1.0", + "wpify/asset": "^1.2" } } diff --git a/package.json b/package.json new file mode 100644 index 0000000..87c392b --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "@wordpress/scripts": "^26.6.0" + }, + "scripts": { + "start": "wp-scripts start", + "build": "wp-scripts build" + } +} diff --git a/src/Frontend.php b/src/Frontend.php new file mode 100644 index 0000000..4405822 --- /dev/null +++ b/src/Frontend.php @@ -0,0 +1,13 @@ +wp_script( $utils->get_plugin_path( 'build/plugin-tutorial.js' ) ); + $asset->wp_script( $utils->get_plugin_path( 'build/plugin-tutorial.css' ) ); + } +} diff --git a/src/Plugin.php b/src/Plugin.php index 53f2e36..240dd6c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -20,6 +20,7 @@ public function __construct( TaxonomiesManager $taxonomies_manager, BlocksManager $blocks_manager, RepositoriesManager $repositories_manager, + Frontend $frontend, ) { // stuff to do on plugin load } diff --git a/templates/blocks/book-link.php b/templates/blocks/book-link.php index 4eb6420..2da303a 100644 --- a/templates/blocks/book-link.php +++ b/templates/blocks/book-link.php @@ -11,7 +11,7 @@ return; } ?> -> + class="book-link"> +

{{ title }} {% if isbn %} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..0dbfd62 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,11 @@ +const defaultConfig = require('@wordpress/scripts/config/webpack.config'); + +module.exports = { + ...defaultConfig, + entry: { + 'plugin-tutorial': [ + './assets/scripts/plugin-tutorial.js', + './assets/styles/plugin-tutorial.scss', + ], + }, +};