1, 'position' => 'bottom-right', 'credit_enabled' => 0, )); } public function menu() { add_options_page('e-iT Accessibility Tools', 'e-iT Accessibility', 'manage_options', 'eitacto-tools', array($this, 'settings_page')); } public function register_settings() { register_setting('eitacto_tools', self::OPTION, array( 'type' => 'array', 'sanitize_callback' => array($this, 'sanitize'), )); } public function sanitize($input) { if (!current_user_can('manage_options')) { return $this->options(); } $input = is_array($input) ? $input : array(); $position = isset($input['position']) ? sanitize_key($input['position']) : 'bottom-right'; return array( 'widget_enabled' => !empty($input['widget_enabled']) ? 1 : 0, 'position' => in_array($position, array('bottom-right', 'bottom-left', 'top-right', 'top-left'), true) ? $position : 'bottom-right', 'credit_enabled' => !empty($input['credit_enabled']) ? 1 : 0, ); } public function same_site_public_url($url) { if (!is_string($url) || !$url) { return false; } $parts = wp_parse_url($url); $home = wp_parse_url(home_url('/')); if (!is_array($parts) || !is_array($home) || !isset($parts['scheme'], $parts['host'], $home['scheme'], $home['host'])) { return false; } if (!in_array(strtolower($parts['scheme']), array('http', 'https'), true) || isset($parts['user']) || isset($parts['pass'])) { return false; } return strtolower($parts['scheme']) === strtolower($home['scheme']) && strtolower($parts['host']) === strtolower($home['host']) && (isset($parts['port']) ? (int) $parts['port'] : 0) === (isset($home['port']) ? (int) $home['port'] : 0); } public function public_urls() { $urls = array(home_url('/')); $truncated = false; $page_for_posts = (int) get_option('page_for_posts'); if ($page_for_posts) { $urls[] = get_permalink($page_for_posts); } foreach (get_post_types(array('public' => true), 'objects') as $type) { if ($type->name === 'attachment') { continue; } if ($type->has_archive) { $archive = get_post_type_archive_link($type->name); if ($archive) { $urls[] = $archive; } } $remaining = self::INVENTORY_LIMIT - count($urls); if ($remaining < 1) { $truncated = true; break; } $query = new WP_Query(array( 'post_type' => $type->name, 'post_status' => 'publish', 'has_password' => false, 'posts_per_page' => $remaining + 1, 'fields' => 'ids', 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, )); if (count($query->posts) > $remaining) { $truncated = true; } foreach (array_slice($query->posts, 0, $remaining) as $post_id) { $permalink = get_permalink($post_id); if ($permalink) { $urls[] = $permalink; } } } foreach (get_taxonomies(array('public' => true), 'names') as $taxonomy) { $remaining = self::INVENTORY_LIMIT - count($urls); if ($remaining < 1) { $truncated = true; break; } $terms = get_terms(array('taxonomy' => $taxonomy, 'hide_empty' => true, 'fields' => 'ids', 'number' => $remaining + 1)); if (is_wp_error($terms)) { continue; } if (count($terms) > $remaining) { $truncated = true; } foreach (array_slice($terms, 0, $remaining) as $term_id) { $term_url = get_term_link((int) $term_id, $taxonomy); if (!is_wp_error($term_url)) { $urls[] = $term_url; } } } $urls = array_filter(array_unique($urls), array($this, 'same_site_public_url')); sort($urls, SORT_STRING); return array('urls' => $urls, 'truncated' => $truncated); } public function settings_page($include_services = true) { if (!current_user_can('manage_options')) { return; } $options = $this->options(); $inventory = $include_services ? $this->public_urls() : array('urls' => array(), 'truncated' => false); $urls = $inventory['urls']; ?>
options(); if (!$options['widget_enabled']) { return; } $base = plugin_dir_url(__FILE__); wp_enqueue_style('eitacto-tools', $base . 'assets/accessibility.css', array(), self::VERSION); wp_enqueue_script('eitacto-tools', $base . 'assets/accessibility.js', array(), self::VERSION, true); do_action('eitacto_panel_assets'); } public function render_widget() { $options = $this->options(); if (!$options['widget_enabled']) { return; } $icon = plugin_dir_url(__FILE__) . 'assets/accessibility-icon.svg'; ?>