• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP papi_is_empty函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中papi_is_empty函数的典型用法代码示例。如果您正苦于以下问题:PHP papi_is_empty函数的具体用法?PHP papi_is_empty怎么用?PHP papi_is_empty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了papi_is_empty函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: convert

 /**
  * Convert property value with the property type converter.
  *
  * @param  string $slug
  * @param  mixed  $value
  *
  * @return mixed
  */
 protected function convert($slug, $value)
 {
     $property = $this->get_property($slug);
     // If no property type is found, just return null.
     if (!papi_is_property($property)) {
         return;
     }
     if (papi_is_empty($value)) {
         if (!papi_is_empty($property->get_option('value'))) {
             return $property->get_option('value');
         }
         return;
     }
     // A property need to know about the page.
     $property->set_page($this);
     // Run load value method right after the value has been loaded from the database.
     $value = $property->load_value($value, $slug, $this->id);
     $value = papi_filter_load_value($property->type, $value, $slug, $this->id);
     // Format the value from the property class.
     $value = $property->format_value($value, $slug, $this->id);
     // Only fired when not in admin.
     if (!is_admin()) {
         $value = papi_filter_format_value($property->type, $value, $slug, $this->id);
     }
     if (is_array($value)) {
         $value = array_filter($value);
     }
     return $value;
 }
开发者ID:ekandreas,项目名称:papi,代码行数:37,代码来源:class-papi-core-page.php


示例2: handle_papi_ajax

 /**
  * Handle Papi ajax.
  */
 public function handle_papi_ajax()
 {
     global $wp_query;
     if (!is_object($wp_query)) {
         return;
     }
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     if (!papi_is_empty(papi_get_qs('action'))) {
         $wp_query->set('papi_ajax_action', papi_get_qs('action'));
     }
     $ajax_action = $wp_query->get('papi_ajax_action');
     if (is_user_logged_in() && has_action($this->action_prefix . $ajax_action) !== false) {
         if (!defined('DOING_AJAX')) {
             define('DOING_AJAX', true);
         }
         if (!defined('DOING_PAPI_AJAX')) {
             define('DOING_PAPI_AJAX', true);
         }
         status_header(200);
         do_action($this->action_prefix . $ajax_action);
         wp_die();
     }
 }
开发者ID:ekandreas,项目名称:papi,代码行数:28,代码来源:class-papi-admin-ajax.php


示例3: html

 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = papi_cast_string_value($this->get_value());
     $options_html = [];
     // Override selected setting with
     // database value if not empty.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     $classes = 'papi-fullwidth';
     if ($settings->select2) {
         $classes .= ' papi-component-select2';
     }
     if (!empty($settings->placeholder)) {
         $options_html[] = papi_html_tag('option', ['value' => '', $settings->placeholder]);
     }
     // Create option html tags for all items.
     foreach ($this->get_items() as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         if (papi_is_empty($key)) {
             continue;
         }
         $options_html[] = papi_html_tag('option', ['selected' => $value === $settings->selected ? 'selected' : null, 'value' => $value, papi_convert_to_string($key)]);
     }
     papi_render_html_tag('select', ['class' => $classes, 'data-allow-clear' => true, 'data-placeholder' => $settings->placeholder, 'data-width' => '100%', 'id' => $this->html_id(), 'name' => $this->html_name(), $options_html]);
 }
开发者ID:ekandreas,项目名称:papi,代码行数:30,代码来源:class-papi-property-dropdown.php


示例4: html

 /**
  * Render property html.
  */
 public function html()
 {
     $options = $this->get_options();
     papi_render_html_tag('div', ['class' => 'papi-property-divider', 'data-papi-rule' => $this->html_name(), sprintf('<h3><span>%s</span></h3>', $options->title)]);
     if (!papi_is_empty($options->description)) {
         echo sprintf('<p>%s</p>', $options->description);
     }
 }
开发者ID:ekandreas,项目名称:papi,代码行数:11,代码来源:class-papi-property-divider.php


