/**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @uses WP_Fields_API_Control::json()
  */
 public function json()
 {
     $json = parent::json();
     $json['statuses'] = $this->statuses;
     $json['defaultValue'] = $this->setting->default;
     return $json;
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @see WP_Fields_API_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $this->json['label'] = html_entity_decode($this->label, ENT_QUOTES, get_bloginfo('charset'));
     $this->json['mime_type'] = $this->mime_type;
     $this->json['button_labels'] = $this->button_labels;
     $this->json['canUpload'] = current_user_can('upload_files');
     $value = $this->value();
     if (is_object($this->setting)) {
         if ($this->setting->default) {
             // Fake an attachment model - needs all fields used by template.
             // Note that the default value must be a URL, NOT an attachment ID.
             $type = in_array(substr($this->setting->default, -3), array('jpg', 'png', 'gif', 'bmp')) ? 'image' : 'document';
             $default_attachment = array('id' => 1, 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->setting->default));
             if ('image' === $type) {
                 $default_attachment['sizes'] = array('full' => array('url' => $this->setting->default));
             }
             $this->json['defaultAttachment'] = $default_attachment;
         }
         if ($value && $this->setting->default && $value === $this->setting->default) {
             // Set the default as the attachment.
             $this->json['attachment'] = $this->json['defaultAttachment'];
         } elseif ($value) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($value);
         }
     }
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @see WP_Fields_API_Control::to_json()
  */
 public function json()
 {
     $json = parent::json();
     $json['mime_type'] = $this->mime_type;
     $json['button_labels'] = $this->button_labels;
     $json['canUpload'] = current_user_can('upload_files');
     $value = $this->value();
     if (is_object($this->field)) {
         if ($this->field->default) {
             // Fake an attachment model - needs all fields used by template.
             // Note that the default value must be a URL, NOT an attachment ID.
             $type = 'document';
             if (in_array(substr($this->field->default, -3), array('jpg', 'png', 'gif', 'bmp'))) {
                 $type = 'image';
             }
             $default_attachment = array('id' => 1, 'url' => $this->field->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->field->default));
             if ('image' === $type) {
                 $default_attachment['sizes'] = array('full' => array('url' => $this->field->default));
             }
             $json['defaultAttachment'] = $default_attachment;
         }
         if ($value && $this->field->default && $value === $this->field->default) {
             // Set the default as the attachment.
             $json['attachment'] = $json['defaultAttachment'];
         } elseif ($value) {
             $json['attachment'] = wp_prepare_attachment_for_js($value);
         }
     }
     return $json;
 }
    /**
     * Render control wrapper, label, description, and control input
     *
     * @param WP_Fields_API_Control $control Control object
     */
    protected function render_control($control)
    {
        $input_id = 'field-' . $control->id;
        if (isset($control->input_attrs['id'])) {
            $input_id = $control->input_attrs['id'];
        }
        ?>
			<tr <?php 
        $control->wrap_attrs();
        ?>
>
				<th>
					<?php 
        if ($control->label && $control->display_label) {
            ?>
						<label for="<?php 
            echo esc_attr($input_id);
            ?>
">
							<?php 
            $control->render_label();
            ?>
						</label>
					<?php 
        }
        ?>
				</th>
				<td>
					<?php 
        $control->maybe_render();
        ?>

					<?php 
        if ($control->description) {
            ?>
						<p class="description">
							<?php 
            $control->render_description();
            ?>
						</p>
					<?php 
        }
        ?>
				</td>
			</tr>
		<?php 
    }
 /**
  * {@inheritdoc}
  */
 protected function render_content()
 {
     $current_user = get_userdata(get_current_user_id());
     $profileuser = get_userdata($this->get_item_id());
     parent::render_content();
     $new_email = get_option($current_user->ID . '_new_email');
     if ($new_email && $new_email['newemail'] != $current_user->user_email && $profileuser->ID == $current_user->ID) {
         echo '<div class="updated inline"><p>';
         printf(__('There is a pending change of your e-mail to %1$s. <a href="%2$s">Cancel</a>'), '<code>' . $new_email['newemail'] . '</code>', esc_url(self_admin_url('profile.php?dismiss=' . $current_user->ID . '_new_email')));
         echo '</p></div>';
     }
 }
 /**
  * Control only visible if password fields are shown.
  *
  * @param WP_Fields_API_Control $control
  *
  * @return bool
  */
 public function capability_show_password_fields($control)
 {
     $profileuser = get_userdata($control->get_item_id());
     /** This filter is documented in wp-admin/user-new.php */
     $show_password_fields = apply_filters('show_password_fields', true, $profileuser);
     $has_access = false;
     if ($show_password_fields) {
         $has_access = true;
     }
     return $has_access;
 }
 /**
  * {@inheritdoc}
  */
 public function render_content()
 {
     // @todo Setup $current_user correctly
     $current_user = new stdClass();
     // @todo Setup $profileuser correctly
     $profileuser = new stdClass();
     parent::render_content();
     $new_email = get_option($current_user->ID . '_new_email');
     if ($new_email && $new_email['newemail'] != $current_user->user_email && $profileuser->ID == $current_user->ID) {
         echo '<div class="updated inline"><p>';
         printf(__('There is a pending change of your e-mail to %1$s. <a href="%2$s">Cancel</a>'), '<code>' . $new_email['newemail'] . '</code>', esc_url(self_admin_url('profile.php?dismiss=' . $current_user->ID . '_new_email')));
         echo '</p></div>';
     }
 }
 /**
  * Get the data to export to the client via JSON.
  *
  * @since 4.1.0
  *
  * @return array Array of parameters passed to the JavaScript.
  */
 public function json()
 {
     $array = parent::json();
     $array['active'] = $this->active();
     // Backwards compatibility
     $array['panel'] = $array['screen'];
     $array['settings'] = $array['fields'];
     return $array;
 }
    /**
     * Render control wrapper, label, description, and control input
     *
     * @param WP_Fields_API_Control $control     Control object
     * @param null|int              $item_id     Item ID
     * @param null|string           $object_name Object name
     */
    public function render_control($control, $item_id = null, $object_name = null)
    {
        // Pass $object_name and $item_id to Control
        $control->object_name = $object_name;
        $control->item_id = $item_id;
        $label = trim($control->label);
        $description = trim($control->description);
        // Avoid outputting them in render_content()
        $control->label = '';
        $control->description = '';
        $input_id = 'field-' . $control->id;
        if (isset($control->input_attrs['id'])) {
            $input_id = $control->input_attrs['id'];
        }
        ?>
			<div <?php 
        $control->wrap_attrs();
        ?>
>
				<?php 
        if (0 < strlen($label)) {
            ?>
					<label for="<?php 
            echo esc_attr($input_id);
            ?>
"><?php 
            echo esc_html($label);
            ?>
</label>
				<?php 
        }
        ?>

				<?php 
        $control->render_content();
        ?>

				<?php 
        if (0 < strlen($description)) {
            ?>
					<p class="description"><?php 
            echo wp_kses_post($description);
            ?>
</p>
				<?php 
        }
        ?>
			</div>
		<?php 
    }
 /**
  * Get the data to export to the client via JSON.
  *
  * @return array Array of parameters passed to the JavaScript.
  *
  * @since 3.2.0
  */
 public function json()
 {
     $array = parent::json();
     $array['active'] = $this->active();
     // Backwards compatibility
     $array['panel'] = $array['screen'];
     unset($array['screen']);
 }