/** * Validate the option * * @param array $dirty New value for the option * @param array $clean Clean value for the option, normally the defaults * @param array $old Old value of the option * * @todo remove code using $short, there is no "short form" anymore. * * @return array Validated clean value for the option to be saved to the database */ protected function validate_option($dirty, $clean, $old) { // Have we receive input from a short (license only) form ? $short = isset($dirty['short_form']) && $dirty['short_form'] === 'on' ? true : false; // Prepare an array of valid data types and taxonomies to validate against $valid_data_types = array_keys($this->valid_data_types); $valid_taxonomies = array(); $taxonomies = get_object_taxonomies('product', 'objects'); if (is_array($taxonomies) && $taxonomies !== array()) { foreach ($taxonomies as $tax) { $tax_name = strtolower($tax->name); $valid_data_types[] = $tax_name; $valid_taxonomies[] = $tax_name; } } unset($taxonomies, $tax, $tax_name); foreach ($clean as $key => $value) { switch ($key) { case 'dbversion': $clean[$key] = $this->db_version; break; case 'data1_type': case 'data2_type': if (isset($dirty[$key])) { if (in_array($dirty[$key], $valid_data_types, true)) { $clean[$key] = $dirty[$key]; } else { if (sanitize_title_with_dashes($dirty[$key]) === $dirty[$key]) { // Allow taxonomies which may not be registered yet $clean[$key] = $dirty[$key]; } } } else { if ($short && isset($old[$key])) { if (in_array($old[$key], $valid_data_types, true)) { $clean[$key] = $old[$key]; } else { if (sanitize_title_with_dashes($old[$key]) === $old[$key]) { // Allow taxonomies which may not be registered yet $clean[$key] = $old[$key]; } } } } break; case 'schema_brand': case 'schema_manufacturer': if (isset($dirty[$key])) { if (in_array($dirty[$key], $valid_taxonomies, true)) { $clean[$key] = $dirty[$key]; } else { if (sanitize_title_with_dashes($dirty[$key]) === $dirty[$key]) { // Allow taxonomies which may not be registered yet $clean[$key] = $dirty[$key]; } } } else { if ($short && isset($old[$key])) { if (in_array($old[$key], $valid_taxonomies, true)) { $clean[$key] = $old[$key]; } else { if (sanitize_title_with_dashes($old[$key]) === $old[$key]) { // Allow taxonomies which may not be registered yet $clean[$key] = $old[$key]; } } } } break; /* boolean (checkbox) field - may not be in form */ /* boolean (checkbox) field - may not be in form */ case 'breadcrumbs': case 'hide_columns': case 'metabox_woo_top': if (isset($dirty[$key])) { $clean[$key] = WPSEO_WooCommerce_Wrappers::validate_bool($dirty[$key]); } else { if ($short && isset($old[$key])) { $clean[$key] = WPSEO_WooCommerce_Wrappers::validate_bool($old[$key]); } else { $clean[$key] = false; } } break; } } return $clean; }
/** * Builds the admin page * * @since 1.0 */ function admin_panel() { WPSEO_WooCommerce_Wrappers::admin_header(true, $this->option_instance->group_name, $this->short_name, false); // @todo [JRF => whomever] change the form fields so they use the methods as defined in WPSEO_Admin_Pages $taxonomies = get_object_taxonomies('product', 'objects'); echo '<h2>' . __('Twitter Product Cards', 'yoast-woo-seo') . '</h2>'; echo '<p>' . __('Twitter allows you to display two pieces of data in the Twitter card, pick which two are shown:', 'yoast-woo-seo') . '</p>'; $i = 1; while ($i < 3) { echo ' <label class="select" for="datatype' . $i . '">' . sprintf(__('Data %d', 'yoast-woo-seo'), $i) . ':</label> <select class="select" id="datatype' . $i . '" name="' . esc_attr($this->short_name . '[data' . $i . '_type]') . '">' . "\n"; foreach ($this->option_instance->valid_data_types as $data_type => $translation) { $sel = selected($data_type, $this->options['data' . $i . '_type'], false); echo '<option value="' . esc_attr($data_type) . '"' . $sel . '>' . esc_html($translation) . "</option>\n"; } unset($sel, $data_type, $translation); if (is_array($taxonomies) && $taxonomies !== array()) { foreach ($taxonomies as $tax) { $sel = selected(strtolower($tax->name), $this->options['data' . $i . '_type'], false); echo '<option value="' . esc_attr(strtolower($tax->name)) . '"' . $sel . '>' . esc_html($tax->labels->name) . "</option>\n"; } unset($tax, $sel); } echo '</select>'; if ($i === 1) { echo '<br class="clear"/>'; } $i++; } echo '<br class="clear"/> <h2>' . __('Schema & OpenGraph additions', 'yoast-woo-seo') . '</h2> <p>' . __('If you have product attributes for the following types, select them here, the plugin will make sure they\'re used for the appropriate Schema.org and OpenGraph markup.', 'yoast-woo-seo') . '</p> <label class="select" for="schema_brand">' . sprintf(__('Brand', 'yoast-woo-seo'), $i) . ':</label> <select class="select" id="schema_brand" name="' . esc_attr($this->short_name . '[schema_brand]') . '"> <option value="">-</option>' . "\n"; if (is_array($taxonomies) && $taxonomies !== array()) { foreach ($taxonomies as $tax) { $sel = selected(strtolower($tax->name), $this->options['schema_brand'], false); echo '<option value="' . esc_attr(strtolower($tax->name)) . '"' . $sel . '>' . esc_html($tax->labels->name) . "</option>\n"; } } unset($tax, $sel); echo ' </select> <br class="clear"/> <label class="select" for="schema_manufacturer">' . sprintf(__('Manufacturer', 'yoast-woo-seo'), $i) . ':</label> <select class="select" id="schema_manufacturer" name="' . esc_attr($this->short_name . '[schema_manufacturer]') . '"> <option value="">-</option>' . "\n"; if (is_array($taxonomies) && $taxonomies !== array()) { foreach ($taxonomies as $tax) { $sel = selected(strtolower($tax->name), $this->options['schema_manufacturer'], false); echo '<option value="' . esc_attr(strtolower($tax->name)) . '"' . $sel . '>' . esc_html($tax->labels->name) . "</option>\n"; } } unset($tax, $sel); echo ' </select> <br class="clear"/>'; $wpseo_options = WPSEO_Options::get_all(); if ($wpseo_options['breadcrumbs-enable'] === true) { echo ' <h2>' . __('Breadcrumbs', 'yoast-woo-seo') . '</h2> <p>' . sprintf(__('Both WooCommerce and WordPress SEO by Yoast have breadcrumbs functionality. The WP SEO breadcrumbs have a slightly higher chance of being picked up by search engines and you can configure them a bit more, on the %1$sInternal Links settings page%2$s. To enable them, check the box below and the WooCommerce breadcrumbs will be replaced.', 'yoast-woo-seo'), '<a href="' . esc_url(admin_url('admin.php?page=wpseo_internal-links')) . '">', '</a>') . "</p>\n"; $this->checkbox('breadcrumbs', __('Replace WooCommerce Breadcrumbs', 'yoast-woo-seo')); } echo ' <br class="clear"/> <h2>' . __('Admin', 'yoast-woo-seo') . '</h2> <p>' . __('Both WooCommerce and WordPress SEO by Yoast add columns to the product page, to remove all but the SEO score column from Yoast on that page, check this box.', 'yoast-woo-seo') . "</p>\n"; $this->checkbox('hide_columns', __('Remove WordPress SEO columns', 'yoast-woo-seo')); echo ' <br class="clear"/> <p>' . __('Both WooCommerce and WordPress SEO by Yoast add metaboxes to the edit product page, if you want WooCommerce to be above WordPress SEO, check the box.', 'yoast-woo-seo') . "</p>\n"; $this->checkbox('metabox_woo_top', __('Move WooCommerce Up', 'yoast-woo-seo')); echo '<br class="clear"/>'; // Submit button and debug info WPSEO_WooCommerce_Wrappers::admin_footer(true, false); }