Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
933 changes: 557 additions & 376 deletions composer.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions js/metabox-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(function () {
var checkbox = document.getElementById('_pdc-lege-use-percentage');

if (!checkbox) {
return;
}

var priceFields = [
document.getElementById('_pdc-lege-price').closest('.cmb-row'),
document.getElementById('_pdc-lege-new-price').closest('.cmb-row'),
];

var percentageFields = [
document.getElementById('_pdc-lege-percentage').closest('.cmb-row'),
document.getElementById('_pdc-lege-new-percentage').closest('.cmb-row'),
];

function toggle() {
var usePercentage = checkbox.checked;

priceFields.forEach(function (row) {
row.style.display = usePercentage ? 'none' : '';
});

percentageFields.forEach(function (row) {
row.style.display = usePercentage ? '' : 'none';
});
}

checkbox.addEventListener('change', toggle);
toggle();
})();
Binary file modified languages/pdc-leges-nl_NL.mo
Binary file not shown.
51 changes: 40 additions & 11 deletions languages/pdc-leges-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,25 @@ msgstr "Breid de geregistreerde metaboxen uit met de volgende functies: een drem
msgid "The following plugins are required to use the PDC Leges:"
msgstr "De PDC Leges plugin heeft de volgende plugins nodig om te functioneren:"

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:186
#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:154
msgid "New price"
msgstr "Nieuw bedrag"

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:190
#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:158
msgid "Price"
msgstr "Bedrag"

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:194
#: src/Leges/Metabox/Metabox.php:64
#: src/Leges/PostType/LegesPostTypeServiceProvider.php:68
#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:162
msgid "Percentage"
msgstr "Percentage"

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:167
msgid "New percentage"
msgstr "Nieuw percentage"

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:172
#: src/Leges/Metabox/Metabox.php:78
#: src/Leges/PostType/LegesPostTypeServiceProvider.php:89
msgid "Date new lege active"
msgstr "Datum actief nieuwe lege"

Expand All @@ -82,7 +90,24 @@ msgstr "Prijs in €"
msgid "Lege new price"
msgstr "Lege nieuw bedrag"

#: src/Leges/Metabox/Metabox.php:69
#: src/Leges/Metabox/Metabox.php:56
msgid "Lege percentage"
msgstr "Lege percentage"

#: src/Leges/Metabox/Metabox.php:57
#: src/Leges/Metabox/Metabox.php:65
msgid "Percentage (%)"
msgstr "Percentage (%)"

#: src/Leges/Metabox/Metabox.php:64
msgid "Lege new percentage"
msgstr "Nieuw percentage"

#: src/Leges/Metabox/Metabox.php:72
msgid "Use percentage instead of price"
msgstr "Gebruik percentage in plaats van prijs"

#: src/Leges/Metabox/Metabox.php:83
msgid "dd-mm-yy"
msgstr "dd-mm-yy"

Expand Down Expand Up @@ -183,10 +208,6 @@ msgstr "Geen leges gevonden."
msgid "No leges found in Trash."
msgstr "Geen leges gevonden in de prullenbak."

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:45
msgid "PDC leges"
msgstr "PDC leges"

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:60
msgid "Lege price (in €)"
msgstr "Lege prijs (in €)"
Expand All @@ -195,7 +216,15 @@ msgstr "Lege prijs (in €)"
msgid "Lege new price (in €)"
msgstr "Nieuwe lege prijs (in €)"

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:73
#: src/Leges/PostType/LegesPostTypeServiceProvider.php:75
msgid "Lege percentage (%)"
msgstr "Lege percentage (%)"

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:82
msgid "Lege new percentage (%)"
msgstr "Nieuw lege percentage (%)"

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:94
msgid "Lege shortcode"
msgstr "Lege shortcode"

Expand Down
47 changes: 40 additions & 7 deletions languages/pdc-leges.pot
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,25 @@ msgstr ""
msgid "The following plugins are required to use the PDC Leges:"
msgstr ""

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:186
#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:154
msgid "New price"
msgstr ""

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:190
#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:158
msgid "Price"
msgstr ""

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:194
#: src/Leges/Metabox/Metabox.php:64
#: src/Leges/PostType/LegesPostTypeServiceProvider.php:68
#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:162
msgid "Percentage"
msgstr ""

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:167
msgid "New percentage"
msgstr ""

#: src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php:172
#: src/Leges/Metabox/Metabox.php:78
#: src/Leges/PostType/LegesPostTypeServiceProvider.php:89
msgid "Date new lege active"
msgstr ""

Expand All @@ -82,7 +90,24 @@ msgstr ""
msgid "Lege new price"
msgstr ""

#: src/Leges/Metabox/Metabox.php:69
#: src/Leges/Metabox/Metabox.php:56
msgid "Lege percentage"
msgstr ""

