public function __construct(array $meta) { parent::__construct($meta); // reset version to prior to upgrades update_option('bwp_plugin_version', '1.0.0'); $this->build_properties('BWP_Plugin', array(), __FILE__, 'http://betterwp.net', false); }
/** * Generate HTML field */ protected function generate_html_field($type = '', $data = array(), $name = '', $in_section = false) { $pre_html_field = ''; $post_html_field = ''; $checked = 'checked="checked" '; $selected = 'selected="selected" '; $value = isset($this->form_options[$name]) ? $this->form_options[$name] : ''; $value = isset($data['value']) ? $data['value'] : $value; if ('checkbox' == $type) { $value = current(array_values($data)); $value = $value ? $value : 'yes'; } $value = !empty($this->domain) && ('textarea' == $type || 'input' == $type) ? $this->bridge->t($value, $this->domain) : $value; if (is_array($value)) { foreach ($value as &$v) { $v = is_array($v) ? array_map('esc_attr', $v) : esc_attr($v); } } else { $value = 'textarea' == $type ? esc_html($value) : esc_attr($value); } $array_replace = array(); $array_search = array('type', 'text', 'size', 'name', 'value', 'cols', 'rows', 'label', 'disabled', 'pre', 'post', 'attributes', 'label_attributes'); $return_html = ''; $attributes = $this->generate_field_attributes($name); $label_attributes = ''; $br = $this->is_compound_field($name) || $type == 'textarea' ? '' : "<br />\n"; $pre = !empty($data['pre']) ? $data['pre'] : ''; $post = !empty($data['post']) ? $data['post'] : ''; $param = empty($this->form['params'][$name]) ? false : $this->form['params'][$name]; $name_attr = esc_attr($name); switch ($type) { case 'heading': case 'heading4': $html_field = '%s'; break; case 'input': $data['label'] = !empty($data['label']) ? ' <em>' . $data['label'] . '</em>' : ''; $html_field = !$in_section ? '%pre%<input %attributes%%disabled% size="%size%" type="text" ' . 'id="' . $name_attr . '" ' . 'name="' . $name_attr . '" ' . 'value="' . $value . '" />%label%' : '<label for="' . $name_attr . '">%pre%<input %attributes%%disabled% size="%size%" type="text" ' . 'id="' . $name_attr . '" ' . 'name="' . $name_attr . '" ' . 'value="' . $value . '" />%label%</label>'; $post_html_field = '%post%'; break; case 'select': case 'select_multi': $pre_html_field = 'select_multi' == $type ? '%pre%<select %attributes%id="' . $name_attr . '" name="' . $name_attr . '[]" multiple>' . "\n" : '%pre%<select %attributes%id="' . $name_attr . '" name="' . $name_attr . '">' . "\n"; $html_field = '<option %selected%value="%value%">%option%</option>'; $post_html_field = '</select>%post%' . $br; break; case 'checkbox': $html_field = '<label %label_attributes%for="%name%">' . '<input %attributes%%checked%type="checkbox" id="%name%" name="%name%" value="yes" /> %label%</label>'; $post_html_field = '%post%'; break; case 'checkbox_multi': $html_field = '<label %label_attributes%for="%name%-%value%">' . '<input %attributes%%checked%type="checkbox" id="%name%-%value%" name="%name%[]" value="%value%" /> %label%</label>'; $post_html_field = '%post%'; break; case 'radio': $html_field = '<label %label_attributes%>' . '<input %attributes%%checked%type="radio" ' . 'name="' . $name_attr . '" value="%value%" /> %label%</label>'; $post_html_field = '%post%'; break; case 'textarea': $html_field = '%pre%<textarea %attributes%%disabled% ' . 'id="' . $name_attr . '" ' . 'name="' . $name_attr . '" cols="%cols%" rows="%rows%">' . $value . '</textarea>'; $post_html_field = '%post%'; break; // @since rev 161 add a help field // @since rev 161 add a help field case 'help': $html_field_class = 'bwp-field-help'; $html_field_inner = ' <span %attributes%>(?)</span>'; // use nice font icon for WP 3.8+ if ($this->plugin->get_current_wp_version('3.8')) { $html_field_class = 'dashicons dashicons-editor-help bwp-field-help'; $html_field_inner = ' <span %attributes%></span>'; } // use explicitly set attributes for this field when needed if (empty($data['url'])) { $attributes = isset($data['attributes']) && is_array($data['attributes']) ? $data['attributes'] : array('class' => ''); $attributes['class'] .= ' ' . $html_field_class; $attributes = $this->generate_attribute_string($attributes); $html_field = $html_field_inner; } else { $attributes = $this->generate_attribute_string(array('class' => $html_field_class)); $html_field = '<a class="bwp-field-help-link" target="_blank" ' . 'title="' . __('View more info in a separate tab', $this->domain) . '" ' . 'href="' . esc_url($data['url']) . '">' . $html_field_inner . '</a>'; } break; // @since rev 165 add button field // @since rev 165 add button field case 'button': $data['type'] = empty($data['type']) ? 'button' : $data['type']; $data['text'] = empty($data['text']) ? '' : $data['text']; // set default button classes $btn_class = !empty($data['is_primary']) ? 'button-primary' : 'button-secondary'; $attributes = $this->get_field_attributes($name); $attributes['class'] = $btn_class . ' ' . $attributes['class']; $attributes = $this->generate_attribute_string($attributes); $html_field = '%pre%<button %attributes%%disabled% ' . 'id="' . $name_attr . '" ' . 'name="' . $name_attr . '" type="%type%">' . '%text%' . '</button>'; $post_html_field = '%post%'; break; } if (!isset($data)) { return; } if (strpos($type, 'heading') === 0 && !is_array($data)) { $return_html .= sprintf($html_field, $data); } elseif ($type == 'radio' || $type == 'checkbox' || $type == 'checkbox_multi' || $type == 'select' || $type == 'select_multi') { // generate label attributes for checkbox/radiobox if any if (strpos($type, 'select') === false) { $label_attributes = array(); $this->generate_field_help_attributes($name, $label_attributes); $label_attributes = $this->generate_attribute_string($label_attributes); // generating label attributes might add some post HTML, so we // need to reassign br here $br = $this->is_compound_field($name) ? '' : "<br />\n"; } foreach ($data as $key => $value) { if ($type == 'checkbox') { // handle checkbox a little bit differently if ($this->form_options[$name] == 'yes') { $return_html .= str_replace(array('%value%', '%name%', '%label%', '%checked%', '%attributes%', '%label_attributes%'), array($value, $name_attr, $key, $checked, $attributes, $label_attributes), $html_field); $return_html .= apply_filters('bwp_option_after_' . $type . '_' . $name . '_checked', '', $value, $param); $return_html .= $br; } else { $return_html .= str_replace(array('%value%', '%name%', '%label%', '%checked%', '%attributes%', '%label_attributes%'), array($value, $name_attr, $key, '', $attributes, $label_attributes), $html_field); $return_html .= apply_filters('bwp_option_after_' . $type . '_' . $name, '', $value, $param); $return_html .= $br; } } elseif ($type == 'checkbox_multi') { // handle a multi checkbox differently if (isset($this->form_options[$name]) && is_array($this->form_options[$name]) && in_array($value, $this->form_options[$name])) { $return_html .= str_replace(array('%value%', '%name%', '%label%', '%checked%', '%attributes%', '%label_attributes%'), array($value, $name_attr, $key, $checked, $attributes, $label_attributes), $html_field); $return_html .= apply_filters('bwp_option_after_' . $type . '_' . $name . '_checked', '', $value, $param); $return_html .= $br; } else { $return_html .= str_replace(array('%value%', '%name%', '%label%', '%checked%', '%attributes%', '%label_attributes%'), array($value, $name_attr, $key, '', $attributes, $label_attributes), $html_field); $return_html .= apply_filters('bwp_option_after_' . $type . '_' . $name, '', $value, $param); $return_html .= $br; } } elseif (isset($this->form_options[$name]) && ($this->form_options[$name] == $value || is_array($this->form_options[$name]) && in_array($value, $this->form_options[$name]))) { $item_br = $type == 'select' || $type == 'select_multi' ? "\n" : $br; $return_html .= str_replace(array('%value%', '%name%', '%label%', '%option%', '%checked%', '%selected%', '%pre%', '%post%'), array($value, $name_attr, $key, $key, $checked, $selected, $pre, $post), $html_field) . $item_br; } else { $item_br = $type == 'select' || $type == 'select_multi' ? "\n" : $br; $return_html .= str_replace(array('%value%', '%name%', '%label%', '%option%', '%checked%', '%selected%', '%pre%', '%post%'), array($value, $name_attr, $key, $key, '', '', $pre, $post), $html_field) . $item_br; } } } else { foreach ($array_search as &$keyword) { $array_replace[$keyword] = ''; if ($keyword == 'attributes') { $array_replace[$keyword] = $attributes; } elseif (!empty($data[$keyword])) { $array_replace[$keyword] = $data[$keyword]; } $keyword = '%' . $keyword . '%'; } $return_html = str_replace($array_search, $array_replace, $html_field) . $br; } // inline fields $inline_html = ''; if (isset($this->form['inline_fields'][$name]) && is_array($this->form['inline_fields'][$name])) { foreach ($this->form['inline_fields'][$name] as $field => $field_type) { if (isset($this->form[$field_type][$field])) { $inline_html = ' ' . $this->generate_html_field($field_type, $this->form[$field_type][$field], $field, $in_section); } } } // html before field $pre = !empty($this->form['pre'][$name]) ? ' ' . $this->form['pre'][$name] : $pre; // html after field $post = !empty($this->form['post'][$name]) ? ' ' . $this->form['post'][$name] : $post; // support for custom html attributes $pre_html_field = str_replace('%attributes%', $attributes, $pre_html_field); return str_replace('%pre%', $pre, $pre_html_field) . $return_html . str_replace('%post%', $post, $post_html_field) . $inline_html; }
public function __construct(array $meta, BWP_WP_Bridge $bridge = null, BWP_Cache $cache = null) { parent::__construct($meta, $bridge, $cache); // basic version checking if (!$this->check_required_versions()) { return; } // default options $options = array('enable_cache' => '', 'enable_cache_auto_gen' => 'yes', 'enable_gzip' => '', 'enable_xslt' => '', 'enable_sitemap_date' => '', 'enable_sitemap_taxonomy' => 'yes', 'enable_sitemap_external' => '', 'enable_sitemap_split_post' => 'yes', 'enable_sitemap_author' => '', 'enable_sitemap_site' => 'yes', 'enable_stats' => 'yes', 'enable_credit' => 'yes', 'enable_ping' => 'yes', 'enable_ping_google' => 'yes', 'enable_ping_bing' => 'yes', 'enable_log' => 'yes', 'enable_debug' => '', 'enable_debug_extra' => '', 'enable_robots' => 'yes', 'enable_global_robots' => '', 'enable_gmt' => 'yes', 'enable_exclude_posts_by_terms' => '', 'enable_image_sitemap' => '', 'input_image_post_types' => '', 'enable_news_sitemap' => '', 'enable_news_keywords' => '', 'enable_news_ping' => '', 'enable_news_multicat' => '', 'select_news_lang' => 'en', 'select_news_post_type' => 'post', 'select_news_taxonomy' => 'category', 'select_news_keyword_type' => 'cat', 'select_news_keyword_source' => '', 'select_news_cat_action' => 'inc', 'select_news_cats' => '', 'input_news_name' => '', 'input_news_age' => 2, 'input_news_genres' => array(), 'input_exclude_post_type' => '', 'input_exclude_post_type_ping' => '', 'input_exclude_taxonomy' => 'post_tag', 'input_cache_age' => 1, 'input_item_limit' => 5000, 'input_split_limit_post' => 0, 'input_alt_module_dir' => '', 'input_oldest' => 7, 'input_sql_limit' => 1000, 'input_custom_xslt' => '', 'input_ping_limit' => 100, 'select_output_type' => 'concise', 'select_time_type' => 3600, 'select_oldest_type' => 16400, 'select_default_freq' => 'daily', 'select_default_pri' => 1.0, 'select_min_pri' => 0.1, 'input_cache_dir' => ''); // super admin only options $this->site_options = array('enable_global_robots', 'enable_log', 'enable_debug', 'enable_debug_extra', 'enable_gzip', 'enable_cache', 'enable_cache_auto_gen', 'input_cache_age', 'input_alt_module_dir', 'input_sql_limit', 'input_cache_dir', 'select_time_type'); $this->add_option_key('BWP_GXS_GENERATOR', 'bwp_gxs_generator', $this->bridge->t('XML Sitemaps', $this->domain)); $this->add_option_key('BWP_GXS_EXTENSIONS', 'bwp_gxs_extensions', $this->bridge->t('Extensions', $this->domain)); // @since 1.4.0 backward compat for google news option key if (!defined('BWP_GXS_GOOGLE_NEWS')) { define('BWP_GXS_GOOGLE_NEWS', 'bwp_gxs_google_news'); } $this->add_extra_option_key('BWP_GXS_GENERATOR_ADVANCED', 'bwp_gxs_generator_advanced', $this->bridge->t('Advanced Options', $this->domain)); $this->add_option_key('BWP_GXS_STATS', 'bwp_gxs_stats', $this->bridge->t('Sitemap Log', $this->domain)); if (!defined('BWP_GXS_LOG')) { define('BWP_GXS_LOG', 'bwp_gxs_log'); define('BWP_GXS_PING', 'bwp_gxs_ping_data'); // @since 1.4.0 allow excluding posts/terms via admin page define('BWP_GXS_EXCLUDED_POSTS', 'bwp_gxs_excluded_posts'); define('BWP_GXS_EXCLUDED_TERMS', 'bwp_gxs_excluded_terms'); // @since 1.4.0 allow adding external pages via admin page define('BWP_GXS_EXTERNAL_PAGES', 'bwp_gxs_external_pages'); // @deprecated 1.4.0 use BWP_GXS_GENERATOR instead define('BWP_GXS_OPTION_GENERATOR', 'bwp_gxs_generator'); } $this->build_properties('BWP_GXS', $options, dirname(dirname(__FILE__)) . '/bwp-gxs.php', 'http://betterwp.net/wordpress-plugins/google-xml-sitemaps/', false); }
protected function is_form_item_hidden($name) { if (isset($this->form['env']) && array_key_exists($name, $this->form['env']) && $this->form['env'][$name] == 'multisite' && !BWP_Framework_V3::is_multisite()) { // hide multisite field if not in multisite environment return true; } if (isset($this->form['php']) && array_key_exists($name, $this->form['php']) && !BWP_Version::get_current_php_version_id($this->form['php'][$name])) { // hide field if the current PHP version requirement is not satisfied return true; } if (isset($this->form['role']) && array_key_exists($name, $this->form['role']) && $this->form['role'][$name] == 'superadmin' && (!BWP_Framework_V3::is_site_admin() || !BWP_Framework_V3::is_on_main_blog())) { // hide site-admin-only settings if not a site admin or not on // main blog return true; } /* if (isset($this->form['callback']) */ /* && array_key_exists($name, $this->form['callback']) */ /* && is_callable($this->form['callback'][$name]) */ /* && !call_user_func($this->form['callback'][$name], $name) */ /* ) { */ /* // a condition not satisfied, hide the field */ /* return true; */ /* } */ if (in_array($name, $this->site_options) && (!BWP_Framework_V3::is_site_admin() || !BWP_Framework_V3::is_on_main_blog())) { // hide site-admin-only settings if not a site admin or not on // main blog return true; } if (isset($this->form['blog']) && array_key_exists($name, $this->form['blog']) && BWP_Framework_V3::is_multisite()) { if ($this->form['blog'][$name] == 'main' && !BWP_Framework_V3::is_on_main_blog()) { // this field should be on main blog only return true; } elseif ($this->form['blog'][$name] == 'sub' && BWP_Framework_V3::is_on_main_blog()) { // this field should be on sub blogs only return true; } } return false; }
/** * Constructor */ public function __construct(array $meta, BWP_WP_Bridge $bridge = null) { parent::__construct($meta, $bridge); // basic version checking if (!$this->check_required_versions()) { return; } // default options $options = array('input_api_key' => '', 'input_update_time' => 12, 'select_time_type' => 3600, 'enable_ssl' => '', 'enable_auto_update' => 'yes', 'last_updated' => '', 'last_update_code' => '', 'input_usercode' => ''); $this->add_option_key('BWP_POLLDADDY_OPTION_GENERAL', 'bwp_polldaddy_general', __('Better WordPress Polldaddy Polls Settings', $this->domain)); if (!defined('BWP_POLLDADDY_POLLS')) { define('BWP_POLLDADDY_POLLS', 'bwp_polldaddy_polls'); } $this->build_properties('BWP_POLLDADDY', $options, dirname(dirname(__FILE__)) . '/bwp-polldaddy.php', 'http://betterwp.net/wordpress-plugins/bwp-polldaddy/', false); }