anylinkOptions = get_option( 'anylink_options' ); } public function addMenu() { $al_option_page = add_submenu_page( 'options-general.php', 'anyLink插件配置', 'anyLink配置', 'manage_options', 'anyLinkSetting', array( &$this, 'anyLinkSettingPage' ) ); add_action( 'admin_print_scripts-' . $al_option_page, array( &$this, 'anylinkAdminScripts' ) ); add_action( 'admin_print_styles-' . $al_option_page, array( &$this, 'anylinkAdminScripts' ) ); } //output scripts and styles public function anylinkAdminScripts() { wp_enqueue_script( 'anylink_script' ); wp_enqueue_style( 'anylink_style' ); } public function anyLinkSettingPage() { if( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); include_once( ANYLNK_PATH . '/al_setting.php' ); } public function alAdminInit() { //register a javascript and css files to output later wp_register_script( 'anylink_script', plugins_url( '/images/al_script.js', dirname( __FILE__ ) ) ); wp_register_style( 'anylink_style', plugins_url( '/images/al_style.css', dirname( __FILE__ ) ) ); register_setting( 'anylink_options_group', 'anylink_options', array( &$this, 'alCatValidate' ) ); add_settings_section( 'al_general_settings', '基本设置', array( &$this, 'alGeneralDisp' ), 'anyLinkSetting' ); add_settings_field( 'al_redirect_cat', '跳转目录名称', array( &$this, 'dispRedirectCat' ), 'anyLinkSetting', 'al_general_settings' ); add_settings_field( 'al_redirect_type', '链接跳转类型', array( &$this, 'dispRedirctType' ), 'anyLinkSetting', 'al_general_settings' ); add_settings_field( 'al_slug_num', '自动生产链接slug的长度', array( &$this, 'dispSlugNum' ), 'anyLinkSetting', 'al_general_settings' ); add_settings_field( 'al_slug_char', '自动生产链接slug的样式', array( &$this, 'dispSlugChar' ), 'anyLinkSetting', 'al_general_settings' ); add_settings_field( 'al_form_identify', '', array( &$this, 'hiddenFormIdentify' ), 'anyLinkSetting', 'al_general_settings' ); } public function alGeneralDisp() { echo ""; } public function dispRedirectCat() { $cat = $this -> anylinkOptions['redirectCat']; echo site_url() . "//ab12
请确保以字母开头,且仅含有字母、数字、下划线、连接符,最大长度不超过12个"; } public function dispRedirctType() { $type = ( int )$this -> anylinkOptions['redirectType']; //determine which radio button should be checked $checked301 = ' '; $checked307 = ' '; $checked200 = ' '; switch( $type ) { case 301: $checked301 = 'checked="checked"'; break; case 307: $checked307 = 'checked="checked"'; break; case 200; $checked200 = 'checked="checked"'; break; } $redirectType = ""; $redirectType .= "
"; $redirectType .= ""; $redirectType .= "
"; $redirectType .= ""; $redirectType .= "
"; echo $redirectType; } public function dispSlugNum() { $num = $this ->anylinkOptions['slugNum']; echo "
最小值为4,最大值为12"; } public function dispSlugChar() { $chars = $this -> anylinkOptions['slugChar']; $htmlChar = " anylinkOptions; $input = array_map( "trim", $input ); if( preg_match( '/^[a-z][a-z0-9_-]{0,11}/', $input['redirectCat'] ) ) $oldOptions['redirectCat'] = $input['redirectCat']; if( $input['redirectType'] == 301 || $input['redirectType'] == 307 || $input['redirectType'] == 200 ) $oldOptions['redirectType'] = $input['redirectType']; if( is_int( ( int )$input['slugNum'] ) && $input['slugNum'] < 13 && $input['slugNum'] > 3 ) $oldOptions['slugNum'] = $input['slugNum']; $oldOptions['slugChar'] = $input['slugChar']; return $oldOptions; } //out put a hidden field to identify the form public function hiddenFormIdentify() { $hiddenHtml = ""; echo $hiddenHtml; } //flush the rewrite rules public function flushRules() { $alOptions = get_option( 'anylink_options' ); if( $alOptions['redirectCat'] != $alOptions['oldCat'] ) { $cat = $alOptions['redirectCat']; add_rewrite_rule( "$cat/([0-9a-z]{4,})", 'index.php?' . $cat . '=$matches[1]', 'top' ); flush_rewrite_rules(); $alOptions['oldCat'] = $alOptions['redirectCat']; update_option( 'anylink_options', $alOptions ); } } } ?>