PluginProbe
Enter Addons – Ultimate Template Builder for Elementor / 2.2.8
Enter Addons – Ultimate Template Builder for Elementor v2.2.8
trunk 2.2.10 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4
enteraddons / classes / Meta_Base.php

Meta_Base.php in Enter Addons – Ultimate Template Builder for Elementor 2.2.8, at classes/Meta_Base.php

70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Enteraddons\Classes;
3
4 /**
5 * Enteraddons Post Type Meta Base class
6 *
7 * @package Enteraddons
8 * @author ThemeLooks
9 * @copyright 2022 ThemeLooks
10 * @license GPL-2.0-or-later
11 *
12 *
13 */
14
15 abstract class Meta_Base {
16 use \Enteraddons\Core\Fields_Flag;
17
18 public function initHook() {
19 add_action( 'add_meta_boxes', [ $this, '_registerMeta' ] );
20
21 if( !empty( $this->getPostTypeName() ) ) {
22 foreach( $this->getPostTypeName() as $postType ) {
23 add_action( 'save_post_'.$postType, [ $this, 'save_meta_postdata' ] );
24 }
25
26 }
27
28 }
29
30 abstract public function getPostTypeName();
31
32 public function _registerMeta() {
33 $args = $this->metaBox;
34
35 add_meta_box(
36 $args['unique_id'], // Unique ID
37 $args['title'], // Box title
38 [$this, 'meta_callback'], // Content callback, must be of type callable
39 [ $this->getPostTypeName() ], // Post type
40 $args['context'], // context
41 $args['priority'] // priority
42 );
43 }
44
45 public function meta_callback() {
46 $this->meta_view();
47 }
48
49 public function save_meta_postdata( $post_id ) {
50
51 $fields = $this->metaFields;
52
53 if( !empty( $fields ) && is_array( $fields ) ) {
54
55 foreach( $fields as $val ) {
56 $key = sanitize_text_field( $val['name'] );
57 $getVal = '';
58 if( !empty( $_POST[$key] ) ) {
59 $getVal = wp_unslash( $_POST[$key] );
60 }
61
62 update_post_meta( absint( $post_id ), $key, $getVal );
63 }
64
65 }
66
67 }
68
69
70 }