Exemplo n.º 1
0
 /**
  * Add help tabs.
  */
 public function add_help_tabs()
 {
     $help = $this->help();
     $screen = get_current_screen();
     // No screen available.
     if ($screen instanceof WP_Screen === false) {
         return;
     }
     // Clean up all existing tabs.
     if (!$this->show_help_tabs || !empty($help)) {
         $screen->remove_help_tabs();
     }
     // No new help tabs available.
     if (empty($help)) {
         return;
     }
     // Add help sidebar content. By default it will be disabled
     // since `help_sidebar` method returns false.
     $help_sidebar = $this->help_sidebar();
     $help_sidebar = papi_maybe_get_callable_value($help_sidebar);
     $screen->set_help_sidebar(wpautop($help_sidebar));
     foreach ($help as $key => $value) {
         $args = ['id' => papi_html_name($key), 'title' => $key];
         if (is_callable($value)) {
             $args['callback'] = function () use($value) {
                 return wpautop($value());
             };
         } else {
             $args['content'] = wpautop($value);
         }
         $screen->add_help_tab($args);
     }
 }
Exemplo n.º 2
0
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $html = papi_maybe_get_callable_value($settings->html);
     if ($settings->save) {
         $value = $this->get_value();
         if (!empty($value) && is_string($value)) {
             $html = $value;
         }
         papi_render_html_tag('input', ['name' => esc_attr($this->html_name()), 'type' => 'hidden', 'value' => $html]);
     }
     papi_render_html_tag('div', ['data-papi-rule' => esc_attr($this->html_name()), 'class' => 'property-html', $html]);
 }
Exemplo n.º 3
0
 /**
  * Add attachment fields.
  *
  * @param  array   $form_fields
  * @param  WP_Post $post
  *
  * @return array
  */
 public function edit_attachment($form_fields, $post)
 {
     foreach ($this->get_boxes() as $box) {
         if (!empty($box->title)) {
             $form_fields['papi-media-title-' . uniqid()] = ['label' => '', 'input' => 'html', 'html' => '<h4 class="papi-media-title">' . $box->title . '</h4>'];
         }
         foreach ($box->properties as $prop) {
             // Raw output is required.
             $prop->raw = true;
             // Set post id to the property.
             $prop->set_post_id($post->ID);
             // Add property to form fields.
             $form_fields[$prop->get_slug()] = ['label' => $prop->title, 'input' => 'html', 'helps' => $prop->description, 'html' => papi_maybe_get_callable_value('papi_render_property', $prop)];
         }
     }
     // Add nonce field.
     $form_fields['papi_meta_nonce'] = ['label' => '', 'input' => 'html', 'html' => sprintf('<input name="papi_meta_nonce" type="hidden" value="%s" />', wp_create_nonce('papi_save_data'))];
     return $form_fields;
 }
Exemplo n.º 4
0
 /**
  * Render property html.
  */
 protected function render_property_html()
 {
     papi_render_html_tag('div', ['class' => 'papi-before-html ' . $this->get_option('before_class'), 'data-property' => $this->get_option('type'), papi_maybe_get_callable_value($this->get_option('before_html'))]);
     $this->html();
     papi_render_html_tag('div', ['class' => 'papi-after-html ' . $this->get_option('after_class'), 'data-property' => $this->get_option('type'), papi_maybe_get_callable_value($this->get_option('after_html'))]);
 }
Exemplo n.º 5
0
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     papi_render_html_tag('div', ['data-papi-rule' => $this->html_name(), 'class' => 'property-html', papi_maybe_get_callable_value($settings->html)]);
 }