/
class.llms.meta.box.achievement.php
122 lines (104 loc) · 2.92 KB
/
class.llms.meta.box.achievement.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* LLMS_Meta_Box_Achievement class file.
*
* @package LifterLMS/Admin/PostTypes/MetaBoxes/Classes
*
* @since 1.0.0
* @version 6.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Achievements meta box class.
*
* Generates the main metabox for the `llms_achievement` and `llms_my_achievement` post types.
*
* @since 1.0.0
*/
class LLMS_Meta_Box_Achievement extends LLMS_Admin_Metabox {
/**
* Configure the metabox settings.
*
* @since 3.0.0
* @since 6.0.0 Added support for the `llms_my_achievement` post type.
*
* @return void
*/
public function configure() {
$this->id = 'lifterlms-achievement';
$this->title = __( 'Achievement Settings', 'lifterlms' );
$this->screens = array(
'llms_achievement',
'llms_my_achievement',
);
$this->priority = 'high';
}
/**
* Builds array of metabox options.
*
* Array is called in output method to display options.
* Appropriate fields are generated based on type.
*
* @since 3.0.0
* @since 3.37.12 Allow some fields to store values with quotes.
* @since 6.0.0 Removed the deprecated achievement background image meta field.
* Made the title field conditional based on viewed post type.
*
* @return array
*/
public function get_fields() {
$fields = array();
if ( 'llms_achievement' === $this->post->post_type ) {
$fields[] = array(
'label' => __( 'Achievement Title', 'lifterlms' ),
'desc' => __( 'The name of the achievement which will be shown to users', 'lifterlms' ),
'id' => $this->prefix . 'achievement_title',
'type' => 'text',
'class' => 'input-full',
'sanitize' => 'no_encode_quotes',
);
}
$fields[] = array(
'label' => __( 'Achievement Content', 'lifterlms' ),
'desc' => __( 'An optional short description of the achievement which will be shown to users', 'lifterlms' ),
'id' => $this->prefix . 'achievement_content',
'type' => 'textarea_w_tags',
'sanitize' => 'no_encode_quotes',
'cols' => 80,
'rows' => 8,
'meta' => $this->post->post_content,
);
return array(
array(
'title' => __( 'General', 'lifterlms' ),
'fields' => $fields,
),
);
}
/**
* Save field in the db.
*
* Expects an already sanitized value.
*
* Stores the `achievement_content` field as `post_content` in favor of storing it in the postmeta table.
*
* @since 6.0.0
*
* @param int $post_id The WP Post ID.
* @param int $field_id The field identifier.
* @param mixed $val Value to save.
* @return bool
*/
protected function save_field_db( $post_id, $field_id, $val ) {
// Save to the post content field.
if ( $this->prefix . 'achievement_content' === $field_id && $this->post->ID === $post_id ) {
return wp_update_post(
array(
'ID' => $post_id,
'post_content' => $val,
)
) ? true : false;
}
return parent::save_field_db( $post_id, $field_id, $val );
}
}