示例5: html

 /**
  * Render property html.
  */
 public function html()
 {
     $options = $this->get_options();
     $text = '';
     $options->description = $options->slug;
     if (!papi_is_empty($options->description)) {
         $text = sprintf('<p>%s</p>', $options->description);
     }
     papi_render_html_tag('div', ['class' => 'papi-property-divider', 'data-papi-rule' => esc_attr($this->html_name()), sprintf('<h3><span>%s</span></h3>%s', esc_html($options->title), $text)]);
 }
开发者ID:wp-papi,项目名称:papi,代码行数:13,代码来源:class-papi-property-divider.php


示例6: import_value

 /**
  * Import value to the property.
  *
  * @param  mixed  $value
  * @param  string $slug
  * @param  int    $post_id
  *
  * @return mixed
  */
 public function import_value($value, $slug, $post_id)
 {
     if (is_string($value) && !papi_is_empty($value)) {
         return [$value];
     }
     if (!is_array($value)) {
         return;
     }
     return $value;
 }
开发者ID:wp-papi,项目名称:papi,代码行数:19,代码来源:class-papi-property-checkbox.php


示例7: html

 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = papi_cast_string_value($this->get_value());
     // Override selected setting with
     // database value if not null.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     foreach ($settings->items as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         papi_render_html_tag('label', ['class' => 'light', 'for' => $this->html_id($key), papi_render_html_tag('input', ['id' => $this->html_id($key), 'name' => $this->html_name(), 'type' => 'radio', 'checked' => $value === $settings->selected ? 'checked' : null, 'value' => $value]), papi_convert_to_string($key)]);
         papi_render_html_tag('br');
     }
 }
开发者ID:ekandreas,项目名称:papi,代码行数:18,代码来源:class-papi-property-radio.php


示例8: html

 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = $this->get_value();
     // If range type is used change the default values if empty.
     if ($settings->type === 'range') {
         $settings->max = papi_is_empty($settings->max) ? 100 : $settings->max;
         $settings->min = papi_is_empty($settings->min) ? 0 : $settings->min;
         $settings->step = papi_is_empty($settings->step) ? 1 : $settings->step;
     }
     if ($settings->min !== 0 && $value < $settings->min) {
         $value = $settings->min;
     }
     papi_render_html_tag('input', ['id' => $this->html_id(), 'max' => $settings->max, 'min' => $settings->min, 'name' => $this->html_name(), 'step' => $settings->step, 'type' => $settings->type, 'value' => $value]);
 }
开发者ID:ekandreas,项目名称:papi,代码行数:18,代码来源:class-papi-property-number.php


示例9: html

 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = papi_cast_string_value($this->get_value());
     // Override selected setting with
     // database value if not null.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     echo '<div class="papi-property-radio">';
     foreach ($settings->items as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         papi_render_html_tag('p', [papi_html_tag('label', ['class' => 'light', 'for' => esc_attr($this->html_id($key)), papi_html_tag('input', ['id' => esc_attr($this->html_id($key)), 'name' => esc_attr($this->html_name()), 'type' => 'radio', 'checked' => $value === $settings->selected, 'value' => $value]), esc_html(papi_convert_to_string($key))])]);
     }
     echo '</div>';
 }
开发者ID:wp-papi,项目名称:papi,代码行数:19,代码来源:class-papi-property-radio.php


