Example #1
0
/**
 * 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>';
}
Example #2
0
/**
 * 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);
}
Example #3
0
    /**
     * 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>';
    }
Example #4
0
/**
 * 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;
}
Example #5
0
/**
 * 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;
}
Example #6
0
/**
 * 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 
    }
}
Example #7
0
/**
 * 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 
}
Example #8
0
/**
 * 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();
}
Example #9
0
/**
 * 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>';
    }
}
Example #10
0
 /**
  * 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;
     }
 }
Example #11
0
/**
 * 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;
}
Example #12
0
/**
 * 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 '&nbsp;<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');
}
Example #13
0
/**
 * 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;
}
Example #14
0
/**
 * 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>';
}
Example #15
0
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 
}
Example #16
0
/**
 * 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;
    }
    beans_open_markup_e('beans_field_description[_' . $field['id'] . ']', '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)) {
        ?>
			<br /><a class="bs-read-more" href="#"><?php 
        _e('More...', 'tm-beans');
        ?>
</a>
			<div class="bs-extended-content"><?php 
        echo $extended;
        ?>
</div>
			<?php 
    }
    beans_close_markup_e('beans_field_description[_' . $field['id'] . ']', 'div');
}
Example #17
0
/**
 * 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())
{
    /**
     * Filter the options fields.
     *
     * The dynamic portion of the hook name, $section, refers to the section id which defines the group of fields.
     *
     * @since 1.0.0
     *
     * @param array $fields An array of options fields.
     */
    $fields = apply_filters("beans_options_fields_{$section}", _beans_pre_standardize_fields($fields));
    /**
     * Filter the options fields menu slug.
     *
     * The dynamic portion of the hook name, $section, refers to the section id which defines the group of fields.
     *
     * @since 1.0.0
     *
     * @param array $menu_slug The menu slug.
     */
    $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_PATH . 'options/class.php';
    $class = new _Beans_Options();
    $class->register($section, $args);
    return true;
}
Example #18
0
 /**
  * Register options.
  */
 public function register()
 {
     global $wp_meta_boxes;
     $fields = array(array('id' => 'beans_dev_mode', 'checkbox_label' => __('Enable development mode', 'beans'), 'type' => 'checkbox', 'description' => 'This option should be enabled while your website is in development.'));
     beans_register_options($fields, 'beans_settings', 'mode_options', array('title' => __('Mode options', 'beans'), 'context' => beans_get('beans_settings', $wp_meta_boxes) ? 'column' : 'normal'));
 }
