/** * Echo loop template part. * * @since 1.0.0 * * @param string $id Optional. The loop ID is used to filter the loop WP_Query arguments. */ function beans_loop_template($id = false) { // Set default loop id. if (!$id) { $id = 'main'; } // Only run new query if a filter is set. if ($_has_filter = beans_has_filters("beans_loop_query_args[_{$id}]")) { global $wp_query; /** * Filter the beans loop query. This can be used for custom queries. * * @since 1.0.0 */ if ($args = beans_apply_filters("beans_loop_query_args[_{$id}]", false)) { $wp_query = new WP_Query($args); } } // Allow overwrite. Require the default loop.php if not overwrite is found. if (locate_template('loop.php', true, false) == '') { require BEANS_STRUCTURE_PATH . 'loop.php'; } // Only reset the query if a filter is set. if ($_has_filter) { wp_reset_query(); } }
/** * Register a widget area. * * Since a Beans widget area is using the WordPress sidebar, this function registers a WordPress sidebar using * {@link http://codex.wordpress.org/Function_Reference/register_sidebar register_sidebar()}, with additional * arguments. * * Note that the 'class', before_widget', 'after_widget', 'before_title' and 'after_title' arguments are not * supported. Beans widgets are built using the Beans HTML API which allows full control over HTML markup * and attributes. * * When allowing for automatic generation of the name and ID parameters, keep in mind that the incrementor for * your widget area can change over time depending on what other plugins and themes are installed. * * @since 1.0.0 * * @param array $args { * Optional. Arguments used by the widget area. * * @type string $id Optional. The unique identifier by which the widget area will be called. * @type string $name Optional. The name or title of the widget area displayed in the * admin dashboard. * @type string $description Optional. The widget area description. * @type string $beans_type Optional. The widget area type. Accepts 'stack', 'grid' or 'offcanvas'. * Default stack. * @type bool $beans_show_widget_title Optional. Whether to show the widget title or not. Default true. * @type bool $beans_show_widget_badge Optional. Whether to show the widget badge or not. Default false. * @type bool $beans_widget_badge_content Optional. The badge content. This may contain widget shortcodes * {@see beans_widget_shortcodes(). Default 'Hello'. * * @return string The widget area ID is added to the $wp_registered_sidebars globals when the widget area is setup. */ function beans_register_widget_area($args = array(), $widget_control = array()) { /** * Filter the default arguments used by the widget area. * * @since 1.0.0 */ $defaults = apply_filters('beans_widgets_area_default_args', array('beans_type' => 'stack', 'beans_show_widget_title' => true, 'beans_show_widget_badge' => false, 'beans_widget_badge_content' => __('Hello', 'beans'))); $id = beans_get('id', $args); /** * Filter the arguments used by the widget area. * * The dynamic portion of the hook name, $id, refers to the widget area id. * * @since 1.0.0 */ $args = beans_apply_filters("beans_widgets_area_args[_{$id}]", array_merge($defaults, $args)); return register_sidebar($args); }
/** * Modify comment form fields. * * This function replaces the default WordPress comment fields. * * @since 1.0.0 * * @param array $fields The WordPress default fields. * * @return array The modified fields. */ function beans_comment_form_fields($fields) { $commenter = wp_get_current_commenter(); // Author. $author = beans_open_markup('beans_comment_form[_name]', 'div', array('class' => 'uk-width-medium-1-3')); /** * Filter whether the comment form name legend should load or not. * * @since 1.0.0 */ if (beans_apply_filters('beans_comment_form_legend[_name]', true)) { $author .= beans_open_markup('beans_comment_form_legend[_name]', 'legend'); $author .= beans_output('beans_comment_form_legend_text[_name]', __('Name', 'tm-beans')); $author .= beans_close_markup('beans_comment_form_legend[_name]', 'legend'); } $author .= beans_selfclose_markup('beans_comment_form_field[_name]', 'input', array('id' => 'author', 'class' => 'uk-width-1-1', 'type' => 'text', 'value' => esc_attr($commenter['comment_author']), 'name' => 'author')); $author .= beans_close_markup('beans_comment_form[_name]', 'div'); // Email. $email = beans_open_markup('beans_comment_form[_email]', 'div', array('class' => 'uk-width-medium-1-3')); /** * Filter whether the comment form email legend should load or not. * * @since 1.0.0 */ if (beans_apply_filters('beans_comment_form_legend[_email]', true)) { $email .= beans_open_markup('beans_comment_form_legend[_email]', 'legend'); $email .= beans_output('beans_comment_form_legend_text[_email]', sprintf(__('Email %s', 'tm-beans'), get_option('require_name_email') ? ' *' : '')); $email .= beans_close_markup('beans_comment_form_legend[_email]', 'legend'); } $email .= beans_selfclose_markup('beans_comment_form_field[_email]', 'input', array('id' => 'email', 'class' => 'uk-width-1-1', 'type' => 'text', 'value' => esc_attr($commenter['comment_author_email']), 'name' => 'email', 'required' => get_option('require_name_email') ? '' : null)); $email .= beans_close_markup('beans_comment_form[_email]', 'div'); // Url. $url = beans_open_markup('beans_comment_form[_website]', 'div', array('class' => 'uk-width-medium-1-3')); /** * Filter whether the comment form url legend should load or not. * * @since 1.0.0 */ if (beans_apply_filters('beans_comment_form_legend[_url]', true)) { $url .= beans_open_markup('beans_comment_form_legend', 'legend'); $url .= beans_output('beans_comment_form_legend_text[_url]', __('Website', 'tm-beans')); $url .= beans_close_markup('beans_comment_form_legend[_url]', 'legend'); } $url .= beans_selfclose_markup('beans_comment_form_field[_url]', 'input', array('id' => 'url', 'class' => 'uk-width-1-1', 'type' => 'text', 'value' => esc_attr($commenter['comment_author_url']), 'name' => 'url')); $url .= beans_close_markup('beans_comment_form[_website]', 'div'); $fields = array('author' => $author, 'email' => $email, 'url' => $url); return $fields; }
/** * Register close markup. * * This function is similar to {@see beans_open_markup()}, but does not accept HTML attributes. The $id * argument must be the identical to the opening markup. * * @since 1.0.0 * * @param string $id Identical to the opening markup ID. * @param string $tag The HTML tag. * @param mixed $var Additional variables passed to the functions hooked to <tt>$id</tt>. * * @return string The output. */ function beans_close_markup($id, $tag) { // Stop here if the tag is set to false, the before and after actions won't run in this case. if (($tag = beans_apply_filters($id . '_markup', $tag)) === null) { return; } $args = func_get_args(); // Remove function $tag argument. unset($args[1]); // Set before action id. $args[0] = $id . '_append_markup'; $output = call_user_func_array('_beans_render_action', $args); // Don't output the tag if empty, the before and after actions still run. if ($tag) { $output .= '</' . $tag . '>'; } // Set after action id. $args[0] = $id . '_after_markup'; $output .= call_user_func_array('_beans_render_action', $args); return $output; }
/** * Echo comment textarea field. * * This function replaces the default WordPress comment textarea field. * * @since 1.0.0 */ function beans_comment_form_comment() { echo beans_open_markup('beans_comment_form[_comment]', 'p', array('class' => 'uk-width-medium-1-1')); /** * Filter whether the comment form textarea legend should load or not. * * @since 1.0.0 */ if (beans_apply_filters('beans_comment_form_legend[_comment]', true)) { echo beans_open_markup('beans_comment_form_legend[_comment]', 'legend'); echo beans_output('beans_comment_form_legend_text[_comment]', __('Comment *', 'tm-beans')); echo beans_close_markup('beans_comment_form_legend[_comment]', 'legend'); } echo beans_open_markup('beans_comment_form_field[_comment]', 'textarea', array('id' => 'comment', 'class' => 'uk-width-1-1', 'name' => 'comment', 'required' => '', 'rows' => 8)); echo beans_close_markup('beans_comment_form_field[_comment]', 'textarea'); echo beans_close_markup('beans_comment_form[_comment]', 'p'); }