From 368b8d81a0b892ec1f07dd4f304d9f8beb8db15b Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Wed, 17 Jan 2024 17:59:00 -0300 Subject: [PATCH] fix: allow dynamic properties --- .../entities/class-tainacan-entity.php | 7 ++ src/classes/entities/class-tainacan-term.php | 5 +- .../class-tainacan-exposers-handler.php | 3 +- .../class-tainacan-bulk-edit-process.php | 26 +++++-- ...ss-tainacan-entity-collection-relation.php | 1 + src/views/class-tainacan-admin.php | 68 +++++++++---------- 6 files changed, 68 insertions(+), 42 deletions(-) diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php index 1672b01ab..d9937f604 100644 --- a/src/classes/entities/class-tainacan-entity.php +++ b/src/classes/entities/class-tainacan-entity.php @@ -8,6 +8,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); * Entity Super class * */ +#[\AllowDynamicProperties] class Entity { /** * The repository of that entity @@ -202,6 +203,9 @@ class Entity { return $this->$method($value); } } + // public function __set(string $name, mixed $value): void { + // $this->{$name} = $value; + // } /** * get the value property @@ -216,6 +220,9 @@ class Entity { return $this->$method(); } } + // public function __get(string $name) { + // return $this->{$name}; + // } /** * set the status of the entity diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 37894453d..4b2fd31e8 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -8,6 +8,8 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); * Represents the Entity Term */ class Term extends Entity { + public $WP_Term; + protected $term_id, $name, @@ -15,8 +17,7 @@ class Term extends Entity { $description, $user, $header_image_id, - $taxonomy, - $WP_Term; + $taxonomy; static $post_type = false; diff --git a/src/classes/exposers/class-tainacan-exposers-handler.php b/src/classes/exposers/class-tainacan-exposers-handler.php index 6e3cc1c68..4bde3186f 100644 --- a/src/classes/exposers/class-tainacan-exposers-handler.php +++ b/src/classes/exposers/class-tainacan-exposers-handler.php @@ -173,7 +173,8 @@ class Exposers_Handler { * @return Exposers\Exposer|boolean false */ public static function request_has_exposer($request) { - $body = json_decode( $request->get_body(), true ); + $data_body = $request->get_body() ?? ''; + $body = json_decode( $data_body, true ); $query_url_params = $request->get_query_params(); $Tainacan_Exposers = self::get_instance(); if( diff --git a/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php b/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php index 7e221c5be..da570025f 100644 --- a/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php +++ b/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php @@ -8,6 +8,11 @@ class Bulk_Edit_Process extends Generic_Process { private $meta_key = '_tnc_bulk'; private $group_id = false; + private $items_repository; + private $metadatum_repository; + private $item_metadata_repository; + private $bulk_edit_data; + public function __construct($attributes = array()) { $this->array_attributes = array_merge($this->array_attributes, [ 'group_id', @@ -93,9 +98,9 @@ class Bulk_Edit_Process extends Generic_Process { $metadata_label = __('Changed metadata', 'tainacan'); $message = __('Bulk edit finished', 'tainacan'); - $message .= "

${title_label}: ${name}

"; - $message .= "

${author_label}: ${author_name}

"; - $message .= "

${metadata_label}: ${metadata}

"; + $message .= "

$title_label: $name

"; + $message .= "

$author_label: $author_name

"; + $message .= "

$metadata_label: $metadata

"; return $message; } @@ -516,7 +521,13 @@ class Bulk_Edit_Process extends Generic_Process { $this->add_error_log( sprintf( __( 'Please verify, invalid value(s) to edit item ID: "%d"', 'tainacan' ), $item->get_id() ) ); $serealize_erro = (object) array('err' => array()); - array_walk_recursive($item->get_errors(), create_function('&$v, $k, &$t', '$t->err[] = $v;'), $serealize_erro); + array_walk_recursive( + $item->get_errors(), + function (&$v, $k, &$t) { + $t->err[] = $v; + }, + $serealize_erro + ); $this->add_error_log( __('errors: ', 'tainacan') . implode(", ", $serealize_erro->err) ); return false; @@ -538,7 +549,12 @@ class Bulk_Edit_Process extends Generic_Process { $this->add_error_log( sprintf( __( 'Please verify, invalid value(s) to edit item ID: "%d"', 'tainacan' ), $item->get_id() ) ); $serealize_erro = (object) array('err' => array()); - array_walk_recursive($item->get_errors(), create_function('&$v, $k, &$t', '$t->err[] = $v;'), $serealize_erro); + array_walk_recursive( + $item->get_errors(), + function (&$v, $k, &$t) { + $t->err[] = $v; + }, + $serealize_erro); $this->add_error_log( __('errors: ', 'tainacan') . implode(", ", $serealize_erro->err) ); return false; diff --git a/src/classes/traits/class-tainacan-entity-collection-relation.php b/src/classes/traits/class-tainacan-entity-collection-relation.php index a36628de6..e7c19283a 100644 --- a/src/classes/traits/class-tainacan-entity-collection-relation.php +++ b/src/classes/traits/class-tainacan-entity-collection-relation.php @@ -14,6 +14,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); */ trait Entity_Collection_Relation { + protected $collection; /** * * @return int collection item ID diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php index 7cec74c0e..6c0870c3c 100644 --- a/src/views/class-tainacan-admin.php +++ b/src/views/class-tainacan-admin.php @@ -77,7 +77,7 @@ class Admin { ); $mobile_app_page_suffix = add_submenu_page( - null, // Mobile app page is not listed in the menu + 'tainacan-no-show-menu', // Mobile app page is not listed in the menu __('Mobile App', 'tainacan'), __('Mobile App', 'tainacan'), 'manage_tainacan', @@ -204,39 +204,39 @@ class Admin { wp_enqueue_style( 'roboto-fonts', 'https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700,700i', [] ); wp_enqueue_style( 'tainacan-admin-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-admin.css', [], TAINACAN_VERSION ); -// $undesired_wp_styles = [ -// 'admin-menu', -// 'admin-bar', -// 'code-editor', -// 'color-picker', -// 'customize-controls', -// 'customize-nav-menus', -// 'customize-widgets', -// 'dashboard', -// 'dashicons', -// 'deprecated-media', -// 'edit', -// 'wp-pointer', -// 'farbtastic', -// 'forms', -// 'common', -// 'install', -// 'wp-auth-check', -// 'site-icon', -// 'buttons', -// 'l10n', -// 'list-tables', -// 'login', -// 'media', -// 'nav-menus', -// 'revisions', -// 'themes', -// 'widgets', -// 'wp-admin' -// ]; -// -// wp_dequeue_style( $undesired_wp_styles ); -// wp_deregister_style( $undesired_wp_styles ); + // $undesired_wp_styles = [ + // 'admin-menu', + // 'admin-bar', + // 'code-editor', + // 'color-picker', + // 'customize-controls', + // 'customize-nav-menus', + // 'customize-widgets', + // 'dashboard', + // 'dashicons', + // 'deprecated-media', + // 'edit', + // 'wp-pointer', + // 'farbtastic', + // 'forms', + // 'common', + // 'install', + // 'wp-auth-check', + // 'site-icon', + // 'buttons', + // 'l10n', + // 'list-tables', + // 'login', + // 'media', + // 'nav-menus', + // 'revisions', + // 'themes', + // 'widgets', + // 'wp-admin' + // ]; + + // wp_dequeue_style( $undesired_wp_styles ); + // wp_deregister_style( $undesired_wp_styles ); }