Skip to content

Commit

Permalink
Develop (#41)
Browse files Browse the repository at this point in the history
## *What has changed?*:

- Disable WordPress' root padding
[cff7e92](cff7e92)
- Add 10% inner saftey distance to all labels
[779f2bf](779f2bf)
- Make template strings translateable
[1ddbc50](1ddbc50)
- Add body-class when block is in use
[293ca9a](293ca9a)
- Recognise paper orientation in browser print dialog
[4942323](4942323)
- NEW FAQ 'How does the block work?'
[a607b2d](a607b2d)
- Try to better align with plugin-readme guidelines
[45a21b7](45a21b7)
- Increase minimum required PHP to 8.1 )

## *Why was it needed?*:

#6 

---

### Code Checklist
- [ ] tested
- [x] documented
  • Loading branch information
carstingaxion authored May 29, 2024
2 parents 45091d8 + 9390683 commit f13b775
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 178 deletions.
121 changes: 66 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Label Printing

Requires at least: 6.2
Tested up to: 6.3.1
Requires PHP: 7.4
Stable tag: 0.2.0
License: GPL3+
Contributors: carstenbach
Stable tag: 0.2.1
Tested up to: 6.5.3
Requires at least: 6.3
Requires PHP: 8.1
License: GPL v3 or later
Tags: Label, print, print.css, block

Contributors: carstenbach

![](.wordpress-org/banner-1544x500.png)

Expand Down Expand Up @@ -116,7 +115,7 @@ The installation process for the ***Label Printing* block** plugin is straightfo

### Installation from within WordPress

1. Visit **Plugins** > Add New**.
1. Visit **Plugins** > **Add New**.
2. Search for **Label Printing**.
3. Install and activate the Label Printing plugin.

Expand All @@ -128,62 +127,77 @@ The installation process for the ***Label Printing* block** plugin is straightfo

### Install via composer

1. Install via command line
```sh
composer require figuren-theater/label-printing
```
1. Install via command line `composer require figuren-theater/label-printing`
2. Visit **Plugins**.
3. Activate the Label Printing plugin.

## Screenshots

1. Insert the Label Printing block
2. Choose your pre-defined Label
3. Switch visually between different label presets
4. Fill in your label content
5. Check everything in your browsers print dialog, exclude pages with header and footer and finally print your labels.

## Frequently Asked Questions

### What are default label sizes that will be created?

The default labels, if not changed via the `Figuren_Theater\Label_Printing\Patterns\bootstrap_labels` filter, are:

```php
$bootstrap_labels = [
[
'name' => 'A6 Landscape',
'width' => 148,
'height' => 105,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
[
'name' => 'A6 Landscape (with Top-Bottom-Borders)',
'width' => 148,
'height' => 90,
'a4_border_tb' => 15,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
[
'name' => 'A8 Portrait',
'width' => 52.5,
'height' => 74,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'portrait',
],
[
'name' => 'A8 Landscape',
'width' => 74,
'height' => 52.5,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
];
```
`
\$bootstrap_labels = [
[
'name' => 'A6 Landscape',
'width' => 148,
'height' => 105,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
[
'name' => 'A6 Landscape (with Top-Bottom-Borders)',
'width' => 148,
'height' => 90,
'a4_border_tb' => 15,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
[
'name' => 'A8 Portrait',
'width' => 52.5,
'height' => 74,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'portrait',
],
[
'name' => 'A8 Landscape',
'width' => 74,
'height' => 52.5,
'a4_border_tb' => 0,
'a4_border_lr' => 0,
'orientation' => 'landscape',
],
];
`

### Why should I use a `blank.php` template

Make sure to only *print* what you really need. If the Print Preview in your browser shows your normal header including logo and navigation, consider selecting only the necessary page in your native print dialog.

Using a `blank.php` template ensures that only the necessary content is printed. If your theme provides this template, it's the best choice to avoid unnecessary headers, post titles, and footers in your printed materials.

### How does the block work?

`figuren-theater/label-printing` is a custom block that uses normal `innerBlocks` to keep the blocks, you are going to add to your label.

To preview the block in the editor and also to render it on the front-end, it uses a hidden, second block called `figuren-theater/label-proxy`. This is a lightweight version of a reusable block, that only works within one post, and not across multiples.

Depending on your selected **pre-defined label** the `…/label-proxy` block will be duplicated as often as the dimensions of the selected label allow. In other words, your label will be fitted into an A4 print-template as often as possible.



## Standards and best-practices, this plugin follows

- ✅ This project is licensed under the **GPL-3.0-or-later**, see the LICENSE file for details
Expand Down Expand Up @@ -212,13 +226,10 @@ Using a `blank.php` template ensures that only the necessary content is printed.
- de_DE
- de_DE_formal

## Screenshots
## Upgrade Notice

1. Insert the Label Printing block
2. Choose your pre-defined Label
3. Switch visually between different label presets
4. Fill in your label content
5. Check everything in your browsers print dialog, exclude pages with header and footer and finally print your labels.
(silence is golden)

<!-- changelog -->
## Changelog

