@@ -30,11 +30,11 @@ abstract class Meta {
3030 const PLUGIN_ACF = 'advanced-custom-fields ' ;
3131
3232 /**
33- * Current page/term object. It can be WP_Post or WP_Term
33+ * Internal cache for post custom fields data
3434 *
35- * @var object
35+ * @var array
3636 */
37- public $ object ;
37+ protected $ _fields = [] ;
3838
3939 /**
4040 * Meta constructor.
@@ -45,8 +45,6 @@ public function __construct() {
4545 } else {
4646 $ this ->custom_fields_plugin = self ::PLUGIN_JCF ;
4747 }
48-
49- return $ this ->custom_fields_plugin ;
5048 }
5149
5250 /**
@@ -55,11 +53,10 @@ public function __construct() {
5553 * Do not call this method directly as it is a PHP magic method that
5654 * will be implicitly called when executing `$value = $object->property;`.
5755 *
58- * @param string $name The property name.
56+ * @param $name the property name.
5957 *
60- * @return mixed the property value
61- * @throws \Exception Property is not defined.
62- * @see __set()
58+ * @return mixed
59+ * @throws \Exception
6360 */
6461 public function __get ( $ name ) {
6562
@@ -83,51 +80,37 @@ public function __isset( $name ) {
8380 return null !== $ this ->get_field ($ name );
8481 }
8582
86- /**
87- * Sets an object property to null.
88- *
89- * Do not call this method directly as it is a PHP magic method that
90- * will be implicitly called when executing `unset($object->property)`.
91- *
92- * Note that if the property is not defined, this method will do nothing.
93- * If the property is read-only, it will throw an exception.
94- *
95- * @param string $name The property name.
96- *
97- * @throws \Exception The property is read only.
98- */
99- public function __unset ( $ name ) {
100- $ setter = 'set_ ' . $ name ;
101- if ( method_exists ( $ this , $ setter ) ) {
102- $ this ->$ setter ( null );
103- } elseif ( method_exists ( $ this , 'get_ ' . $ name ) ) {
104- throw new \Exception ( 'Setting read-only property: ' . get_class ( $ this ) . ':: ' . $ name );
105- }
106- }
107-
10883 /**
10984 * Getter of postmeta from just custom fields
11085 *
11186 * @param string $field_name Field name to get.
112- * @param int $post_id Post ID if different from get_the_ID.
87+ * @param int $object_id Post/Term ID
11388 * @param bool|string $format_value Format value or not.
11489 *
11590 * @return mixed
11691 * @throws \Exception Unsupported custom fields plugin.
11792 */
118- abstract public function get_field_jcf ( $ field_name , $ post_id , $ format_value );
93+ abstract public function get_field_jcf ( $ field_name , $ object_id , $ format_value );
11994
12095 /**
12196 * Getter of postmeta from advanced custom fields
12297 *
12398 * @param string $field_name Field name to get.
124- * @param int $post_id Post ID if different from get_the_ID.
99+ * @param int $object_id Post/Term ID
125100 * @param bool|string $format_value Format value or not.
126101 *
127102 * @return mixed
128103 * @throws \Exception Unsupported custom fields plugin.
129104 */
130- abstract public function get_field_acf ( $ field_name , $ post_id , $ format_value );
105+ abstract public function get_field_acf ( $ field_name , $ object_id , $ format_value );
106+
107+ /**
108+ * Get id of entity
109+ * It can be post or term
110+ *
111+ * @return mixed
112+ */
113+ abstract public function get_id ();
131114
132115 /**
133116 * Main post meta fields getter function.
@@ -141,10 +124,8 @@ abstract public function get_field_acf( $field_name, $post_id, $format_value );
141124 */
142125 public function get_field ( $ field_name , $ post_id = null , $ format_value = true ) {
143126
144- if ( is_a ( $ this ->object , 'WP_Post ' ) ) {
145- $ post_id = $ this ->object ->ID ;
146- } else {
147- $ post_id = $ this ->object ->term_id ;
127+ if ( empty ( $ post_id ) ) {
128+ $ post_id = $ this ->get_id ();
148129 }
149130
150131 // Check cache, if not exists - get field value.
0 commit comments