#: src/Leges/Metabox/Metabox.php:57
#: src/Leges/Metabox/Metabox.php:65
msgid "Percentage (%)"
msgstr ""

#: src/Leges/Metabox/Metabox.php:64
msgid "Lege new percentage"
msgstr ""

#: src/Leges/Metabox/Metabox.php:72
msgid "Use percentage instead of price"
msgstr ""

#: src/Leges/Metabox/Metabox.php:83
msgid "dd-mm-yy"
msgstr ""

Expand Down Expand Up @@ -195,7 +220,15 @@ msgstr ""
msgid "Lege new price (in €)"
msgstr ""

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:73
#: src/Leges/PostType/LegesPostTypeServiceProvider.php:75
msgid "Lege percentage (%)"
msgstr ""

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:82
msgid "Lege new percentage (%)"
msgstr ""

#: src/Leges/PostType/LegesPostTypeServiceProvider.php:94
msgid "Lege shortcode"
msgstr ""

Expand Down
65 changes: 25 additions & 40 deletions src/Leges/Admin/QuickEdit/QuickEditServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace OWC\PDC\Leges\Admin\QuickEdit;

use OWC\PDC\Base\Foundation\ServiceProvider;
use OWC\PDC\Leges\Traits\NumberSanitizer;
use WP_Post;

class QuickEditServiceProvider extends ServiceProvider
{
use NumberSanitizer;
/**
* Prefix for the quickedit.
*/
Expand Down Expand Up @@ -120,51 +122,17 @@ public function registerQuickEditHandler(string $columnName, string $postType):
continue;
}

$method = explode('-', $key);
$method = array_map('ucfirst', $method);
$method = implode('', $method);

if (method_exists($this, $method)) {
$this->$method($handler);
}
$this->renderField($handler);
}

echo '</div>
</fieldset>';
}

/**
* Adds active date to quickedit handler.
* Renders a quickedit input field for the given handler.
*/
protected function activeDate(array $item): void
{
$value = get_post_meta(get_the_ID(), $item['metaboxKey'], true); ?>

<label class="aligncenter" for="<?php echo $item['metaboxKey']; ?>">
<span class="title"><?php echo __($item['label'], 'pdc-leges'); ?></span>
<span class="input-text-wrap"><input type="text" id="<?php echo $item['metaboxKey']; ?>" name="<?php echo $item['metaboxKey']; ?>" value="<?php echo $value; ?>"></span>
</label>
<?php
}

/**
* Adds price to quickedit handlers.
*/
protected function price(array $item): void
{
$value = get_post_meta(get_the_ID(), $item['metaboxKey'], true); ?>

<label class="aligncenter" for="<?php echo $item['metaboxKey']; ?>">
<span class="title"><?php echo __($item['label'], 'pdc-leges'); ?></span>
<span class="input-text-wrap"><input type="text" id="<?php echo $item['metaboxKey']; ?>" name="<?php echo $item['metaboxKey']; ?>" value="<?php echo $value; ?>"></span>
</label>
<?php
}

/**
* Adds newPrice to quickedit handlers.
*/
protected function newPrice(array $item): void
protected function renderField(array $item): void
{
$value = get_post_meta(get_the_ID(), $item['metaboxKey'], true); ?>

Expand All @@ -189,6 +157,16 @@ public function setQuickEditHandlers(): array
'metaboxKey' => sprintf('%s-%s', $this->prefix, 'price'),
'label' => __('Price', 'pdc-leges'),
],
'percentage' => [
'metaboxKey' => sprintf('%s-%s', $this->prefix, 'percentage'),
'label' => __('Percentage', 'pdc-leges'),
'sanitize_cb' => [$this, 'sanitizeFloatFourDecimals'],
],
'new-percentage' => [
'metaboxKey' => sprintf('%s-%s', $this->prefix, 'new-percentage'),
'label' => __('New percentage', 'pdc-leges'),
'sanitize_cb' => [$this, 'sanitizeFloatFourDecimals'],
],
'active-date' => [
'metaboxKey' => sprintf('%s-%s', $this->prefix, 'active-date'),
'label' => __('Date new lege active', 'pdc-leges'),
Expand Down Expand Up @@ -220,10 +198,17 @@ public function registerSavePostHandler(int $postID, WP_Post $post): void
}