示例10: format_value

 /**
  * Format the value of the property before it's returned
  * to WordPress admin or the site.
  *
  * @param  mixed  $values
  * @param  string $repeater_slug
  * @param  int    $post_id
  *
  * @return array
  */
 public function format_value($values, $repeater_slug, $post_id)
 {
     if (!is_array($values)) {
         return [];
     }
     foreach ($values as $index => $layout) {
         foreach ($layout as $slug => $value) {
             if (is_string($value) && preg_match($this->layout_value_regex, $value)) {
                 if (isset($values[$index][$this->layout_key])) {
                     unset($values[$index][$slug]);
                     continue;
                 }
                 $values[$index][$this->layout_key] = $value;
                 unset($values[$index][$slug]);
                 continue;
             }
             if (papi_is_property_type_key($slug)) {
                 continue;
             }
             $property_type_slug = papi_get_property_type_key_f($slug);
             if (!isset($values[$index][$property_type_slug])) {
                 continue;
             }
             $property_type_value = $values[$index][$property_type_slug];
             $property_type = papi_get_property_type($property_type_value);
             if (!is_object($property_type)) {
                 continue;
             }
             // Get property child slug.
             $child_slug = $this->get_child_slug($repeater_slug, $slug);
             // Create cache key.
             $cache_key = sprintf('%s_%d_%s', $repeater_slug, $index, $slug);
             // Get raw value from cache if enabled.
             if ($this->cache) {
                 $raw_value = papi_cache_get($cache_key, $post_id, $this->get_meta_type());
             } else {
                 $raw_value = false;
             }
             // Load the value.
             if ($raw_value === null || $raw_value === false) {
                 $values[$index][$slug] = $property_type->load_value($value, $child_slug, $post_id);
                 $values[$index][$slug] = papi_filter_load_value($property_type->type, $values[$index][$slug], $child_slug, $post_id, papi_get_meta_type());
                 if (!papi_is_empty($values[$index][$slug]) && $this->cache) {
                     papi_cache_set($cache_key, $post_id, $values[$index][$slug], $this->get_meta_type());
                 }
             } else {
                 $values[$index][$slug] = $raw_value;
             }
             if (strtolower($property_type->type) === 'repeater') {
                 $property_type->cache = false;
             }
             // Format the value from the property class.
             $values[$index][$slug] = $property_type->format_value($values[$index][$slug], $child_slug, $post_id);
             if (!is_admin()) {
                 $values[$index][$slug] = papi_filter_format_value($property_type->type, $values[$index][$slug], $child_slug, $post_id, papi_get_meta_type());
             }
             $values[$index][$property_type_slug] = $property_type_value;
         }
     }
     if (!is_admin()) {
         foreach ($values as $index => $row) {
             foreach ($row as $slug => $value) {
                 if (is_string($value) && preg_match($this->layout_value_regex, $value)) {
                     unset($values[$index][$slug]);
                     $values[$index]['_layout'] = preg_replace($this->layout_value_regex, '', $value);
                 }
                 if (papi_is_property_type_key($slug)) {
                     unset($values[$index][$slug]);
                 }
                 if (papi_is_empty($value)) {
                     unset($values[$index][$slug]);
                 }
             }
         }
     }
     return $values;
 }
开发者ID:nlemoine,项目名称:papi,代码行数:87,代码来源:class-papi-property-flexible.php


示例11: render_row_html

    /**
     * Render the final html that is displayed in the table.
     */
    protected function render_row_html()
    {
        $display_class = $this->display() ? '' : ' papi-hide';
        $rules_class = papi_is_empty($this->get_rules()) ? '' : ' papi-rules-exists';
        $css_class = trim($display_class . $rules_class);
        if ($this->get_option('raw')) {
            echo sprintf('<div class="%s">', $css_class);
            $this->render_property_html();
            echo '</div>';
        } else {
            ?>
			<tr class="<?php 
            echo $css_class;
            ?>
">
				<?php 
            if ($this->get_option('sidebar')) {
                ?>
					<td>
						<?php 
                $this->render_label_html();
                $this->render_description_html();
                ?>
					</td>
				<?php 
            }
            ?>
				<td <?php 
            echo $this->get_option('sidebar') ? '' : 'colspan="2"';
            ?>
>
					<?php 
            $this->render_property_html();
            ?>
				</td>
			</tr>
			<?php 
        }
    }
开发者ID:ekandreas,项目名称:papi,代码行数:42,代码来源:class-papi-property.php


