bulk-edit.php
3 years ago
col-sidebars.php
3 years ago
import.php
3 years ago
metabox.php
3 years ago
quick-edit.php
9 years ago
widgets-delete.php
3 years ago
widgets-editor.php
3 years ago
widgets-export.php
3 years ago
widgets-location.php
3 years ago
widgets.php
3 years ago
metabox.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Metabox inside posts/pages where user can define custom sidebars for an |
| 4 | * individual post. |
| 5 | * |
| 6 | * Uses: |
| 7 | * $selected |
| 8 | * $wp_registered_sidebars |
| 9 | * $post_id |
| 10 | */ |
| 11 | |
| 12 | $sidebars = CustomSidebars::get_options( 'modifiable' ); |
| 13 | |
| 14 | $is_front = get_option( 'page_on_front' ) == $post_id; |
| 15 | $is_blog = get_option( 'page_for_posts' ) == $post_id; |
| 16 | /** |
| 17 | * check is WooCommerce shop |
| 18 | */ |
| 19 | $is_woo_shop = intval( $post_id ) === ( function_exists( 'wc_get_page_id' )? intval( wc_get_page_id( 'shop' ) ) : 0 ); |
| 20 | /** |
| 21 | * local display helper |
| 22 | * |
| 23 | * @since 3.2.0 |
| 24 | * |
| 25 | * @param string $page_name Page Name to display. |
| 26 | * @param string $img Image to display. |
| 27 | * @param string $archive Archive name to display. |
| 28 | */ |
| 29 | if ( ! function_exists( 'custom_sidebars_replace_not_allowed' ) ) { |
| 30 | function custom_sidebars_replace_not_allowed( $page_name, $img, $archive = null ) { |
| 31 | echo '<p>'; |
| 32 | printf( |
| 33 | '<strong>%s</strong>', |
| 34 | sprintf( |
| 35 | esc_html__( 'To change the sidebar for %s', 'custom-sidebars' ), |
| 36 | esc_html( $page_name ) |
| 37 | ) |
| 38 | ); |
| 39 | echo '<ul>'; |
| 40 | printf( |
| 41 | '<li>%s</li>', |
| 42 | sprintf( |
| 43 | __( 'Go to the <a href="%1$s">Widgets page</a>', 'custom-sidebars' ), |
| 44 | admin_url( 'widgets.php' ) |
| 45 | ) |
| 46 | ); |
| 47 | printf( |
| 48 | '<li>%s</li>', |
| 49 | esc_html__( 'Click on "Sidebar Location"', 'custom-sidebars' ) |
| 50 | ); |
| 51 | printf( |
| 52 | '<li>%s</li>', |
| 53 | esc_html__( 'Open the "Archive-Types" tab', 'custom-sidebars' ) |
| 54 | ); |
| 55 | printf( |
| 56 | '<li>%s</li>', |
| 57 | sprintf( |
| 58 | esc_html__( 'Choose "%s"', 'custom-sidebars' ), |
| 59 | esc_html( empty( $archive )? $page_name : $archive ) |
| 60 | ) |
| 61 | ); |
| 62 | echo '</ul>'; |
| 63 | echo '</p>'; |
| 64 | $url = esc_url( CSB_IMG_URL . 'metabox/' . $img . '?version=3.2.4' ); |
| 65 | printf( |
| 66 | '<a href="%s" target="_blank"><img src="%s" style="width:100%%" /></a>', |
| 67 | esc_url( $url ), |
| 68 | esc_url( $url ) |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | /** |
| 73 | * show |
| 74 | */ |
| 75 | if ( $is_front ) { |
| 76 | $page_name = esc_html__( 'Front Page', 'custom-sidebars' ); |
| 77 | custom_sidebars_replace_not_allowed( $page_name, 'frontpage-info.png' ); |
| 78 | } elseif ( $is_blog ) { |
| 79 | $page_name = esc_html__( 'Blog Page', 'custom-sidebars' ); |
| 80 | $archive = esc_html__( 'Post Index', 'custom-sidebars' ); |
| 81 | custom_sidebars_replace_not_allowed( $page_name, 'blogpage-info.png', $archive ); |
| 82 | } elseif ( $is_woo_shop ) { |
| 83 | $page_name = esc_html__( 'WooCommerce Shop', 'custom-sidebars' ); |
| 84 | $post_type_object = get_post_type_object( 'product' ); |
| 85 | $archive = sprintf( esc_html__( '%s Archives', 'custom-sidebars' ), $post_type_object->label ); |
| 86 | custom_sidebars_replace_not_allowed( $page_name, 'wooshop-info.png', $archive ); |
| 87 | } else { |
| 88 | echo '<p>'; |
| 89 | esc_html_e( 'Here you can replace the default sidebars. Simply select what sidebar you want to show for this post!', 'custom-sidebars' ); |
| 90 | echo '</p>'; |
| 91 | if ( ! empty( $sidebars ) ) { |
| 92 | global $wp_registered_sidebars; |
| 93 | $available = CustomSidebars::sort_sidebars_by_name( $wp_registered_sidebars ); |
| 94 | foreach ( $sidebars as $s ) { ?> |
| 95 | <?php $sb_name = $available[ $s ]['name']; ?> |
| 96 | <p> |
| 97 | <label for="cs_replacement_<?php echo esc_attr( $s ); ?>"> |
| 98 | <b><?php echo esc_html( $sb_name ); ?></b>: |
| 99 | </label> |
| 100 | <select name="cs_replacement_<?php echo esc_attr( $s ); ?>" |
| 101 | id="cs_replacement_<?php echo esc_attr( $s ); ?>" |
| 102 | class="cs-replacement-field <?php echo esc_attr( $s ); ?>"> |
| 103 | <option value=""></option> |
| 104 | <?php foreach ( $available as $a ) { ?> |
| 105 | <option value="<?php echo esc_attr( $a['id'] ); ?>" <?php selected( $selected[ $s ], $a['id'] ); ?>> |
| 106 | <?php echo esc_html( $a['name'] ); ?> |
| 107 | </option> |
| 108 | <?php } ?> |
| 109 | </select> |
| 110 | </p> |
| 111 | <?php |
| 112 | } |
| 113 | } else { |
| 114 | echo '<p id="message" class="updated">'; |
| 115 | printf( |
| 116 | __( 'All sidebars have been locked, you cannot replace them. Go to <a href="%s">the widgets page</a> to unlock a sidebar.', 'custom-sidebars' ), |
| 117 | admin_url( 'widgets.php' ) |
| 118 | ); |
| 119 | echo '</p>'; |
| 120 | } |
| 121 | } |
| 122 |