html = ""; } //register settings public function aplhabet_listing_register_settings() { register_setting( 'alphabet-listing-settings-group', 'alphabet-listing-settings', array( &$this, 'validate_settings') ); } //validate user input public function validate_settings( $settings ) { $settings['type'] = (preg_match('/^(post|page|category)$/i', $settings['type']) ? strtolower($settings['type']) : "post"); $settings['bg_color'] = (preg_match('/^#[a-f0-9]{6}$/i', $settings['bg_color']) ? $settings['bg_color'] : "#f0f0f0"); $settings['text_color'] = (preg_match('/^#[a-f0-9]{6}$/i', $settings['text_color']) ? $settings['text_color'] : "#424242"); $settings['alpha_bg_color'] = (preg_match('/^#[a-f0-9]{6}$/i', $settings['alpha_bg_color']) ? $settings['alpha_bg_color'] : "#000000"); return $settings; } // activating the default values public function aplhabet_listing_activate() { $new_options = array( 'title' => 'A to Z listing', 'type' => 'post', 'bg_color' => '#f0f0f0', 'text_color' => '#424242', 'alpha_bg_color' => '#000000' ); add_option('alphabet-listing-settings',$new_options); } public function alphabet_listing_create_menu() { add_menu_page( __('Alphabet Listing'), __('Alphabet Listing Settings'), 0, AL_DIRECTORY.'/alphabet_listing_settings.php', '', plugins_url('/images/icon.png', __FILE__) ); add_submenu_page( AL_DIRECTORY.'/alphabet_listing_settings.php', __("Alphabet Listing Settings"), __("Settings"), 0, AL_DIRECTORY.'/alphabet_listing_settings.php' ); add_submenu_page( AL_DIRECTORY.'/alphabet_listing_settings.php', __("Alphabet Listing Help"), __("Help"), 9, AL_DIRECTORY.'/help.php' ); } // deactivating public function aplhabet_listing_deactivate() { // needed for proper deletion of every option delete_option('alphabet-listing-settings'); } //To inject the css that is need for rendering alphabets public function inject_css() { wp_register_style( 'prefix-style', AL_URL . "css/alphabet_listing.css" ); wp_enqueue_style( 'prefix-style' ); } //To read post table and return all posts public function get_all_titles($type) { global $wpdb; //reset $sql = ""; $this->html = ""; switch ($type) { case 'post': $sql = "select id, post_title from $wpdb->posts where post_status = 'publish' AND post_type = 'post' ORDER BY post_title"; break; case 'page': $sql = "select id, post_title from $wpdb->posts where post_status = 'publish' AND post_type = 'page' ORDER BY post_title"; break; case 'category': $sql = "SELECT term_id as id, name as post_title FROM $wpdb->terms ORDER BY name"; break; } $this->result = $wpdb->get_results($sql, ARRAY_A ); } /* To generate A to Z html with links */ public function generateAtoZHtml() { $startCapital = 65; $startSmall = 97; $this->html .= "