示例12: html

    /**
     * Render property html.
     */
    public function html()
    {
        $settings = $this->get_settings();
        $value = $this->get_value();
        if (is_object($value)) {
            $value = $value->ID;
        } else {
            $value = 0;
        }
        $posts = $this->get_posts($settings);
        $render_label = count($posts) > 1;
        $classes = 'papi-fullwidth';
        if ($settings->select2) {
            $classes = ' papi-component-select2';
        }
        ?>

		<div class="papi-property-post">
			<select
				id="<?php 
        echo $this->html_id();
        ?>
"
				name="<?php 
        echo $this->html_name();
        ?>
"
				class="<?php 
        echo $classes;
        ?>
"
				data-allow-clear="true"
				data-placeholder="<?php 
        echo $settings->placeholder;
        ?>
"
				data-width="100%">

				<?php 
        if (!empty($settings->placeholder)) {
            ?>
					<option value=""></option>
				<?php 
        }
        ?>

				<?php 
        foreach ($posts as $label => $items) {
            ?>

					<?php 
            if ($render_label && is_string($label)) {
                ?>
						<optgroup label="<?php 
                echo $label;
                ?>
">
					<?php 
            }
            ?>

					<?php 
            foreach ($items as $post) {
                if (papi_is_empty($post->post_title)) {
                    continue;
                }
                papi_render_html_tag('option', ['value' => $post->ID, 'selected' => $value === $post->ID ? 'selected' : null, $post->post_title]);
            }
            ?>

					<?php 
            if ($render_label) {
                ?>
						</optgroup>
					<?php 
            }
            ?>

				<?php 
        }
        ?>

			</select>
		</div>
		<?php 
    }
开发者ID:ekandreas,项目名称:papi,代码行数:89,代码来源:class-papi-property-post.php


示例13: papi_update_property_meta_value

/**
 * Update property values on the post with the given post id
 * or update property values on the option page.
 *
 * @param  array $meta
 *
 * @return bool
 */
function papi_update_property_meta_value(array $meta = [])
{
    $meta = array_merge(['id' => 0, 'slug' => '', 'type' => 'post', 'value' => ''], $meta);
    $meta = (object) $meta;
    $meta->type = papi_get_meta_type($meta->type);
    $save_value = true;
    // Set the right update value function for the type.
    $update_value_fn = $meta->type === 'option' ? 'update_option' : 'update_metadata';
    /**
     * Change update function.
     *
     * @param string $update_value_fn
     */
    $update_value_fn = apply_filters('papi/core/update_value_fn', $update_value_fn);
    // Check so the function is callable before using it.
    if (!is_callable($update_value_fn)) {
        return;
    }
    // Check for string keys in the array if any.
    foreach (papi_to_array($meta->value) as $key => $value) {
        if (is_string($key)) {
            $save_value = false;
            break;
        }
    }
    // If main value shouldn't be saved it should be array.
    if (!$save_value && is_array($meta->value)) {
        $meta->value = [$meta->value];
    }
    // Delete saved value if empty.
    if (papi_is_empty($meta->value)) {
        return papi_delete_property_meta_value($meta->id, $meta->slug, $meta->type);
    }
    $result = true;
    foreach (papi_to_array($meta->value) as $key => $value) {
        // Delete saved value if value is empty.
        if (papi_is_empty($value) || $value === '[]' || $value === '{}') {
            return papi_delete_property_meta_value($meta->id, $meta->slug, $meta->type);
        }
        // Delete main value cache.
        papi_cache_delete($meta->slug, $meta->id, $meta->type);
        // If not a array we can save the value.
        if (!is_array($value)) {
            if ($save_value) {
                $value = $meta->value;
            }
            if (papi_get_meta_type($meta->type) === 'option') {
                $out = call_user_func_array($update_value_fn, [unpapify($meta->slug), $value]);
                $result = $out ? $result : $out;
            } else {
                $out = call_user_func_array($update_value_fn, [$meta->type, $meta->id, unpapify($meta->slug), $value]);
                $result = $out ? $result : $out;
            }
            continue;
        }
        // Delete all child value caches.
        papi_update_property_meta_value_cache_delete($meta, $value);
        // Update metadata or option value for all child values.
        foreach ($value as $child_key => $child_value) {
            if (papi_is_empty($child_value)) {
                papi_delete_property_meta_value($meta->id, $child_key, $meta->type);
            } else {
                if (papi_get_meta_type($meta->type) === 'option') {
                    call_user_func_array($update_value_fn, [unpapify($child_key), $child_value]);
                } else {
                    call_user_func_array($update_value_fn, [$meta->type, $meta->id, unpapify($child_key), $child_value]);
                }
            }
        }
    }
    return $result;
}
开发者ID:wp-papi,项目名称:papi,代码行数:80,代码来源:property.php


