C:\xampp\htdocs\landing\wp-content\plugins\penci-smart-lists\lib\meta-box\inc\media-modal.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
123
124
125
<?php
/**
 * Add support for editing attachment custom fields in the media modal.
 *
 * @package Meta Box
 */

/**
 * The media modal class.
 * Handling showing and saving custom fields in the media modal.
 */
class RWMB_Media_Modal {
    
/**
     * List of custom fields.
     *
     * @var array
     */
    
protected $fields = array();

    
/**
     * Initialize.
     */
    
public function init() {
        
add_action'init', array( $this'get_fields' ) );
        
add_filter'attachment_fields_to_edit', array( $this'add_fields' ), 11);
        
add_filter'attachment_fields_to_save', array( $this'save_fields' ), 11);

        
add_filter'rwmb_show', array( $this'is_in_normal_mode' ), 10);
    }

    
/**
     * Get list of custom fields and store in the current object for future use.
     */
    
public function get_fields() {
        
$meta_boxes rwmb_get_registry'meta_box' )->all();
        foreach ( 
$meta_boxes as $meta_box ) {
            if ( 
$this->is_in_modal$meta_box->meta_box ) ) {
                
$this->fields array_merge$this->fieldsarray_values$meta_box->fields ) );
            }
        }
    }

    
/**
     * Add fields to the attachment edit popup.
     *
     * @param array   $form_fields An array of attachment form fields.
     * @param WP_Post $post The WP_Post attachment object.
     *
     * @return mixed
     */
    
public function add_fields$form_fieldsWP_Post $post ) {
        foreach ( 
$this->fields as $field ) {
            
$form_field          $field;
            
$form_field['label'] = $field['name'];
            
$form_field['input'] = 'html';

            
// Just ignore the field 'std' because there's no way to check it.
            
$meta                RWMB_Field::call$field'meta'$post->IDtrue );
            
$form_field['value'] = $meta;

            
$field['field_name'] = 'attachments[' $post->ID '][' $field['field_name'] . ']';
            
$form_field['html']  = RWMB_Field::call$field'html'$meta );

            
$form_fields$field['id'] ] = $form_field;
        }

        return 
$form_fields;
    }

    
/**
     * Save custom fields.
     *
     * @param array $post An array of post data.
     * @param array $attachment An array of attachment metadata.
     *
     * @return array
     */
    
public function save_fields$post$attachment ) {
        foreach ( 
$this->fields as $field ) {
            
$key $field['id'];

            
$old RWMB_Field::call$field'raw_meta'$post['ID'] );
            
$new = isset( $attachment$key ] ) ? $attachment$key ] : '';

            
// Allow field class change the value.
            
if ( $field['clone'] ) {
                
$new RWMB_Clone::value$new$old$post['ID'], $field );
            } else {
                
$new RWMB_Field::call$field'value'$new$old$post['ID'] );
                
$new RWMB_Field::filter'sanitize'$new$field );
            }
            
$new RWMB_Field::filter'value'$new$field$old );

            
// Call defined method to save meta value, if there's no methods, call common one.
            
RWMB_Field::call$field'save'$new$old$post['ID'] );
        }

        return 
$post;
    }

    
/**
     * Whether or not show the meta box when editing custom fields in the normal mode.
     *
     * @param bool  $show     Whether to show the meta box in normal editing mode.
     * @param array $meta_box Meta Box parameters.
     *
     * @return bool
     */
    
public function is_in_normal_mode$show$meta_box ) {
        
$show $show && ! $this->is_in_modal$meta_box );

        return 
$show;
    }

    
/**
     * Check if the meta box is for editing custom fields in the media modal.
     *
     * @param array $meta_box Meta Box parameters.
     *
     * @return bool
     */
    
protected function is_in_modal$meta_box ) {
        return 
in_array'attachment'$meta_box['post_types'], true ) && ! empty( $meta_box['media_modal'] );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586