foreach ($this->getQuickEditHandlers() as $key => $handler) {
// update!
if (isset($_POST["{$this->prefix}-{$key}"])) {
update_post_meta($postID, "{$this->prefix}-{$key}", $_POST["{$this->prefix}-{$key}"]);
if (! isset($_POST["{$this->prefix}-{$key}"])) {
continue;
}

$value = wp_unslash($_POST["{$this->prefix}-{$key}"]);

if (isset($handler['sanitize_cb']) && is_callable($handler['sanitize_cb'])) {
$value = call_user_func($handler['sanitize_cb'], $value);
}

update_post_meta($postID, "{$this->prefix}-{$key}", $value);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Leges/Foundation/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Plugin extends BasePlugin
*/
const VERSION = '2.2.10';

public function loadTextDomain(): void
{
load_plugin_textdomain($this->getName(), false, basename($this->rootPath) . '/languages/');
}

protected function checkForUpdate()
{
if (! class_exists(PucFactory::class) || $this->isExtendedClass()) {
Expand Down
22 changes: 22 additions & 0 deletions src/Leges/Metabox/Metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ protected function addDefaultFields(CMB2 $cmb): void
'sanitization_cb' => [$this, 'sanitizeFloat'],
]);

$cmb->add_field([
'name' => __('Lege percentage', 'pdc-leges'),
'desc' => __('Percentage (%)', 'pdc-leges'),
'id' => sprintf('%s-percentage', self::PREFIX),
'type' => 'text',
'sanitization_cb' => [$this, 'sanitizeFloatFourDecimals'],
]);

$cmb->add_field([
'name' => __('Lege new percentage', 'pdc-leges'),
'desc' => __('Percentage (%)', 'pdc-leges'),
'id' => sprintf('%s-new-percentage', self::PREFIX),
'type' => 'text',
'sanitization_cb' => [$this, 'sanitizeFloatFourDecimals'],
]);

$cmb->add_field([
'name' => __('Use percentage instead of price', 'pdc-leges'),
'id' => sprintf('%s-use-percentage', self::PREFIX),
'type' => 'checkbox',
]);

$cmb->add_field([
'name' => esc_html__('Date new lege active', 'pdc-leges'),
'id' => sprintf('%s-active-date', self::PREFIX),
Expand Down
19 changes: 19 additions & 0 deletions src/Leges/Metabox/MetaboxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@
namespace OWC\PDC\Leges\Metabox;

use OWC\PDC\Base\Foundation\ServiceProvider;
use OWC\PDC\Leges\Foundation\Plugin;

class MetaboxServiceProvider extends ServiceProvider
{
public function register(): void
{
add_filter('cmb2_admin_init', [new Metabox(), 'registerMetaboxes'], 10, 0);
add_action('admin_enqueue_scripts', [$this, 'enqueueScripts']);
}

public function enqueueScripts(): void
{
$screen = get_current_screen();

if (! $screen || 'pdc-leges' !== $screen->post_type || 'post' !== $screen->base) {
return;
}

wp_enqueue_script(
'pdc-leges-metabox-toggle',
plugins_url('/js/metabox-toggle.js', $this->plugin->getRootPath() . '/pdc-leges.php'),
[],
Plugin::VERSION,
true
);
}
}
14 changes: 14 additions & 0 deletions src/Leges/PostType/LegesPostTypeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public function registerPostType(): PostType
echo $price ? number_format_i18n((float) $price, 2) : '';
},
],
'percentage' => [
'title' => __('Lege percentage (%)', 'pdc-leges'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik weet even niet meer wat het doel is van de percentages, wellicht een kleine omschrijving erbij plaatsen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik heb de werking wat aangepast en een video toegevoegd aan deze PR, hopelijk is het daarmee wat duidelijker.

'function' => function () {
$percentage = get_post_meta(get_the_ID(), "{$this->prefix}-percentage", true);
echo ('' !== $percentage && null !== $percentage) ? esc_html(str_replace('.', ',', $percentage)) . '%' : '';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik zou hier alleen maar checken op datgeen wat je wilt, bijvoorbeeld:
is_string($percentage) && '' !== trim(percentage)

Stel dat er een keer een array voorbij komt dan heb je een fatal error.
Is wel een persoonlijke voorkeur, andere laten het liever crashen zodat de fout goed opvalt.

},
],
'new-percentage' => [
'title' => __('Lege new percentage (%)', 'pdc-leges'),
'function' => function () {
$percentage = get_post_meta(get_the_ID(), "{$this->prefix}-new-percentage", true);
echo ('' !== $percentage && null !== $percentage) ? esc_html(str_replace('.', ',', $percentage)) . '%' : '';
},
],
'active-date' => [
'title' => __('Date new lege active', 'pdc-leges'),
'meta_key' => "{$this->prefix}-active-date",
Expand Down
2 changes: 2 additions & 0 deletions src/Leges/RestAPI/Controllers/LegesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ protected function checkAllowedMetaKeys(string $metaKey): bool
$allowed = apply_filters('owc/pdc/leges/rest-api/args/allowed-meta-keys', [
'_pdc-lege-price',
'_pdc-lege-new-price',
'_pdc-lege-percentage',
'_pdc-lege-new-percentage',
'_pdc-lege-active-date',
'_pdc-lege-start-time',
'_pdc-lege-end-time',
Expand Down
Loading