本文整理汇总了PHP中beans_get函数的典型用法代码示例。如果您正苦于以下问题:PHP beans_get函数的具体用法?PHP beans_get怎么用?PHP beans_get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了beans_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beans_field_radio
/**
* Echo radio field type.
*
* @since 1.0.0
*
* @param array $field {
* For best practices, pass the array of data obtained using {@see beans_get_fields()}.
*
* @type mixed $value The field value.
* @type string $name The field name value.
* @type array $attributes An array of attributes to add to the field. The array key defines the
* attribute name and the array value defines the attribute value. Default array.
* @type mixed $default The default value. Default false.
* @type array $options An array used to populate the radio options. The array key defines radio
* value and the array value defines the radio label or image path.
* }
*/
function beans_field_radio($field)
{
if (empty($field['options'])) {
return;
}
$field['default'] = isset($checkbox['default']) ? $checkbox['default'] : key($field['options']);
echo '<fieldset>';
$i = 0;
foreach ($field['options'] as $id => $radio) {
$checked = $id == $field['value'] ? ' checked="checked"' : null;
$extensions = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico');
$has_image = in_array(beans_get('extension', pathinfo($radio)), $extensions) ? 'bs-has-image' : false;
echo '<label class="' . $has_image . '">';
if ($has_image) {
echo '<img src="' . $radio . '" />';
}
echo '<input type="radio" name="' . $field['name'] . '" value="' . $id . '" ' . $checked . ' ' . beans_sanatize_attributes($field['attributes']) . '/>';
if (!$has_image) {
echo $radio;
}
echo '</label>';
$i++;
}
echo '</fieldset>';
}
示例2: beans_get_term_meta
/**
* Get the current term meta value.
*
* @since 1.0.0
*
* @param string $field_id The term meta id searched.
* @param mixed $default The default value to return if the term meta value doesn't exist.
* @param int $term_id Overwrite the current term id.
*
* @return mixed Save data if the term meta value exists, otherwise set the default value.
*/
function beans_get_term_meta($field_id, $default = false, $term_id = false)
{
if (!$term_id) {
$term_id = ($_term_id = beans_get('term_id', get_queried_object())) ? $_term_id : beans_get('tag_ID');
}
return get_option("beans_term_{$term_id}_{$field_id}", $default);
}
示例3: page
/**
* Page content.
*/
public function page($page)
{
global $wp_meta_boxes;
if (!($boxes = beans_get($page, $wp_meta_boxes))) {
return;
}
// Only add column class if there is more than 1 metaboxes.
$column_class = beans_get('column', $boxes, array()) ? ' column' : false;
// Set page data which will be used by the postbox.
echo '<form action="" method="post" class="bs-options" data-page="' . beans_get('page') . '">';
wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
echo '<input type="hidden" name="beans_options_nonce" value="' . esc_attr(wp_create_nonce('beans_options_nonce')) . '" />';
echo '<div class="metabox-holder' . $column_class . '">';
do_meta_boxes($page, 'normal', null);
if ($column_class) {
do_meta_boxes($page, 'column', null);
}
echo '</div>';
echo '<p class="bs-options-form-actions">
<input type="submit" name="beans_save_options" value="Save" class="button-primary">
<input type="submit" name="beans_reset_options" value="Reset" class="button-secondary">
</p>';
echo '</form>';
}
示例4: beans_updater
/**
* Retrieve product data from Beans REST API.
*
* Data are cached in a 24 hours transients and will be returned if found to avoid long loading time.
*
* @ignore
*/
function beans_updater($value)
{
$data = get_site_transient('beans_updater');
$theme = wp_get_theme('tm-beans');
if (!$theme->exists()) {
return $value;
}
$current_version = $theme->get('Version');
// Query Beans REST API if the transient is expired.
if (empty($data)) {
$args = array('timeout' => 15, 'sslverify' => false);
$response = wp_remote_get('http://www.getbeans.io/rest-api/', $args);
if (is_wp_error($response)) {
return $value;
}
// Retrieve data from the body and decode json format.
$data = json_decode(wp_remote_retrieve_body($response), true);
// Stop here if the is an error.
if (isset($data['error'])) {
// Set temporary transient.
set_site_transient('beans_updater', array('version' => $current_version), 30 * MINUTE_IN_SECONDS);
return $value;
}
set_site_transient('beans_updater', $data, 24 * HOUR_IN_SECONDS);
}
// Return data if Beans is not up to date.
if (version_compare($current_version, beans_get('version', $data), '<')) {
$value->response[$data['path']] = array('slug' => $data['slug'], 'name' => $data['name'], 'url' => $data['changelog_url'], 'package' => $data['download_url'], 'new_version' => $data['version'], 'tested' => $data['tested'], 'requires' => $data['requires']);
return $value;
}
return $value;
}
示例5: _beans_is_admin_post_type
/**
* Check if the current screen is a given post type.
*
* @ignore
*/
function _beans_is_admin_post_type($post_types)
{
// Check if it is a new post and treat it as such.
if (stripos($_SERVER['REQUEST_URI'], 'post-new.php') !== false) {
if (!($current_post_type = beans_get('post_type'))) {
return false;
}
} else {
// Try to get id from $_GET.
if ($id = beans_get('post')) {
$post_id = $id;
} elseif ($id = beans_post('post_ID')) {
$post_id = $id;
}
if (!isset($post_id)) {
return false;
}
$current_post_type = get_post_type($post_id);
}
if ($post_types === true) {
return true;
}
if (in_array($current_post_type, (array) $post_types)) {
return true;
}
// Support post ids.
if (isset($post_id) && in_array($post_id, (array) $post_types)) {
return true;
}
return false;
}
示例6: beans_field_checkbox
/**
* Echo checkbox field type.
*
* @since 1.0.0
*
* @param array $field {
* For best practices, pass the array of data obtained using {@see beans_get_fields()}.
*
* @type mixed $value The field value.
* @type string $name The field name value.
* @type array $attributes An array of attributes to add to the field. The array key defines the
* attribute name and the array value defines the attribute value. Default array.
* @type mixed $default The default value. Default false.
* @type string $checkbox_label The field checkbox label. Default 'Enable'.
* }
*/
function beans_field_checkbox($field)
{
?>
<input type="hidden" value="0" name="<?php
echo esc_attr($field['name']);
?>
" />
<input type="checkbox" name="<?php
echo esc_attr($field['name']);
?>
" value="1" <?php
checked($field['value'], 1);
?>
<?php
echo beans_esc_attributes($field['attributes']);
?>
/>
<?php
if ($checkbox_label = beans_get('checkbox_label', $field, __('Enable', 'tm-beans'))) {
?>
<span class="bs-checkbox-label"><?php
echo $checkbox_label;
?>
</span>
<?php
}
}
示例7: beans_field_radio
/**
* Echo radio field type.
*
* @since 1.0.0
*
* @param array $field {
* For best practices, pass the array of data obtained using {@see beans_get_fields()}.
*
* @type mixed $value The field value.
* @type string $name The field name value.
* @type array $attributes An array of attributes to add to the field. The array key defines the
* attribute name and the array value defines the attribute value. Default array.
* @type mixed $default The default value. Default false.
* @type array $options An array used to populate the radio options. The array key defines radio
* value and the array value defines the radio label or image path.
* }
*/
function beans_field_radio($field)
{
if (empty($field['options'])) {
return;
}
$field['default'] = isset($checkbox['default']) ? $checkbox['default'] : key($field['options']);
?>
<fieldset>
<?php
$i = 0;
foreach ($field['options'] as $id => $radio) {
$extensions = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico');
$has_image = in_array(beans_get('extension', pathinfo($radio)), $extensions) ? 'bs-has-image' : false;
?>
<label class="<?php
echo esc_attr($has_image);
?>
">
<?php
if ($has_image) {
?>
<img src="<?php
echo esc_url($radio);
?>
"/>
<?php
}
?>
<input type="radio" name="<?php
echo esc_attr($field['name']);
?>
" value="<?php
echo esc_attr($id);
?>
" <?php
checked($id, $field['value'], 1);
?>
<?php
echo beans_esc_attributes($field['attributes']);
?>
/>
<?php
if (!$has_image) {
?>
<?php
echo $radio;
?>
<?php
}
?>
</label>
<?php
$i++;
}
?>
</fieldset>
<?php
}
示例8: beans_comments_template
/**
* Echo comments template part.
*
* The comments template part only loads if comments are active to prevent unnecessary memory usage.
*
* @since 1.0.0
*/
function beans_comments_template()
{
global $post;
if (!post_type_supports(beans_get('post_type', $post), 'comments')) {
return;
}
comments_template();
}
示例9: beans_field_checkbox
/**
* Echo checkbox field type.
*
* @since 1.0.0
*
* @param array $field {
* For best practices, pass the array of data obtained using {@see beans_get_fields()}.
*
* @type mixed $value The field value.
* @type string $name The field name value.
* @type array $attributes An array of attributes to add to the field. The array key defines the
* attribute name and the array value defines the attribute value. Default array.
* @type mixed $default The default value. Default false.
* @type string $checkbox_label The field checkbox label. Default 'Enable'.
* }
*/
function beans_field_checkbox($field)
{
$checked = $field['value'] ? ' checked="checked"' : null;
echo '<input type="hidden" value="0" name="' . $field['name'] . '" />';
echo '<input type="checkbox" name="' . $field['name'] . '" value="1" ' . $checked . ' ' . beans_sanatize_attributes($field['attributes']) . ' />';
if ($checkbox_label = beans_get('checkbox_label', $field, 'Enable')) {
echo '<span class="bs-checkbox-label">' . $checkbox_label . '</span>';
}
}
示例10: do_once
/**
* Trigger actions only once.
*/
private function do_once()
{
static $once = false;
if (!$once) {
add_action(beans_get('taxonomy') . '_edit_form', array($this, 'nonce'));
add_action('edit_term', array($this, 'save'));
add_action('delete_term', array($this, 'delete'), 10, 3);
$once = true;
}
}
示例11: beans_get_post_meta
/**
* Get the current post meta value.
*
* This function is a shortcut of {@link http://codex.wordpress.org/Function_Reference/get_post_meta get_post_meta()}.
*
* @since 1.0.0
*
* @param string $field_id The post meta id searched.
* @param mixed $default The default value to return of the post meta value doesn't exist.
* @param int $term_id Overwrite the current post id.
*
* @return mixed Saved data if exist, otherwise default value set.
*/
function beans_get_post_meta($field_id, $default = false, $post_id = false)
{
if (!$post_id) {
$post_id = !($id = get_the_id()) ? beans_get('post') : $id;
}
$post_meta = get_post_meta($post_id);
if (isset($post_meta[$field_id])) {
return get_post_meta($post_id, $field_id, true);
}
return $default;
}
示例12: beans_field_description
/**
* Echo field description.
*
* @since 1.0.0
*
* @param array $field {
* Array of data.
*
* @type string $description The field description. The description can be truncated using <!--more-->
* as a delimiter. Default false.
* }
*/
function beans_field_description($field)
{
if (!($description = beans_get('description', $field))) {
return;
}
echo beans_open_markup('beans_field_description', 'div', array('class' => 'bs-field-description'));
if (preg_match('#<!--more-->#', $description, $matches)) {
list($description, $extended) = explode($matches[0], $description, 2);
}
echo $description;
if (isset($extended)) {
echo ' <a class="bs-read-more" href="#">' . __('More...', 'beans') . '</a>';
echo '<div class="bs-extended-content">' . $extended . '</div>';
}
echo beans_close_markup('beans_field_description', 'div');
}
示例13: beans_register_options
/**
* Register options.
*
* This function should only be invoked through the 'admin_init' action.
*
* @since 1.0.0
*
* @param array $fields {
* Array of fields to register.
*
* @type string $id A unique id used for the field. This id will also be used to save the value in
* the database.
* @type string $type The type of field to use. Please refer to the Beans core field types for more
* information. Custom field types are accepted here.
* @type string $label The field label. Default false.
* @type string $description The field description. The description can be truncated using <!--more-->
* as a delimiter. Default false.
* @type array $attributes An array of attributes to add to the field. The array key defines the
* attribute name and the array value defines the attribute value. Default array.
* @type mixed $default The default field value. Default false.
* @type array $fields Must only be used for 'group' field type. The array arguments are similar to the
* {@see beans_register_fields()} $fields arguments.
* @type bool $db_group Must only be used for 'group' field types. Defines whether the group of fields
* registered should be saved as a group in the database or as individual
* entries. Default false.
* }
* @param string $menu_slug The menu slug used by fields.
* @param string $section A section id to define the group of fields.
* @param array $args {
* Optional. Array of arguments used to register the fields.
*
* @type string $title The metabox Title. Default 'Undefined'.
* @type string $context Where on the page where the metabox should be shown
* ('normal', 'column'). Default 'normal'.
* }
*
* @return bool True on success, false on failure.
*/
function beans_register_options(array $fields, $menu_slug, $section, $args = array())
{
$fields = apply_filters("beans_options_fields_{$section}", _beans_pre_standardize_fields($fields));
$menu_slug = apply_filters("beans_options_menu_slug_{$section}", $menu_slug);
// Stop here if the page isn't concerned.
if (beans_get('page') !== $menu_slug || !is_admin()) {
return;
}
// Stop here if the field can't be registered.
if (!beans_register_fields($fields, 'option', $section)) {
return false;
}
// Load the class only if this function is called to prevent unnecessary memory usage.
require_once BEANS_API_COMPONENTS_PATH . 'options/class.php';
$class = new _Beans_Options();
$class->register($section, $args);
return true;
}
示例14: beans_field_image
/**
* Echo image field type.
*
* @since 1.0.0
*
* @param array $field {
* For best practices, pass the array of data obtained using {@see beans_get_fields()}.
*
* @type mixed $value The field value.
* @type string $name The field name value.
* @type array $attributes An array of attributes to add to the field. The array key defines the
* attribute name and the array value defines the attribute value. Default array.
* @type mixed $default The default value. Default false.
* @type string $multiple Set to true to enable mutliple images (gallery). Default false.
* }
*/
function beans_field_image($field)
{
// Set the images variable and add placeholder to the array.
$images = array_merge((array) $field['value'], array('placeholder'));
// Is multiple set.
$multiple = beans_get('multiple', $field);
// Hide beans if it is a single image and an image already exists
$hide = !$multiple && is_numeric($field['value']) ? 'style="display: none"' : '';
echo '<a href="#" class="bs-add-image button button-small" ' . $hide . '>';
echo _n('Add Image', 'Add Images', $multiple ? 2 : 1, 'beans');
echo '</a>';
echo '<input type="hidden" name="' . $field['name'] . '" value="">';
echo '<div class="bs-images-wrap" data-multiple="' . $multiple . '">';
foreach ($images as $id) {
// Stop here if the id is false.
if (!$id) {
continue;
}
$class = '';
$img = wp_get_attachment_image_src($id, 'thumbnail');
$attributes = array_merge(array('class' => 'image-id', 'type' => 'hidden', 'name' => $multiple ? $field['name'] . '[]' : $field['name'], 'value' => $id), $field['attributes']);
// Set placeholder.
if ($id == 'placeholder') {
$class = 'bs-image-template';
$attributes = array_merge($attributes, array('disabled' => 'disabled', 'value' => false));
}
echo '<div class="bs-image-wrap ' . $class . '">';
echo '<input ' . beans_sanatize_attributes($attributes) . ' />';
echo '<img src="' . beans_get(0, $img) . '">';
echo '<div class="bs-toolbar">';
if ($multiple) {
echo '<a href="#" class="dashicons dashicons-menu"></a>';
}
echo '<a href="#" class="dashicons dashicons-edit"></a>';
echo '<a href="#" class="dashicons dashicons-post-trash"></a>';
echo '</div>';
echo '</div>';
}
echo '</div>';
}
示例15: tbr_blog_top
function tbr_blog_top()
{
?>
<div class="uk-clearfix">
<div id="js-blog-filters" class="filters uk-float-left">
<nav class="uk-clearfix">
<a href="#offcanvas_filters" class="uk-hidden-large uk-float-left tm-filters uk-button uk-button-small" data-uk-offcanvas><i class="uk-icon-filter"></i> Show Filters</a>
<ul id="filters" class="uk-subnav uk-subnav-line uk-margin-large-bottom uk-visible-large">
<li<?php
echo !beans_get('filter_term_id') ? ' class="uk-active"' : '';
?>
data-uk-filter=""><a href="/blog/">All</a></li>
<?php
foreach (get_terms('category', array('orderby' => 'id', 'hide_empty' => true)) as $term) {
?>
<li<?php
echo beans_get('filter_term_id') == $term->term_id ? ' class="uk-active"' : '';
?>
data-uk-filter="<?php
echo $term->name;
?>
"><a href="<?php
echo add_query_arg('filter_term_id', $term->term_id);
?>
"><?php
echo $term->name;
?>
</a></li>
<?php
}
?>
</ul>
</nav>
</div>
</div>
<?php
}