<!-- changelog -->
27 changes: 25 additions & 2 deletions inc/block-styles/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @return void
*/
function register() :void {
function register(): void {
\add_action( 'init', __NAMESPACE__ . '\\bootstrap', 1 );
}

Expand All @@ -29,7 +29,7 @@ function register() :void {
*
* @return void
*/
function bootstrap() :void {
function bootstrap(): void {

// Register A4 portrait block style.
\register_block_style(
Expand All @@ -52,5 +52,28 @@ function bootstrap() :void {
'inline_style' => '.wp-block-group.is-style-label-overview-landscape { --label-printing-doc-width: 29.7cm; --label-printing-doc-height: 21cm }',
]
);

\add_filter( 'body_class', __NAMESPACE__ . '\\body_class' );
}

/**
* Add a CSS class to the <body> element if 'label-printing' block is present and is a singular-view.
*
* @see https://developer.wordpress.org/reference/hooks/body_class/
* @see https://developer.wordpress.org/reference/functions/has_block/
*
* @param string[] $classes CSS classes that will be added to the <body> element by WordPress.
*
* @return string[]
*/
function body_class( array $classes ): array {

if ( ! \is_singular() || \is_admin() ) {
return $classes;
}

if ( \has_block( 'figuren-theater/label-printing' ) ) {
$classes[] = 'is-label-printing';
}
return $classes;
}
29 changes: 15 additions & 14 deletions inc/block-variations/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @return void
*/
function register() :void {
function register(): void {
\add_action( 'init', __NAMESPACE__ . '\\register_assets', 5 );
\add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_assets' );
}
Expand All @@ -24,7 +24,7 @@ function register() :void {
*
* @return void
*/
function register_assets() :void {
function register_assets(): void {
\array_map( __NAMESPACE__ . '\\register_asset', get_assets() );
}

Expand All @@ -33,7 +33,7 @@ function register_assets() :void {
*
* @return string[] Array of asset slugs.
*/
function get_assets() : array {
function get_assets(): array {
return [
'label-overview',
];
Expand All @@ -48,7 +48,7 @@ function get_assets() : array {
*
* @return void
*/
function register_asset( string $asset ) : void {
function register_asset( string $asset ): void {

$dir = Label_Printing\DIRECTORY;

Expand All @@ -59,27 +59,28 @@ function register_asset( string $asset ) : void {
$error_message = "You need to run `npm start` or `npm run build` for the '$asset' block-asset first.";

if ( ! file_exists( $script_asset_path ) ) {
if ( \in_array( wp_get_environment_type(), [ 'local', 'development' ], true ) ) {
if ( \in_array( \wp_get_environment_type(), [ 'local', 'development' ], true ) ) {
throw new \Error(
$error_message
\esc_html( $error_message )
);
} else {
\error_log( $error_message );
\error_log( $error_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
return;
}
}

$index_js = "$path/$asset.js";
$script_asset = require $script_asset_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable

wp_register_script(
\wp_register_script(
"label-printing--$asset",
plugins_url( $index_js, "$dir/plugin.php" ),
\plugins_url( $index_js, "$dir/plugin.php" ),
$script_asset['dependencies'],
$script_asset['version']
$script_asset['version'],
true
);

wp_set_script_translations(
\wp_set_script_translations(
"label-printing--$asset",
'label-printing',
"$dir/languages"
Expand All @@ -91,7 +92,7 @@ function register_asset( string $asset ) : void {
*
* @return void
*/
function enqueue_assets() : void {
function enqueue_assets(): void {
\array_map( __NAMESPACE__ . '\\enqueue_asset', get_assets() );
}

Expand All @@ -102,6 +103,6 @@ function enqueue_assets() : void {
*
* @return void
*/
function enqueue_asset( string $asset ) : void {
wp_enqueue_script( "label-printing--$asset" );
function enqueue_asset( string $asset ): void {
\wp_enqueue_script( "label-printing--$asset" );
}
13 changes: 6 additions & 7 deletions inc/blocks/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @return void
*/
function register() :void {
function register(): void {
\add_action( 'init', __NAMESPACE__ . '\\bootstrap' );
}

Expand All @@ -23,17 +23,16 @@ function register() :void {
*
* @return void
*/
function bootstrap() :void {
function bootstrap(): void {
register_blocks();

}

/**
* Get list of blocks.
*
* @return string[] Array of block slugs.
*/
function get_blocks() : array {
function get_blocks(): array {
return [
'label-printing',
'label-proxy',
Expand All @@ -45,7 +44,7 @@ function get_blocks() : array {
*
* @return void
*/
function register_blocks() : void {
function register_blocks(): void {
\array_map( __NAMESPACE__ . '\\register_block', get_blocks() );
}

Expand All @@ -56,7 +55,7 @@ function register_blocks() : void {
*
* @return void
*/
function register_block( string $block ) : void {
function register_block( string $block ): void {

require_once Label_Printing\DIRECTORY . '/build/' . $block . '/index.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant

Expand All @@ -83,6 +82,6 @@ function register_block( string $block ) : void {
*
* @return string Namespaced block name.
*/
function get_ns_name( string $block ) : string {
function get_ns_name( string $block ): string {
return \ucfirst( \str_replace( 'label-', '', $block ) );
}
2 changes: 1 addition & 1 deletion inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @return void
*/
function register() :void {
function register(): void {

\load_plugin_textdomain(
'label-printing',
Expand Down
2 changes: 1 addition & 1 deletion inc/patterns/class-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Generator {
/**
* Setup a new Pattern Generator with a pre-defined Label.
*
* @param Label $label Printing-Label
* @param Label $label The Printing-Label object with all measurements & dimensions.
*/
public function __construct( Label $label ) {
$this->label = $label;
Expand Down
Loading

0 comments on commit f13b775

Please sign in to comment.