示例14: papi_update_field

/**
 * Update field with new value. The old value will be deleted.
 *
 * @param  int    $id
 * @param  string $slug
 * @param  mixed  $value
 * @param  string $type
 *
 * @return bool
 */
function papi_update_field($id = null, $slug = null, $value = null, $type = 'post')
{
    if (!is_numeric($id) && is_string($id)) {
        $type = empty($value) ? $value : $type;
        $value = $slug;
        $slug = $id;
        $id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    if (papi_is_empty($value)) {
        return papi_delete_field($id, $slug, $type);
    }
    $id = papi_get_meta_id($type, $id);
    $store = papi_get_meta_store($id, $type);
    if (is_null($store)) {
        return false;
    }
    $property = $store->get_property($slug);
    if (!papi_is_property($property)) {
        return false;
    }
    papi_delete_field($id, $slug, $type);
    $value = $property->update_value($value, $slug, $id);
    $value = papi_filter_update_value($property->get_option('type'), $value, $slug, $id, $type);
    return papi_update_property_meta_value(['type' => $type, 'id' => $id, 'slug' => $slug, 'value' => $value]);
}
开发者ID:nlemoine,项目名称:papi,代码行数:38,代码来源:page.php


示例15: html

 /**
  * Render property html.
  */
 public function html()
 {
     // Setup variables needed.
     $settings = $this->get_settings();
     $value = $this->get_value();
     $options_html = [];
     // Properties that extends dropdown property
     // maybe don't have this setting.
     if (!isset($settings->multiple)) {
         $settings->multiple = false;
     }
     // Override selected setting with
     // database value if not empty.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     $classes = 'papi-fullwidth';
     if ($settings->select2) {
         $classes .= ' papi-component-select2';
     }
     // Add placeholder if any.
     if (!empty($settings->placeholder)) {
         $options_html[] = papi_html_tag('option', ['value' => '', $settings->placeholder]);
     }
     // Create option html tags for all items.
     foreach ($this->get_items() as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         if (papi_is_empty($key)) {
             continue;
         }
         // When a multiple we need to check with
         // `in_array` since the value is a array.
         if ($settings->multiple) {
             $selected = in_array($value, $settings->selected, true);
         } else {
             $selected = $value === $settings->selected;
         }
         $options_html[] = papi_html_tag('option', ['data-edit-url' => get_edit_post_link($value), 'selected' => $selected ? 'selected' : null, 'value' => $value, esc_html(papi_convert_to_string($key))]);
     }
     // When selectize is empty this will be used.
     papi_render_html_tag('input', ['name' => $this->html_name() . ($settings->multiple ? '[]' : ''), 'type' => 'hidden']);
     papi_render_html_tag('select', ['class' => $classes, 'data-allow-clear' => !empty($settings->placeholder), 'data-placeholder' => $settings->placeholder, 'data-width' => '100%', 'id' => $this->html_id() . ($settings->multiple ? '[]' : ''), 'multiple' => $settings->multiple ? 'multiple' : null, 'name' => $this->html_name() . ($settings->multiple ? '[]' : ''), $options_html]);
 }
开发者ID:wp-papi,项目名称:papi,代码行数:46,代码来源:class-papi-property-dropdown.php


示例16: setup_properties

 /**
  * Setup properties.
  */
 protected function setup_properties()
 {
     $this->conditional = new Papi_Core_Conditional();
     if ($this->default_options['sort_order'] === -1) {
         $this->default_options['sort_order'] = papi_filter_settings_sort_order();
     }
     if (papi_is_empty($this->default_options['post_type'])) {
         $this->default_options['post_type'] = papi_get_post_type();
     }
 }
开发者ID:nlemoine,项目名称:papi,代码行数:13,代码来源:class-papi-core-property.php


示例17: papi_html_tag

/**
 * Get html tag from tag name and array of attributes.
 *
 * @param  string $tag
 * @param  array  $attr
 *
 * @return string
 */
function papi_html_tag($tag, $attr = [])
{
    $attributes = [];
    $content = [];
    if (!is_array($attr)) {
        $attr = [$attr];
    }
    foreach ($attr as $key => $value) {
        if (is_numeric($key)) {
            if (is_array($value)) {
                $content[] = implode(' ', $value);
            } else {
                $content[] = $value;
            }
            continue;
        }
        if (is_array($value) || is_object($value)) {
            $value = json_encode($value);
        } else {
            if (is_bool($value)) {
                $value = $value ? 'true' : 'false';
            } else {
                if (is_string($value)) {
                    $value = trim($value);
                }
            }
        }
        if (is_null($value)) {
            continue;
        }
        $attributes[] = sprintf('%s="%s"', $key, esc_attr($value));
    }
    if (papi_is_empty($content)) {
        $end = '>';
    } else {
        $end = sprintf('>%s</%s>', implode(' ', $content), $tag);
    }
    if (!empty($attributes)) {
        $attributes = ' ' . implode(' ', $attributes);
    } else {
        $attributes = '';
    }
    return sprintf('<%s%s%s', $tag, $attributes, $end);
}
开发者ID:KristoferN,项目名称:papi,代码行数:52,代码来源:utilities.php


示例18: import

 /**
  * Import data to Papi.
  *
  * @param  mixed $options
  * @param  array $fields
  *
  * @return bool
  */
 public function import($options, array $fields = [])
 {
     $options = $this->get_import_options($options);
     $meta_id = empty($options['meta_id']) ? $options['post_id'] : $options['meta_id'];
     $meta_type = $options['meta_type'];
     $entry_type = $options['page_type'];
     if (isset($options['update_arrays'])) {
         $this->driver->set_options(['update_array' => $options['update_arrays']]);
     }
     if (empty($meta_id) || empty($fields)) {
         return false;
     }
     if (empty($entry_type)) {
         $entry_type = papi_get_entry_type_by_meta_id($meta_id, $meta_type);
     }
     if (is_string($entry_type)) {
         $entry_type = papi_get_entry_type_by_id($entry_type);
     }
     if ($entry_type instanceof Papi_Entry_Type === false) {
         return false;
     }
     update_metadata($meta_type, $meta_id, papi_get_page_type_key(), $entry_type->get_id());
     $result = true;
     foreach ($fields as $slug => $value) {
         if (!is_string($slug) || papi_is_empty($value)) {
             continue;
         }
         $property = $entry_type->get_property($slug);
         if (!papi_is_property($property)) {
             $result = false;
             continue;
         }
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'before', 'value' => [$value, $slug]]);
         $value = $this->get_value(['post_id' => $meta_id, 'property' => $property, 'slug' => $slug, 'value' => $value]);
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'after', 'value' => [$value, $slug]]);
         $out = papi_update_property_meta_value(['id' => $meta_id, 'slug' => $slug, 'type' => $meta_type, 'value' => $value]);
         $result = $out ? $result : $out;
     }
     return $result;
 }
