Changeset 1345038
- Timestamp:
- 02/07/2016 07:59:01 AM (10 years ago)
- Location:
- add-page-from-template/trunk
- Files:
-
- 9 added
- 2 edited
-
bin (added)
-
bin/install-wp-tests.sh (added)
-
includes/class-loader.php (modified) (3 diffs)
-
includes/class-option.php (modified) (22 diffs)
-
phpunit.xml (added)
-
tests (added)
-
tests/bootstrap.php (added)
-
tests/pages (added)
-
tests/pages/page-hoge.php (added)
-
tests/test-loader.php (added)
-
tests/test-sample.php (added)
Legend:
- Unmodified
- Added
- Removed
-
add-page-from-template/trunk/includes/class-loader.php
r1323830 r1345038 97 97 } 98 98 99 /** Absorb shocks of version difference. 99 /** 100 * Absorb shocks of version difference. 100 101 * @see https://core.trac.wordpress.org/browser/tags/4.1/src/wp-admin/includes/post.php#L533 101 102 */ … … 113 114 * 114 115 * thanks! the master of rewrite_rules! 115 * https://github.com/yousan/add-page-from-template/issues/1#event-456557115116 * @link https://github.com/yousan/add-page-from-template/issues/1#event-456557115 116 117 */ 117 118 private function register_update_rewrite_rules() { … … 127 128 add_rewrite_endpoint($template->getTemplateSlug(), EP_ROOT); 128 129 } 130 flush_rewrite_rules(); 129 131 } 130 132 -
add-page-from-template/trunk/includes/class-option.php
r1323814 r1345038 1 1 <?php 2 2 3 /** 3 4 * Created by PhpStorm. … … 16 17 17 18 18 public static function getDefaults() { 19 public static function getDefaults() 20 { 19 21 return array( 20 ' is_aggressive' => false,22 'aggressive' => false, 21 23 'base_dir' => 'pages/', 22 24 ); … … 30 32 AddPageFromTemplate::loadTextDomain(); 31 33 32 add_action( 'admin_menu', array( $this, 'add_plugin_page' ));33 add_action( 'admin_init', array( $this, 'page_init' ));34 add_action('admin_menu', array($this, 'add_plugin_page')); 35 add_action('admin_init', array($this, 'page_init')); 34 36 } 35 37 … … 39 41 * @return null 40 42 */ 41 static public function get_($varname) { 42 $options = get_option( self::APFT_OPTION_NAME ); 43 static public function get_($varname) 44 { 45 $options = get_option(self::APFT_OPTION_NAME); 43 46 if (isset($options[$varname])) { 44 47 return $options[$varname]; … … 60 63 'manage_options', 61 64 'apft-setting-admin', 62 array( $this, 'create_admin_page')65 array($this, 'create_admin_page') 63 66 ); 64 67 } … … 70 73 { 71 74 // Set class property 72 $this->options = get_option( self::APFT_OPTION_NAME);75 $this->options = get_option(self::APFT_OPTION_NAME); 73 76 ?> 74 77 <div class="wrap"> 75 <?php //screen_icon(); ?> 76 <h2><?php _e('Add Page From Template (APFT)', 'apft')?></h2> 78 <?php //screen_icon(); 79 ?> 80 <h2><?php _e('Add Page From Template (APFT)', 'apft') ?></h2> 77 81 <form method="post" action="options.php"> 78 82 <?php 79 83 // This prints out all hidden setting fields 80 settings_fields( 'apft_option_group');81 do_settings_sections( 'apft-setting-admin');84 settings_fields('apft_option_group'); 85 do_settings_sections('apft-setting-admin'); 82 86 submit_button(); 83 87 ?> … … 95 99 'apft_option_group', // Option group 96 100 self::APFT_OPTION_NAME, // Option name 97 array( $this, 'sanitize') // Sanitize101 array($this, 'sanitize') // Sanitize 98 102 ); 99 103 … … 101 105 'setting_apft', // ID 102 106 __('APFT Custom Settings', 'apft'), // Title 103 array( $this, 'print_section_info'), // Callback107 array($this, 'print_section_info'), // Callback 104 108 'apft-setting-admin' // Page 105 109 ); … … 108 112 'is_aggressive', // ID 109 113 __("'Aggressive' flush_rewrite", 'apft'), // Title 110 array( $this, 'is_aggressive_callback'), // Callback114 array($this, 'is_aggressive_callback'), // Callback 111 115 'apft-setting-admin', // Page 112 116 'setting_apft' // Section … … 116 120 'base_dir', 117 121 __('Base Directory', 'apft'), 118 array( $this, 'base_dir_callback'),122 array($this, 'base_dir_callback'), 119 123 'apft-setting-admin', 120 124 'setting_apft' … … 124 128 'template_files', 125 129 __('Template Files', 'apft'), 126 array( $this, 'template_files_callback'),130 array($this, 'template_files_callback'), 127 131 'apft-setting-admin', 128 132 'setting_apft' … … 136 140 * @return array 137 141 */ 138 public function sanitize( $input)142 public function sanitize($input) 139 143 { 140 144 $new_input = array(); 141 if ( isset( $input['aggressive'] )) {145 if (isset($input['aggressive'])) { 142 146 $new_input['aggressive'] = $input['aggressive']; 143 147 } else { … … 145 149 } 146 150 147 if ( isset( $input['title'] ))148 $new_input['title'] = sanitize_text_field( $input['title']);151 if (isset($input['title'])) 152 $new_input['title'] = sanitize_text_field($input['title']); 149 153 150 154 return $new_input; … … 164 168 public function is_aggressive_callback() 165 169 { 166 if ( isset($this->options['aggressive']) && false == $this->options['aggressive']) {170 if (isset($this->options['aggressive']) && false == $this->options['aggressive']) { 167 171 $checked = ''; 168 172 } else { … … 181 185 * ベースディレクトリの設定部分 182 186 */ 183 public function base_dir_callback() { 184 if (isset( $this->options['base_dir'] )) { 185 $base_dir = esc_attr( $this->options['base_dir']); 186 } else { 187 public function base_dir_callback() 188 { 189 if (isset($this->options['base_dir'])) { 190 $base_dir = esc_attr($this->options['base_dir']); 191 } else { 187 192 $base_dir = 'pages/'; 188 193 } … … 199 204 * @see _get_page_link() 200 205 */ 201 private function getPageLink($slug){ 206 private function getPageLink($slug) 207 { 202 208 global $wp_rewrite; 203 209 $link = $wp_rewrite->get_page_permastruct(); … … 206 212 $link = home_url($link); 207 213 $link = user_trailingslashit($link, 'page'); 208 return apply_filters( '_get_page_link', $link, 0);214 return apply_filters('_get_page_link', $link, 0); 209 215 } 210 216 … … 212 218 * テンプレートファイル一覧の設定部分 213 219 */ 214 public function template_files_callback() { 220 public function template_files_callback() 221 { 215 222 $templates = AP_TemplateSearcher::getTemplates(); 216 223 ?> 217 224 <table class="widefat" id="apft-templates"> 218 <thead><tr class="head" style="cursor: move;"> 225 <thead> 226 <tr class="head" style="cursor: move;"> 219 227 <th scope="col"><?php _e('Template Name', 'apft'); ?></th> 220 228 <th scope="col"><?php _e('Status', 'apft'); ?></th> … … 226 234 <tr class="nodrag nodrop"> 227 235 <td><?php echo $template->slug; ?></td> 228 <td class="apft-status-<?php echo $template->status; ?>">236 <td class="apft-status-<?php echo $template->status; ?>"> 229 237 <?php _e(ucfirst($template->status), 'apft'); ?> 230 238 </td> … … 233 241 // ファイルパス テーマディレクトリから下 URLエンコードが必要 234 242 // ex) pages%2Fpage-fuga.php 235 $filepath = urlencode(str_replace( get_stylesheet_directory().'/', '', $template->path));243 $filepath = urlencode(str_replace(get_stylesheet_directory() . '/', '', $template->path)); 236 244 $themeName = basename(get_stylesheet_directory()); 237 $editUrl = home_url('/wp-admin/theme-editor.php?file=' .$filepath.'&theme='.$themeName);245 $editUrl = home_url('/wp-admin/theme-editor.php?file=' . $filepath . '&theme=' . $themeName); 238 246 ?> 239 247 <td> … … 252 260 </tr> 253 261 <?php } ?> 254 <!-- <tr class="nodrag nodrop">--> 255 <!-- <td> </td>--> 256 <!-- <td><i>Registration IP</i></td>--> 257 <!-- <td><i>wpmem_reg_ip</i></td>--> 258 <!-- <td colspan="5"> </td>--> 259 <!-- <td align="center">--> 260 <!-- <input type="checkbox" name="ut_fields[wpmem_reg_ip]" value="Registration IP">--> 261 <!-- </td>--> 262 <!-- </tr>--> 263 </tbody></table> 262 </tbody> 263 </table> 264 264 <div class="footnote"> 265 265 <?php _e('Status: Conflict means same slug alredy exists.'); ?> … … 275 275 printf( 276 276 '<input type="text" id="title" name="my_option_name[title]" value="%s" />', 277 isset( $this->options['title'] ) ? esc_attr($this->options['title']) : ''277 isset($this->options['title']) ? esc_attr($this->options['title']) : '' 278 278 ); 279 279 }
Note: See TracChangeset
for help on using the changeset viewer.