php - WordPress theme options - Implementing a code editor for Custom CSS -
i'm creating custom wordpress theme, , within theme options, i've been trying create area user write custom css.
i'm trying use ace editor in theme; editor works intended, fields aren't saving @ all.
here's code:
<h2>custom code</h2> <?php do_settings_fields('register_custom_code','custom_code_section'); settings_fields('cus_code_setting'); ?> </div> <div class="clear"></div> </div> <?php } add_action('admin_init','register_custom_code'); function register_custom_code() { register_setting( 'cus_code_setting', 'custom_css', 'custom_css_validation'); add_settings_section( 'custom_code_section', '', 'custom_code_settings_callback', 'register_custom_code' ); add_settings_field( 'custom_css', '', 'custom_css_callback', 'register_custom_code', 'custom_code_section' ); function custom_css_callback() { // default message appear $custom_css_default = __( '/* welcome custom css editor! please add custom css here , avoid modifying core theme files, since that\'ll make upgrading theme problematic. custom css loaded after theme\'s stylesheets, means rules take precedence. add css here want change, don\'t need copy theme\'s style.css content. */' ); $custom_css = get_option( 'custom_css', $custom_css_default ); ?> <div class="wrap"> <div id="icon-themes" class="icon32"></div> <h2><?php _e( 'custom css' ); ?></h2> <?php if ( ! empty( $_get['settings-updated'] ) ) echo '<div id="message" class="updated"><p><strong>' . __( 'custom css updated.' ) . '</strong></p></div>'; ?> <form id="custom_css_form" method="post" action="options.php" style="margin-top: 15px;"> <?php settings_fields( 'cus_code_setting' ); ?> <div id="custom_css_container"> <div name="custom_css" id="custom_css" style="border: 1px solid #dfdfdf; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; width: 100%; height: 200px; position: relative;"></div> </div> <textarea id="custom_css_textarea" name="custom_css" style="display: none;"><?php echo $custom_css; ?></textarea> <p><input type="submit" class="button-primary" value="<?php _e( 'save changes' ) ?>" /></p> </form> </div> <?php } function custom_code_settings_callback() {} } ?> i feel i'm messing on register_setting() / settings_field() methods used handle saving setting options, i'm not entirely sure.
i've followed this tutorial try , implement it.
Comments
Post a Comment