开发者ID:wp-papi,项目名称:papi,代码行数:48,代码来源:class-papi-porter.php


示例19: papi_update_property_meta_value

/**
 * Update property values on the post with the given post id
 * or update property values on the option page.
 *
 * @param  array $meta
 *
 * @return bool
 */
function papi_update_property_meta_value(array $meta = [])
{
    $meta = array_merge(['post_id' => 0, 'slug' => '', 'type' => Papi_Post_Page::TYPE, 'value' => ''], $meta);
    $meta = (object) $meta;
    $option = $meta->type === 'option' || papi_is_option_page();
    $save_value = true;
    foreach (papi_to_array($meta->value) as $key => $value) {
        if (is_string($key)) {
            $save_value = false;
            break;
        }
    }
    if (!$save_value && is_array($meta->value)) {
        $meta->value = [$meta->value];
    }
    if (papi_is_empty($meta->value)) {
        return papi_delete_property_meta_value($meta->post_id, $meta->slug, $meta->type);
    }
    $result = true;
    foreach (papi_to_array($meta->value) as $key => $value) {
        papi_cache_delete($meta->slug, $meta->post_id);
        if (!is_array($value)) {
            if ($save_value) {
                $value = $meta->value;
            }
            if ($option) {
                $out = update_option(unpapify($meta->slug), $value);
                $result = $out ? $result : $out;
            } else {
                $out = update_post_meta($meta->post_id, unpapify($meta->slug), $value);
                $result = $out ? $result : $out;
            }
            continue;
        }
        foreach ($value as $child_key => $child_value) {
            if (papi_is_empty($child_value)) {
                papi_delete_property_meta_value($meta->post_id, $child_key, $meta->type);
            } else {
                if ($option) {
                    update_option(unpapify($child_key), $child_value);
                } else {
                    update_post_meta($meta->post_id, unpapify($child_key), $child_value);
                }
            }
        }
    }
    return $result;
}
开发者ID:ekandreas,项目名称:papi,代码行数:56,代码来源:property.php


