/** * Return the template path if the template exists. Otherwise, return default. * * @param string $template * @return string The template path if the template exists. Otherwise, return default. * @since 1.0.0 */ function charitable_get_template_path($template, $default = "") { $t = new Charitable_Template($template, false); $path = $t->locate_template(); if (!file_exists($path)) { $path = $default; } return $path; }
/** * The callback method for the campaigns shortcode. * * This receives the user-defined attributes and passes the logic off to the class. * * @param array $atts User-defined shortcode attributes. * @return string * @access public * @static * @since 1.0.0 */ public static function display($atts) { $default = array('orderby' => 'post_date', 'number' => get_option('posts_per_page'), 'category' => '', 'creator' => '', 'exclude' => '', 'include_inactive' => false, 'columns' => 2); $args = shortcode_atts($default, $atts, 'campaigns'); $args['campaigns'] = self::get_campaigns($args); /* Allows extensions/themes to plug in their own template objects here. */ $template = apply_filters('charitable_campaigns_shortcode_template', false, $args); /* Fall back to default Charitable_Template if no template returned or if template was not object of 'Charitable_Template' class. */ if (!is_object($template) || !is_a($template, 'Charitable_Template')) { $template = new Charitable_Template('campaign-loop.php', false); } if (!$template->template_file_exists()) { return false; } $view_args = apply_filters('charitable_campaigns_shortcode_view_args', array('campaigns' => $args['campaigns'], 'columns' => $args['columns']), $args); $template->set_view_args($view_args); ob_start(); $template->render(); return apply_filters('charitable_campaigns_shortcode', ob_get_clean(), $args); }
/** * Render a form field. * * @param array $field * @param string $key * @param Charitable_Form $form * @param int $index * @return boolean False if the field was not rendered. True otherwise. * @access public * @since 1.0.0 */ public function render_field($field, $key, $form, $index = 0, $namespace = null) { if (!$form->is_current_form($this->id)) { return false; } if (!isset($field['type'])) { return false; } $input_name = is_null($namespace) ? $key : $namespace . '[' . $key . ']'; $field['key'] = apply_filters('charitable_form_field_key', $input_name, $key, $namespace, $form, $index); /* Allows extensions/themes to plug in their own template objects here. */ $template = apply_filters('charitable_form_field_template', false, $field, $form, $index); /* Fall back to default Charitable_Template if no template returned or if template was not object of 'Charitable_Template' class. */ if (!$this->is_valid_template($template)) { $template = new Charitable_Template($this->get_template_name($field), false); } if (!$template->template_file_exists()) { return false; } $template->set_view_args(array('form' => $this, 'field' => $field, 'classes' => $this->get_field_classes($field, $index))); $template->render(); return true; }