Changeset 1417567
- Timestamp:
- 05/16/2016 12:11:22 AM (10 years ago)
- Location:
- dynamically-dynamic-sidebar
- Files:
-
- 1 added
- 4 edited
- 9 copied
-
tags/0.4 (added)
-
tags/0.4/admin-main.php (copied) (copied from dynamically-dynamic-sidebar/trunk/inc/admin-main.php)
-
tags/0.4/admin-post.php (copied) (copied from dynamically-dynamic-sidebar/trunk/inc/admin-post.php) (2 diffs)
-
tags/0.4/admin-term.php (copied) (copied from dynamically-dynamic-sidebar/trunk/inc/admin-term.php)
-
tags/0.4/dynamically-dynamic-sidebar.php (copied) (copied from dynamically-dynamic-sidebar/trunk/dynamically-dynamic-sidebar.php) (2 diffs)
-
tags/0.4/functions.php (copied) (copied from dynamically-dynamic-sidebar/trunk/inc/functions.php)
-
tags/0.4/inc (copied) (copied from dynamically-dynamic-sidebar/trunk/inc)
-
tags/0.4/inc/admin-post.php (modified) (2 diffs)
-
tags/0.4/readme-ja.md (copied) (copied from dynamically-dynamic-sidebar/trunk/readme-ja.md)
-
tags/0.4/readme.md (copied) (copied from dynamically-dynamic-sidebar/trunk/readme.md)
-
tags/0.4/readme.txt (copied) (copied from dynamically-dynamic-sidebar/trunk/readme.txt) (2 diffs)
-
trunk/dynamically-dynamic-sidebar.php (modified) (2 diffs)
-
trunk/inc/admin-post.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dynamically-dynamic-sidebar/tags/0.4/admin-post.php
r1417566 r1417567 92 92 } 93 93 94 if ( empty( $_POST['dds_widget_area'] ) ) {94 if ( !isset( $_POST['dds_widget_area'] ) ) { 95 95 return; 96 96 } … … 133 133 $format = '<strong>%1$s</strong><br>(from %2$s of %3$s )'; 134 134 printf( 135 $format,136 esc_html( $widget_by_term["area-name"] ),137 esc_html( $widget_by_term["term"]->name ),138 esc_html( $widget_by_term["term"]->taxonomy )135 $format, 136 esc_html( $widget_by_term["area-name"] ), 137 esc_html( $widget_by_term["term"]->name ), 138 esc_html( $widget_by_term["term"]->taxonomy ) 139 139 ); 140 140 -
dynamically-dynamic-sidebar/tags/0.4/dynamically-dynamic-sidebar.php
r1417566 r1417567 2 2 /* 3 3 Plugin Name: Dynamically Dynamic Sidebar 4 Version: 0. 24 Version: 0.4 5 5 Description: This plugin enables you to create unlimited widget area and use them for posts, pages, categories, tags and so on. 6 6 Author: Shinichi Nishikawa … … 10 10 */ 11 11 12 require 'inc/admin-main.php';13 require 'inc/admin-post.php';14 require 'inc/admin-term.php';15 require 'inc/functions.php';16 12 17 add_action( 'widgets_init', 'dds_widgets_init' ); 18 function dds_widgets_init() { 13 $dds_wp_version = $GLOBALS['wp_version']; 19 14 20 $dds_sidebars = get_option( 'dds_sidebars' ); 21 if( $dds_sidebars && is_array( $dds_sidebars ) ){ 22 foreach ( $dds_sidebars as $key => $val ) { 23 register_sidebar( 24 array( 25 'name' => $val, 26 'id' => $key, 27 ) 28 ); 29 } 30 } 15 if ( version_compare( (float)$dds_wp_version, '4.4', '<' ) ) { 16 add_action( 'admin_notices', 'dds_admin_error_notice' ); 17 return false; 18 } else { 19 20 define( 'DDS_PATH', plugin_dir_path( __FILE__ ) ); 21 22 require DDS_PATH . 'inc/main.php'; 23 require DDS_PATH . 'inc/admin-main.php'; 24 require DDS_PATH . 'inc/admin-post.php'; 25 require DDS_PATH . 'inc/admin-term.php'; 26 require DDS_PATH . 'inc/functions.php'; 31 27 32 28 } 33 29 34 add_filter( 'is_active_sidebar', 'dds_switch_sidebar', 10, 2 ); 35 function dds_switch_sidebar( $is_active_sidebar, $index ) { 36 37 // 投稿やタームで指定されたウィジェットエリアを取得 38 $switch = dds_get_desired_widget_area(); 39 40 if ( false == $switch ) { 41 return $is_active_sidebar; 42 } 43 44 // スイッチングされるべきウィジェットエリアを取得 45 $dds_target = get_option( 'dds_target_widget_area' ); 46 47 if ( ! $dds_target ) { 48 return $is_active_sidebar; 49 } 50 51 // 今 is_active_sidebar されているものが、ターゲットの場合にだけ実行 52 if ( $dds_target === $index ) { 53 54 // ウィジェットエリアの表示用のパラメータを元のところから持ってきて、 55 // ユーザーが定義したウィジェットエリアにセットする 56 global $wp_registered_sidebars; 57 if ( isset( $wp_registered_sidebars[$index] ) ) { 58 $original_params = $wp_registered_sidebars[$index]; // この中にテーマなどで定義されたウィジェット周辺のHTML情報が入っている 59 } else { 60 // テーマを切り替えるなどして、ターゲットに指定されていたウィジェットエリアのIDがなくなることがある 61 // その場合は何もしない 62 return $is_active_sidebar; 63 } 64 65 $params = array( 66 'before_widget', 67 'after_widget', 68 'before_title', 69 'after_title', 70 ); 71 foreach ( $params as $p ) { 72 // 管理画面で作られたウィジェットエリアにもそれを入れちゃう 73 $wp_registered_sidebars[$switch][$p] = $original_params[$p]; 74 } 75 76 // 止めちゃう 77 $is_active_sidebar = false; 78 79 // output the dynamic one. 80 do_action( 'dynamically_dynamic_sidebar' ); 81 82 } 83 84 return $is_active_sidebar; 85 30 function dds_admin_error_notice() { 31 ?><div class="error"><p><?php _e( '"Dynamically Dynamic Sidebar" plugin utilizes Term Meta API which was introduced in WordPress version 4.4. You need to upgrade your WordPress to activate the plugin.', 'dynamically-dynamic-sidebar' ); ?></p></div><?php 86 32 } 87 88 // 出力!89 add_action( 'dynamically_dynamic_sidebar', 'dynamically_dynamic_sidebar' );90 function dynamically_dynamic_sidebar() {91 92 // 投稿やタームで指定されたウィジェットエリアを取得93 $switch = dds_get_desired_widget_area();94 95 if ( false == $switch ) {96 return;97 }98 99 // ユーザーが作ったやつのリスト100 $registered = get_option( 'dds_sidebars' );101 102 // ユーザー作ったやつが存在すればいよいよ実行103 if ( array_key_exists( $switch, $registered ) ) {104 105 // is_active_sidebar が無限ループしてしまうのを防いだ106 remove_filter( 'is_active_sidebar', 'dds_switch_sidebar' );107 108 // 中身があれば出力。無ければ何もしない109 if ( is_active_sidebar( $switch ) ) {110 dynamic_sidebar( $switch );111 }112 113 // 外したのをもう一度入れておく114 add_filter( 'is_active_sidebar', 'dds_switch_sidebar', 10, 2 );115 116 } else {117 118 // ユーザーが投稿やタームで指定したウィジェットエリアが何かの拍子に消えてしまっていたらデフォルト119 dynamic_sidebar( 1 );120 }121 122 }123 124 // return widget area id (ie, sidebar-custom)125 function dds_get_desired_widget_area() {126 127 $widget_area = false;128 129 if ( is_singular() ) {130 131 global $post;132 $widget_area = get_post_meta( $post->ID, 'dds_widget_area', true );133 if ( $widget_area ) {134 return $widget_area;135 }136 137 $by_term = dds_get_widget_of_post_by_term( $post );138 if ( $by_term ) {139 return $by_term["area-id"];140 }141 142 143 } elseif ( is_category() || is_tag() || is_tax() ) {144 145 // ページ表示に使われたタクソノミのオブジェクト146 $queried_obj = get_queried_object();147 148 // のid149 $term_id = $queried_obj->term_id;150 151 // に割当はあるか?152 $widget_area = get_term_meta( $term_id, 'dds_widget_area', true );153 154 // あればいいんだけど、155 if ( $widget_area ) {156 return $widget_area;157 }158 159 // ない場合には親をチェックせねば。160 $ancestors = get_ancestors( $term_id, $queried_obj->taxonomy );161 if ( is_array( $ancestors ) ) {162 $widget_area_arr = dds_check_term_arrays_allocated_area( $ancestors );163 $widget_area = $widget_area_arr["area-id"];164 return $widget_area;165 }166 167 }168 169 return false;170 171 } -
dynamically-dynamic-sidebar/tags/0.4/inc/admin-post.php
r1287029 r1417567 92 92 } 93 93 94 if ( empty( $_POST['dds_widget_area'] ) ) {94 if ( !isset( $_POST['dds_widget_area'] ) ) { 95 95 return; 96 96 } … … 133 133 $format = '<strong>%1$s</strong><br>(from %2$s of %3$s )'; 134 134 printf( 135 $format,136 esc_html( $widget_by_term["area-name"] ),137 esc_html( $widget_by_term["term"]->name ),138 esc_html( $widget_by_term["term"]->taxonomy )135 $format, 136 esc_html( $widget_by_term["area-name"] ), 137 esc_html( $widget_by_term["term"]->name ), 138 esc_html( $widget_by_term["term"]->taxonomy ) 139 139 ); 140 140 -
dynamically-dynamic-sidebar/tags/0.4/readme.txt
r1417566 r1417567 3 3 Tags: widget, widget area, sidebar 4 4 Requires at least: 4.4 5 Tested up to: 3.46 Stable tag: 0. 25 Tested up to: 4.5.2 6 Stable tag: 0.4 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 77 77 = 0.1 = 78 78 * Released on github 79 80 = 0.3 = 81 * Get terms ancestors' allocated widget area for posts. 82 83 = 0.4 = 84 * 2016/05/16 85 * Bug fix. Now you can reset the dynamically chosen sidebar to default. 86 -
dynamically-dynamic-sidebar/trunk/dynamically-dynamic-sidebar.php
r1287055 r1417567 2 2 /* 3 3 Plugin Name: Dynamically Dynamic Sidebar 4 Version: 0. 24 Version: 0.4 5 5 Description: This plugin enables you to create unlimited widget area and use them for posts, pages, categories, tags and so on. 6 6 Author: Shinichi Nishikawa … … 10 10 */ 11 11 12 require 'inc/admin-main.php';13 require 'inc/admin-post.php';14 require 'inc/admin-term.php';15 require 'inc/functions.php';16 12 17 add_action( 'widgets_init', 'dds_widgets_init' ); 18 function dds_widgets_init() { 13 $dds_wp_version = $GLOBALS['wp_version']; 19 14 20 $dds_sidebars = get_option( 'dds_sidebars' ); 21 if( $dds_sidebars && is_array( $dds_sidebars ) ){ 22 foreach ( $dds_sidebars as $key => $val ) { 23 register_sidebar( 24 array( 25 'name' => $val, 26 'id' => $key, 27 ) 28 ); 29 } 30 } 15 if ( version_compare( (float)$dds_wp_version, '4.4', '<' ) ) { 16 add_action( 'admin_notices', 'dds_admin_error_notice' ); 17 return false; 18 } else { 19 20 define( 'DDS_PATH', plugin_dir_path( __FILE__ ) ); 21 22 require DDS_PATH . 'inc/main.php'; 23 require DDS_PATH . 'inc/admin-main.php'; 24 require DDS_PATH . 'inc/admin-post.php'; 25 require DDS_PATH . 'inc/admin-term.php'; 26 require DDS_PATH . 'inc/functions.php'; 31 27 32 28 } 33 29 34 add_filter( 'is_active_sidebar', 'dds_switch_sidebar', 10, 2 ); 35 function dds_switch_sidebar( $is_active_sidebar, $index ) { 36 37 // 投稿やタームで指定されたウィジェットエリアを取得 38 $switch = dds_get_desired_widget_area(); 39 40 if ( false == $switch ) { 41 return $is_active_sidebar; 42 } 43 44 // スイッチングされるべきウィジェットエリアを取得 45 $dds_target = get_option( 'dds_target_widget_area' ); 46 47 if ( ! $dds_target ) { 48 return $is_active_sidebar; 49 } 50 51 // 今 is_active_sidebar されているものが、ターゲットの場合にだけ実行 52 if ( $dds_target === $index ) { 53 54 // ウィジェットエリアの表示用のパラメータを元のところから持ってきて、 55 // ユーザーが定義したウィジェットエリアにセットする 56 global $wp_registered_sidebars; 57 if ( isset( $wp_registered_sidebars[$index] ) ) { 58 $original_params = $wp_registered_sidebars[$index]; // この中にテーマなどで定義されたウィジェット周辺のHTML情報が入っている 59 } else { 60 // テーマを切り替えるなどして、ターゲットに指定されていたウィジェットエリアのIDがなくなることがある 61 // その場合は何もしない 62 return $is_active_sidebar; 63 } 64 65 $params = array( 66 'before_widget', 67 'after_widget', 68 'before_title', 69 'after_title', 70 ); 71 foreach ( $params as $p ) { 72 // 管理画面で作られたウィジェットエリアにもそれを入れちゃう 73 $wp_registered_sidebars[$switch][$p] = $original_params[$p]; 74 } 75 76 // 止めちゃう 77 $is_active_sidebar = false; 78 79 // output the dynamic one. 80 do_action( 'dynamically_dynamic_sidebar' ); 81 82 } 83 84 return $is_active_sidebar; 85 30 function dds_admin_error_notice() { 31 ?><div class="error"><p><?php _e( '"Dynamically Dynamic Sidebar" plugin utilizes Term Meta API which was introduced in WordPress version 4.4. You need to upgrade your WordPress to activate the plugin.', 'dynamically-dynamic-sidebar' ); ?></p></div><?php 86 32 } 87 88 // 出力!89 add_action( 'dynamically_dynamic_sidebar', 'dynamically_dynamic_sidebar' );90 function dynamically_dynamic_sidebar() {91 92 // 投稿やタームで指定されたウィジェットエリアを取得93 $switch = dds_get_desired_widget_area();94 95 if ( false == $switch ) {96 return;97 }98 99 // ユーザーが作ったやつのリスト100 $registered = get_option( 'dds_sidebars' );101 102 // ユーザー作ったやつが存在すればいよいよ実行103 if ( array_key_exists( $switch, $registered ) ) {104 105 // is_active_sidebar が無限ループしてしまうのを防いだ106 remove_filter( 'is_active_sidebar', 'dds_switch_sidebar' );107 108 // 中身があれば出力。無ければ何もしない109 if ( is_active_sidebar( $switch ) ) {110 dynamic_sidebar( $switch );111 }112 113 // 外したのをもう一度入れておく114 add_filter( 'is_active_sidebar', 'dds_switch_sidebar', 10, 2 );115 116 } else {117 118 // ユーザーが投稿やタームで指定したウィジェットエリアが何かの拍子に消えてしまっていたらデフォルト119 dynamic_sidebar( 1 );120 }121 122 }123 124 // return widget area id (ie, sidebar-custom)125 function dds_get_desired_widget_area() {126 127 $widget_area = false;128 129 if ( is_singular() ) {130 131 global $post;132 $widget_area = get_post_meta( $post->ID, 'dds_widget_area', true );133 if ( $widget_area ) {134 return $widget_area;135 }136 137 $by_term = dds_get_widget_of_post_by_term( $post );138 if ( $by_term ) {139 return $by_term["area-id"];140 }141 142 143 } elseif ( is_category() || is_tag() || is_tax() ) {144 145 // ページ表示に使われたタクソノミのオブジェクト146 $queried_obj = get_queried_object();147 148 // のid149 $term_id = $queried_obj->term_id;150 151 // に割当はあるか?152 $widget_area = get_term_meta( $term_id, 'dds_widget_area', true );153 154 // あればいいんだけど、155 if ( $widget_area ) {156 return $widget_area;157 }158 159 // ない場合には親をチェックせねば。160 $ancestors = get_ancestors( $term_id, $queried_obj->taxonomy );161 if ( is_array( $ancestors ) ) {162 $widget_area_arr = dds_check_term_arrays_allocated_area( $ancestors );163 $widget_area = $widget_area_arr["area-id"];164 return $widget_area;165 }166 167 }168 169 return false;170 171 } -
dynamically-dynamic-sidebar/trunk/inc/admin-post.php
r1287029 r1417567 92 92 } 93 93 94 if ( empty( $_POST['dds_widget_area'] ) ) {94 if ( !isset( $_POST['dds_widget_area'] ) ) { 95 95 return; 96 96 } … … 133 133 $format = '<strong>%1$s</strong><br>(from %2$s of %3$s )'; 134 134 printf( 135 $format,136 esc_html( $widget_by_term["area-name"] ),137 esc_html( $widget_by_term["term"]->name ),138 esc_html( $widget_by_term["term"]->taxonomy )135 $format, 136 esc_html( $widget_by_term["area-name"] ), 137 esc_html( $widget_by_term["term"]->name ), 138 esc_html( $widget_by_term["term"]->taxonomy ) 139 139 ); 140 140 -
dynamically-dynamic-sidebar/trunk/readme.txt
r1287059 r1417567 3 3 Tags: widget, widget area, sidebar 4 4 Requires at least: 4.4 5 Tested up to: 3.46 Stable tag: 0. 25 Tested up to: 4.5.2 6 Stable tag: 0.4 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 77 77 = 0.1 = 78 78 * Released on github 79 80 = 0.3 = 81 * Get terms ancestors' allocated widget area for posts. 82 83 = 0.4 = 84 * 2016/05/16 85 * Bug fix. Now you can reset the dynamically chosen sidebar to default. 86
Note: See TracChangeset
for help on using the changeset viewer.