示例20: html

    /**
     * Render property html.
     */
    public function html()
    {
        $post_id = papi_get_post_id();
        $slug = $this->html_name();
        $settings = $this->get_settings();
        $settings_json = [];
        $sort_option = $this->get_sort_option($post_id);
        $sort_options = static::get_sort_options();
        $values = papi_get_only_objects($this->get_value());
        $items = $this->get_items($settings);
        if (papi_is_empty($settings->items)) {
            $values = array_map([$this, 'convert_post_to_item'], $values);
        } else {
            foreach (array_keys($sort_options) as $key) {
                if (strpos($key, 'Post') === 0) {
                    unset($sort_options[$key]);
                }
            }
        }
        // Remove existing values if `only once` is active.
        if ($this->get_setting('only_once')) {
            $items = array_udiff($items, $values, function ($a, $b) {
                // Backwards compatibility with both `post_title` and `title`.
                return strcmp(strtolower(isset($a->post_title) ? $a->post_title : $a->title), strtolower(isset($b->post_title) ? $b->post_title : $b->title));
            });
        }
        // Convert all sneak case key to camel case.
        foreach ((array) $settings as $key => $val) {
            if (!is_string($key) || !in_array($key, ['only_once', 'limit'], true)) {
                continue;
            }
            if ($key = papi_camel_case($key)) {
                $settings_json[$key] = $val;
            }
        }
        ?>
		<div class="papi-property-relationship" data-settings='<?php 
        echo esc_attr(papi_maybe_json_encode($settings_json));
        ?>
'>
			<input type="hidden" name="<?php 
        echo esc_attr($slug);
        ?>
[]" data-papi-rule="<?php 
        echo esc_attr($slug);
        ?>
" />
			<div class="relationship-inner">
				<div class="relationship-top-left">
					<label for="<?php 
        echo esc_attr($this->html_id('search'));
        ?>
"><?php 
        esc_html_e('Search', 'papi');
        ?>
</label>
					<input id="<?php 
        echo esc_attr($this->html_id('search'));
        ?>
" type="search" />
				</div>
				<div class="relationship-top-right">
					<?php 
        if ($settings->show_sort_by) {
            ?>
						<label for="<?php 
            echo esc_attr($this->html_id('sort_option'));
            ?>
"><?php 
            esc_html_e('Sort by', 'papi');
            ?>
</label>
						<select id="<?php 
            echo esc_attr($this->html_id('sort_option'));
            ?>
" name="<?php 
            echo esc_attr($this->html_id('sort_option'));
            ?>
">
							<?php 
            foreach (array_keys($sort_options) as $key) {
                ?>
								<option value="<?php 
                echo esc_attr($key);
                ?>
" <?php 
                echo $key === $sort_option ? 'selected="selected"' : '';
                ?>
><?php 
                echo esc_html($key);
                ?>
</option>
							<?php 
            }
            ?>
						</select>
					<?php 
//.........这里部分代码省略.........
开发者ID:nlemoine,项目名称:papi,代码行数:101,代码来源:class-papi-property-relationship.php



注:本文中的papi_is_empty函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP papi_is_property函数代码示例发布时间:2022-05-15
下一篇:
PHP papi_get_qs函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap