Skip to content

Commit

Permalink
Fix style selector; HTML structure & link failure when no sheet selected
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Jan 14, 2025
1 parent df3f303 commit 6885e48
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/my-calendar-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,17 @@ function mc_stylesheet_selector() {
<form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=my-calendar-design' ) ); ?>">
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'my-calendar-nonce' ) ); ?>"/>
<input type="hidden" value="true" name="mc_choose_style"/>
<div>
<p>
<label for="mc_css_file"><?php esc_html_e( 'Select Theme (optional)', 'my-calendar' ); ?></label><br />
<select name="mc_css_file" id="mc_css_file"><option value=""><?php esc_html_e( 'None', 'my-calendar' ); ?></option>
<?php
$custom_directory = str_replace( '/my-calendar/', '', $dir ) . '/my-calendar-custom/styles/';
$directory = __DIR__ . '/styles/';
$files = mc_css_list( $custom_directory );
if ( ! empty( $files ) ) {
?>
<optgroup label="<?php esc_html_e( 'Your Custom Stylesheets', 'my-calendar' ); ?>">
<optgroup label="<?php esc_html_e( 'Your Custom Stylesheets', 'my-calendar' ); ?>">
<?php
foreach ( $files as $value ) {
$test = 'mc_custom_' . $value;
Expand All @@ -291,17 +295,17 @@ function mc_stylesheet_selector() {
if ( 'css' === $path['extension'] ) {
$selected = ( mc_get_option( 'css_file' ) === $test ) ? true : false;
?>
<option value='mc_custom_<?php echo esc_attr( $value ); ?>'<?php selected( true, $selected ); ?>><?php echo esc_html( $value ); ?></option>
<option value='mc_custom_<?php echo esc_attr( $value ); ?>'<?php selected( true, $selected ); ?>><?php echo esc_html( $value ); ?></option>
<?php
}
}
?>
</optgroup>
</optgroup>
<?php
}
$files = mc_css_list( $directory );
?>
<optgroup label="<?php esc_html_e( 'Installed Stylesheets', 'my-calendar' ); ?>">
<optgroup label="<?php esc_html_e( 'Installed Stylesheets', 'my-calendar' ); ?>">
<?php
$current = mc_get_option( 'css_file' );
foreach ( $files as $value ) {
Expand All @@ -310,17 +314,12 @@ function mc_stylesheet_selector() {
if ( isset( $path['extension'] ) && 'css' === $path['extension'] ) {
$selected = ( $current === $value ) ? true : false;
?>
<option value='<?php echo esc_attr( $value ); ?>'<?php selected( true, $selected ); ?>><?php echo esc_html( $value ); ?></option>
<option value='<?php echo esc_attr( $value ); ?>'<?php selected( true, $selected ); ?>><?php echo esc_html( $value ); ?></option>
<?php
}
}
?>
</optgroup>
<div>
<p>
<label for="mc_css_file"><?php esc_html_e( 'Select Theme (optional)', 'my-calendar' ); ?></label><br />
<select name="mc_css_file" id="mc_css_file"><option value=""><?php esc_html_e( 'None', 'my-calendar' ); ?></option>
<?php echo wp_kses_post( $options ); ?>
</optgroup>
</select>
</p>
<p>
Expand All @@ -329,9 +328,10 @@ function mc_stylesheet_selector() {
</div>
</form>
<?php
$link = add_query_arg( 'mcpreview', mc_get_option( 'css_file' ), mc_get_uri() );
$file = ( mc_get_option( 'css_file' ) ) ? mc_get_option( 'css_file' ) : 'none';
$link = add_query_arg( 'mcpreview', $file, mc_get_uri() );
?>
<a href="<?php echo esc_url( $link ); ?>" class="preview-link" data-css="<?php echo esc_attr( mc_get_option( 'css_file' ) ); ?>"><?php esc_html_e( 'Preview Stylesheet', 'my-calendar' ); ?></a>
<a href="<?php echo esc_url( $link ); ?>" class="preview-link" data-css="<?php echo esc_attr( $file ); ?>"><?php esc_html_e( 'Preview Stylesheet', 'my-calendar' ); ?></a>
</div>
<?php
}
Expand Down

0 comments on commit 6885e48

Please sign in to comment.