/** * Handle the [wpsl] shortcode. * * @since 1.0.0 * @param array $atts Shortcode attributes * @return string $output The wpsl template */ public function show_store_locator($atts) { global $wpsl_settings; // Accept a 'template' attribute to specify the template ID e.g. "default" or "below_map". $atts = shortcode_atts(array('template' => $wpsl_settings['template_id']), $atts); // Make sure the required scripts are included for the wpsl shortcode. array_push($this->load_scripts, 'wpsl_store_locator'); $template_list = wpsl_get_templates(); $template_path = ''; // Loop over the template list and look for a matching id with the one set on the settings page. foreach ($template_list as $template) { if ($atts['template'] == $template['id']) { $template_path = $template['path']; break; } } // Check if we have a template path and the file exists, otherwise we use the default template. if (!$template_path || !file_exists($template_path)) { $template_path = WPSL_PLUGIN_DIR . 'frontend/templates/default.php'; } $output = (include $template_path); return $output; }
/** * Show a list of available templates. * * @since 1.2.20 * @return string $dropdown The html for the template option list */ public function show_template_options() { global $wpsl_settings; $dropdown = '<select id="wpsl-store-template" name="wpsl_ux[template_id]" autocomplete="off">'; $i = 0; foreach (wpsl_get_templates() as $template) { $template_id = isset($template['id']) ? $template['id'] : ''; $selected = $wpsl_settings['template_id'] == $template_id ? ' selected="selected"' : ''; $dropdown .= "<option value='" . esc_attr($template_id) . "' {$selected}>" . esc_html($template['name']) . "</option>"; $i++; } $dropdown .= '</select>'; return $dropdown; }