Example #19
0
 /**
  * Extend WordPress start menu elements.
  *
  * @ignore
  */
 function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     // Stop here if the depth is smaller than starting depth.
     if ($depth < $args->beans_start_level) {
         return;
     }
     $item_id = $item->ID;
     // Wp item attributes.
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = 'menu-item-' . $item->ID;
     $_classes = join(' ', (array) apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
     // WP link attributes.
     $_link_attr = array('title' => $item->attr_title, 'target' => $item->target, 'rel' => $item->xfn, 'href' => $item->url);
     // Prevent empty WP link attributes.
     foreach ($_link_attr as $attr => $value) {
         if (!empty($value)) {
             $link_attr[$attr] = $value;
         }
     }
     $link_attr = apply_filters('nav_menu_link_attributes', $link_attr, $item, $args);
     // Set wp item attributes as defaults.
     $item_attr = array('class' => array($_classes));
     // Add UIKit active class.
     if (in_array('current-menu-item', $classes)) {
         $item_attr['class'][] = 'uk-active';
     }
     // Add UIKit parent attributes.
     if ($depth == $args->beans_start_level && in_array('menu-item-has-children', $classes)) {
         $item_attr['class'][] = 'uk-parent';
         if (beans_get('beans_type', $args) == 'navbar') {
             $item_attr['data-uk-dropdown'] = '';
             $child_indicator = true;
         }
     }
     // Implode to avoid empty spaces.
     $item_attr['class'] = implode(' ', array_filter($item_attr['class']));
     // Set to null if empty to avoid outputing empty class html attribute.
     if (!$item_attr['class']) {
         $item_attr['class'] = null;
     }
     $output .= beans_open_markup("beans_menu_item[_{$item_id}]", 'li', $item_attr, $item, $depth, $args);
     $item_output = $args->before;
     $item_output .= beans_open_markup("beans_menu_item_link[_{$item_id}]", 'a', $link_attr, $item, $depth, $args);
     $item_output .= beans_output("beans_menu_item_text[_{$item_id}]", $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after);
     if (isset($child_indicator)) {
         $item_output .= beans_open_markup("beans_menu_item_child_indicator[_{$item_id}]", 'i', array('class' => 'uk-icon-caret-down uk-margin-small-left'), $item, $depth, $args);
         $item_output .= beans_close_markup("beans_menu_item_child_indicator[_{$item_id}]", 'i', $item, $depth, $args);
     }
     $item_output .= beans_close_markup("beans_menu_item_link[_{$item_id}]", 'a', $link_attr, $item, $depth, $args);
     $item_output .= $args->after;
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
Example #20
0
function tbr_resources_loop($query)
{
    $query_args = array('post_type' => 'resources');
    if ($term_id = beans_get('filter_term_id')) {
        $query_args = array_merge($query_args, array('tax_query' => array(array('taxonomy' => 'resource_type', 'field' => 'term_id', 'terms' => beans_get('filter_term_id')))));
    }
    $the_query = new WP_Query($query_args);
    if (wp_is_mobile()) {
        $filter_id = 'mobile-filters';
    } else {
        $filter_id = 'filters';
    }
    ?>

    <div class="tm-index-wrap tm-portfolio tm-lazy uk-grid-width-1-1 uk-grid-width-small-1-2 uk-grid-width-medium-1-3" data-uk-grid="{gutter: 30, controls: '#<?php 
    echo $filter_id;
    ?>
'}">

		<?php 
    if ($the_query->have_posts()) {
        while ($the_query->have_posts()) {
            $the_query->the_post();
            global $post;
            $thumb_id = get_post_thumbnail_id();
            $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full-size', true);
            $resized_src = beans_edit_image($thumb_url_array[0], array('resize' => array(407, 379, array('center', 'top'))));
            $resource_cats = get_the_terms($post->ID, 'resource_type');
            $resource_cats = array_values($resource_cats);
            for ($cat_count = 0; $cat_count < count($resource_cats); $cat_count++) {
                $resource_type = $resource_cats[$cat_count]->name;
                $lowercase_resource_type = strtolower($resource_type);
                if ($cat_count < count($resource_cats) - 1) {
                    echo ', ';
                }
            }
            ?>
		<div class="tm-item" data-uk-filter="<?php 
            echo $lowercase_resource_type;
            ?>
">
            <div class="uk-article">
                <a rel="bookmark" href="<?php 
            echo get_permalink();
            ?>
" title="<?php 
            the_title();
            ?>
">
                    <img src="<?php 
            echo $resized_src;
            ?>
" width="407" height="378" alt="<?php 
            the_title();
            ?>
" />
                </a>
                <div class="uk-panel uk-panel-box">
    			    <h3 class="uk-margin-top-remove"><a rel="bookmark" href="<?php 
            echo get_permalink();
            ?>
" title="<?php 
            the_title();
            ?>
"><?php 
            the_title();
            ?>
</a></h3>
                    <div class="tm-meta"><?php 
            echo get_the_term_list($post->ID, 'resource_type', '', '');
            echo get_the_term_list($post->ID, 'resource_tags', '', '');
            ?>
</div>
    				<p><?php 
            the_excerpt();
            ?>
</p>
                    <p class="uk-margin-remove"><a rel="bookmark" class="uk-button uk-button-small uk-button-secondary" href="<?php 
            echo get_permalink();
            ?>
" title="Learn more">Learn more</a></p>
    			</div>
            </div>
		</div>
		<?php 
        }
    } else {
        ?>
			<p>Sorry, there are no posts to display</p>
		<?php 
    }
    ?>
	</div>
	<?php 
    wp_reset_query();
}
Example #21
0
/**
 * Setup widget area global widgets data.
 *
 * @ignore
 */
function _beans_setup_widgets($widget_area_content)
{
    global $wp_registered_widgets, $_beans_widget_area;
    $_beans_widgets = array();
    foreach (explode('<!--widget-end-->', $widget_area_content) as $content) {
        if (!preg_match('#<!--widget-([a-z0-9-_]+?)-->#smU', $content, $matches)) {
            continue;
        }
        // Retrieve widget id.
        $id = $matches[1];
        // Stop here if the widget can't be found.
        if (!($data = beans_get($id, $wp_registered_widgets))) {
            continue;
        }
        // Start building the widget array.
        $widget = array();
        // Set defaults.
        $widget['options'] = array();
        $widget['type'] = null;
        $widget['title'] = '';
        // Add total count.
        $widget['count'] = $_beans_widget_area['widgets_count'];
        // Add basic widget arguments.
        foreach (array('id', 'name', 'classname', 'description') as $var) {
            $widget[$var] = isset($data[$var]) ? $data[$var] : null;
        }
        // Add type and options
        if (isset($data['callback']) && is_array($data['callback']) && ($object = current($data['callback']))) {
            if (is_a($object, 'WP_Widget')) {
                $widget['type'] = $object->id_base;
                if (isset($data['params'][0]['number'])) {
                    $number = $data['params'][0]['number'];
                    $params = get_option($object->option_name);
                    if (false === $params && isset($object->alt_option_name)) {
                        $params = get_option($object->alt_option_name);
                    }
                    if (isset($params[$number])) {
                        $widget['options'] = $params[$number];
                    }
                }
            }
        } elseif ($id == 'nav_menu-0') {
            $widget['type'] = 'nav_menu';
        }
        // Widget fallback name.
        if (empty($widget['name'])) {
            $widget['name'] = ucfirst($widget['type']);
        }
        // Extract and add title.
        if (preg_match('#<!--title-start-->(.*)<!--title-end-->#s', $content, $matches)) {
            $widget['title'] = strip_tags($matches[1]);
        }
        // Remove title from content.
        $content = preg_replace('#(<!--title-start-->.*<!--title-end-->*?)#smU', '', $content);
        // Remove widget HTML delimiters.
        $content = preg_replace('#(<!--widget-([a-z0-9-_]+)-->|<!--widgets-end-->)#', '', $content);
        $widget['content'] = $content;
        // Add widget control arguments and register widget.
        $_beans_widgets[$widget['id']] = array_merge($widget, array('show_title' => $_beans_widget_area['beans_show_widget_title'], 'badge' => $_beans_widget_area['beans_show_widget_badge'], 'badge_content' => $_beans_widget_area['beans_widget_badge_content']));
    }
    return $_beans_widgets;
}
Example #22
0
 /**
  * Add setting.
  */
 private function add_setting($wp_customize, $field)
 {
     $defaults = array('db_type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh');
     $field = array_merge($defaults, $field);
     $wp_customize->add_setting($field['name'], array('default' => beans_get('default', $field), 'type' => $field['db_type'], 'capability' => $field['capability'], 'transport' => $field['transport'], 'sanitize_callback' => array($this, 'sanitize')));
 }
Example #23
0
 /**
  * Wrap content in query.
  */
 public function add_content_media_query($content)
 {
     // Ignore if the fragment is a function.
     if ($this->is_function($this->current_fragment)) {
         return $content;
     }
     $parse_url = parse_url($this->current_fragment);
     // Return content if it no media query is set.
     if (!($query = beans_get('query', $parse_url)) || stripos($query, 'beans_compiler_media_query') === false) {
         return $content;
     }
     // Wrap the content in the query.
     $new_content = '@media ' . beans_get('beans_compiler_media_query', wp_parse_args($query)) . ' {' . "\n";
     $new_content .= $content . "\n";
     $new_content .= '}' . "\n";
     return $new_content;
 }
Example #24
0
/**
 * Check the current screen conditions.
 *
 * @ignore
 */
function _beans_is_post_meta_conditions($conditions)
{
    // Check if it is a new post and treat it as such.
    if (false !== stripos($_SERVER['REQUEST_URI'], 'post-new.php')) {
        if (!($current_post_type = beans_get('post_type'))) {
            if (in_array('post', (array) $conditions)) {
                return true;
            } else {
                return false;
            }
        }
    } else {
        // Try to get id from $_GET.
        if ($id = beans_get('post')) {
            $post_id = $id;
        } elseif ($id = beans_post('post_ID')) {
            // Try to get id from $_POST.
            $post_id = $id;
        }
        if (!isset($post_id)) {
            return false;
        }
        $current_post_type = get_post_type($post_id);
    }
    $statements = array(true === $conditions, in_array($current_post_type, (array) $conditions), isset($post_id) && in_array($post_id, (array) $conditions), isset($post_id) && in_array(get_post_meta($post_id, '_wp_page_template', true), (array) $conditions));
    // Return true if any condition is met, otherwise false.
    return in_array(true, $statements);
}
Example #25
0
/**
 * Get action.
 *
 * @ignore
 */
function _beans_get_action($id, $status)
{
    global $_beans_registered_actions;
    $id = _beans_unique_action_id($id);
    if (!($registered = beans_get($status, $_beans_registered_actions))) {
        return false;
    }
    if (!($action = beans_get($id, $registered))) {
        return false;
    }
    return (array) json_decode($action);
}
Example #26
0
/**
 * Get registered theme.
 *
 * @ignore
 */
function _beans_uikit_get_registered_theme($id)
{
    global $_beans_uikit_registered_items;
    // Stop here if is already registered.
    if ($theme = beans_get($id, $_beans_uikit_registered_items['themes'])) {
        return $theme;
    }
    return false;
}
Example #27
0
/**
 * Modify widget count.
 *
 * @since 1.0.0
 *
 * @param string $content The widget content.
 *
 * @return string The modified widget content.
 */
function beans_modify_widget_count($content)
{
    $count = beans_output('beans_widget_count', '$1');
    if (beans_get('dropdown', beans_get_widget('options')) == true) {
        $output = $count;
    } else {
        $output = beans_open_markup('beans_widget_count', 'span', 'class=tm-count');
        $output .= $count;
        $output .= beans_close_markup('beans_widget_count', 'span');
    }
    // Keep closing tag to avoid overwriting the inline JavaScript.
    return preg_replace('#>((\\s|&nbsp;)\\((.*)\\))#', '>' . $output, $content);
}
 /**
  * Dequeue scripts which have been compiled, grab localized
  * data and add it inline.
  */
 public function dequeue_scripts()
 {
     global $wp_scripts;
     if (empty($this->dequeued_scripts)) {
         return;
     }
     $localized = '';
     // Fetch the localized content and dequeue script.
     foreach ($this->dequeued_scripts as $id => $src) {
         if (!($args = beans_get($id, $wp_scripts->registered))) {
             continue;
         }
         if (isset($args->extra['data'])) {
             $localized .= $args->extra['data'] . "\n";
         }
         wp_dequeue_script($id);
     }
     // Add localized content since it was removed with dequeue scripts.
     echo '<script type="text/javascript">';
     echo $localized;
     echo '</script>';
 }
/**
 * Get the current layout.
 *
 * This function generate the layout class base on the current layout.
 *
 * @since 1.0.0
 *
 * @param string $id The searched layout section ID.
 *
 * @return bool Layout class, false if no layout class found.
 */
function beans_get_layout_class($id)
{
    /**
     * Filter the arguments used to define the layout grid.
     *
     * The content number of columns are automatically calculated based on the grid, sidebar primary and
     * sidebar secondary columns.
     *
     * @since 1.0.0
     *
     * @param array $args {
     *     An array of arguments.
     *
     *     @type int $grid              Total number of columns the grid contains. Default 4.
     *     @type int $sidebar_primary   The number of columns the sidebar primary takes. Default 1.
     *     @type int $sidebar_secondary The number of columns the sidebar secondary takes. Default 1.
     * }
     */
    $args = apply_filters('beans_layout_grid_settings', array('grid' => 4, 'sidebar_primary' => 1, 'sidebar_secondary' => 1));
    $g = beans_get('grid', $args);
    // $g stands for grid.
    $c = $g;
    // $c stands for content. Same value as grid by default
    $sp = beans_get('sidebar_primary', $args);
    // $sp stands for sidebar primary.
    $ss = beans_get('sidebar_secondary', $args);
    // $ss stands for 'sidebar secondary.
    $prefix = 'uk-width-medium';
    $classes = array();
    switch ($layout = beans_get_layout()) {
        case 'c':
            $classes['content'] = "{$prefix}-{$c}-{$g}";
            break;
        default:
            $classes['content'] = "{$prefix}-{$c}-{$g}";
    }
    // Add sidebar primary layouts if the primary widget area is registered.
    if ($has_primary = beans_has_widget_area('sidebar_primary')) {
        switch ($layout) {
            case 'c_sp':
                $c = $g - $sp;
                $classes['content'] = "{$prefix}-{$c}-{$g}";
                $classes['sidebar_primary'] = "{$prefix}-{$sp}-{$g}";
                break;
            case 'sp_c':
                $c = $g - $sp;
                $classes['content'] = "{$prefix}-{$c}-{$g} uk-push-{$sp}-{$g}";
                $classes['sidebar_primary'] = "{$prefix}-{$sp}-{$g} uk-pull-{$c}-{$g}";
                break;
        }
    }
    // Add sidebar secondary layouts if the primary and secondary widget area are registered.
    if ($has_primary && beans_has_widget_area('sidebar_secondary')) {
        switch ($layout) {
            case 'c_ss':
                $c = $g - $sp;
                $classes['content'] = "{$prefix}-{$c}-{$g}";
                $classes['sidebar_secondary'] = "{$prefix}-{$sp}-{$g}";
                break;
            case 'c_sp_ss':
                $c = $g - ($sp + $ss);
                $classes['content'] = "{$prefix}-{$c}-{$g}";
                $classes['sidebar_primary'] = "{$prefix}-{$sp}-{$g}";
                $classes['sidebar_secondary'] = "{$prefix}-{$ss}-{$g}";
                break;
            case 'ss_c':
                $c = $g - $sp;
                $classes['content'] = "{$prefix}-{$c}-{$g} uk-push-{$sp}-{$g}";
                $classes['sidebar_secondary'] = "{$prefix}-{$sp}-{$g} uk-pull-{$c}-{$g}";
                break;
            case 'sp_ss_c':
                $c = $g - ($sp + $ss);
                $push_content = $sp + $ss;
                $classes['content'] = "{$prefix}-{$c}-{$g} uk-push-{$push_content}-{$g}";
                $classes['sidebar_primary'] = "{$prefix}-{$sp}-{$g} uk-pull-{$c}-{$g}";
                $classes['sidebar_secondary'] = "{$prefix}-{$ss}-{$g} uk-pull-{$c}-{$g}";
                break;
            case 'sp_c_ss':
                $c = $g - ($sp + $ss);
                $classes['content'] = "{$prefix}-{$c}-{$g} uk-push-{$sp}-{$g}";
                $classes['sidebar_primary'] = "{$prefix}-{$sp}-{$g} uk-pull-{$c}-{$g}";
                $classes['sidebar_secondary'] = "{$prefix}-{$ss}-{$g}";
                break;
        }
    }
    /**
     * Filter the layout class.
     *
     * The dynamic portion of the hook name refers to the searched layout section ID.
     *
     * @since 1.0.0
     *
     * @param string $layout The layout class.
     */
    return apply_filters("beans_layout_class_{$id}", beans_get($id, $classes));
}
 /**
  * Register options.
  */
 public function register()
 {
     global $wp_meta_boxes;
     $fields = array(array('id' => 'beans_edited_images_directories', 'type' => 'flush_edited_images', 'description' => 'Clear all edited images. New images will be created on page load.'));
     beans_register_options($fields, 'beans_settings', 'images_options', array('title' => __('Images options', 'tm-beans'), 'context' => beans_get('beans_settings', $wp_meta_boxes) ? 'column' : 'normal'));
 }