Changeset 2375582
- Timestamp:
- 09/05/2020 03:03:07 AM (5 years ago)
- File:
-
- 1 edited
-
shorthand-connect/trunk/shorthand_connect.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shorthand-connect/trunk/shorthand_connect.php
r2336571 r2375582 1 1 <?php 2 2 3 /** 3 4 * @package Shorthand Connect 4 * @version 1.3. 25 * @version 1.3.3 5 6 */ 6 7 /* … … 9 10 Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic! 10 11 Author: Shorthand 11 Version: 1.3. 212 Version: 1.3.3 12 13 Author URI: http://shorthand.com 13 14 */ … … 27 28 28 29 /* Create the Shorthand post type */ 29 function shand_create_post_type() { 30 $permalink = get_option('sh_permalink'); 31 if ($permalink == '') { 32 $permalink = 'shorthand_story'; 33 } 34 register_post_type( 'shorthand_story', 35 array( 36 'labels' => array( 37 'name' => __( 'Shorthand' ), 38 'singular_name' => __( 'Shorthand Story' ), 39 'add_new' => __( 'Add Shorthand Story' ), 40 'add_new_item' => __( 'Add Shorthand Story' ), 41 'new_item' => __( 'Add Shorthand Story' ), 42 'edit_item' => __( 'Update Shorthand Story' ), 43 'view_item' => __( 'View Shorthand Story' ), 44 'not_found' => __( 'No stories found' ), 45 'not_found_in_trash' => __( 'No stories found in trash' ) 46 ), 47 'publicly_queryable' => true, 48 'public' => true, 49 'has_archive' => true, 50 'menu_position' => 4, 51 'supports' => array('title', 'thumbnail', 'author', 'custom-fields'), 52 'register_meta_box_cb' => 'shand_add_shorthand_metaboxes', 53 'menu_icon' => plugins_url( '/includes/icon.png', __FILE__ ), 54 'rewrite' => array('slug' => $permalink, 'with_front' => true), 55 'taxonomies' => array('category', 'post_tag'), 56 ) 57 ); 58 59 register_taxonomy_for_object_type( 'category', 'shorthand_story' ); 60 register_taxonomy_for_object_type( 'post_tag', 'shorthand_story' ); 61 } 62 add_action( 'init', 'shand_create_post_type' ); 63 64 65 function shand_wpt_shorthand_story() { 30 function shand_create_post_type() 31 { 32 $permalink = get_option('sh_permalink'); 33 if ($permalink == '') { 34 $permalink = 'shorthand_story'; 35 } 36 register_post_type( 37 'shorthand_story', 38 array( 39 'labels' => array( 40 'name' => __('Shorthand'), 41 'singular_name' => __('Shorthand Story'), 42 'add_new' => __('Add Shorthand Story'), 43 'add_new_item' => __('Add Shorthand Story'), 44 'new_item' => __('Add Shorthand Story'), 45 'edit_item' => __('Update Shorthand Story'), 46 'view_item' => __('View Shorthand Story'), 47 'not_found' => __('No stories found'), 48 'not_found_in_trash' => __('No stories found in trash') 49 ), 50 'publicly_queryable' => true, 51 'public' => true, 52 'has_archive' => true, 53 'menu_position' => 4, 54 'supports' => array('title', 'thumbnail', 'author', 'custom-fields'), 55 'register_meta_box_cb' => 'shand_add_shorthand_metaboxes', 56 'menu_icon' => plugins_url('/includes/icon.png', __FILE__), 57 'rewrite' => array('slug' => $permalink, 'with_front' => true), 58 'taxonomies' => array('category', 'post_tag'), 59 ) 60 ); 61 62 register_taxonomy_for_object_type('category', 'shorthand_story'); 63 register_taxonomy_for_object_type('post_tag', 'shorthand_story'); 64 } 65 add_action('init', 'shand_create_post_type'); 66 67 68 function shand_wpt_shorthand_story() 69 { 66 70 67 71 global $post; … … 83 87 <style> 84 88 li.story { 85 float:left; 86 width:160px; 87 margin:5px; 88 } 89 float: left; 90 width: 160px; 91 margin: 5px; 92 } 93 89 94 li.story.selected label { 90 background:#5b9dd9; 91 color:#eee; 92 } 95 background: #5b9dd9; 96 color: #eee; 97 } 98 93 99 li.story input { 94 100 display: none !important; 95 101 } 102 96 103 li.story label { 97 display: block;98 background: #fafafa;104 display: block; 105 background: #fafafa; 99 106 text-align: center; 100 height:160px; 101 padding-top:5px; 102 border:1px solid #eeeeee; 103 } 107 height: 160px; 108 padding-top: 5px; 109 border: 1px solid #eeeeee; 110 } 111 104 112 li.story label:hover { 105 border:1px solid #5b9dd9; 106 } 113 border: 1px solid #5b9dd9; 114 } 115 107 116 li.story label span { 108 117 display: block; 109 118 font-weight: bold; 110 119 } 120 111 121 li.story label span.desc { 112 122 display: none; 113 123 } 124 114 125 div.clear { 115 clear:left; 116 } 126 clear: left; 127 } 128 117 129 #codearea { 118 border:1px solid #999999; 119 font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace; 120 width:100%; 121 height:300px; 122 } 130 border: 1px solid #999999; 131 font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace; 132 width: 100%; 133 height: 300px; 134 } 135 123 136 #abstract { 124 border:1px solid #999999; 125 width:100%; 126 height:200px; 127 } 137 border: 1px solid #999999; 138 width: 100%; 139 height: 200px; 140 } 141 128 142 ul.stories { 129 max-height:400px; 130 overflow-y:scroll; 131 } 143 max-height: 400px; 144 overflow-y: scroll; 145 } 146 132 147 ul.stories img { 133 148 object-fit: cover; 134 height:110px; 135 } 149 height: 110px; 150 } 151 136 152 p.warning { 137 153 color: red; … … 139 155 } 140 156 </style> 141 <?php157 <?php 142 158 143 159 $selected_story = get_post_meta($post->ID, 'story_id', true); … … 146 162 if ($story_api_version == $version) { 147 163 echo '<p>Clicking UPDATE will update Wordpress with the latest version of the story from Shorthand.</p>'; 148 echo '<input name="story_id" type="hidden" value="' .$selected_story.'" />';149 } else {164 echo '<input name="story_id" type="hidden" value="' . $selected_story . '" />'; 165 } else { 150 166 echo '<p class="warning">To update this story from Shorthand, please switch to the correct API version <a href="options-general.php?page=shorthand-options">here</a></p>'; 151 167 echo '<style>#publish { visibility: hidden !important; }</style>'; 152 echo '<input name="story_id" type="hidden" value="' .$selected_story.'" />';168 echo '<input name="story_id" type="hidden" value="' . $selected_story . '" />'; 153 169 } 154 170 return; … … 156 172 $stories = sh_get_stories(); 157 173 158 if (!is_array($stories)) {174 if (!is_array($stories)) { 159 175 echo 'Could not connect to Shorthand, please check your <a href="options-general.php?page=shorthand-options">Wordpress Shorthand settings</a>.'; 160 } else if (sizeOf($stories) == 0) {176 } else if (sizeOf($stories) == 0) { 161 177 echo 'You currently have no stories ready for publishing on Shorthand. Please check that your story is set to be ready for publishing.'; 162 178 } else { 163 179 echo '<ul class="stories">'; 164 foreach ($stories as $story) {180 foreach ($stories as $story) { 165 181 $selected = ''; 166 182 $story_selected = ''; … … 177 193 } 178 194 } 179 echo '<li class="story ' .$story_selected.'"><label><input name="story_id" type="radio" value="'.$story->id.'" '.$selected.' /><img width="150" src="'.$baseurl.$story->image.'" /><span class="title">'.$story->title.$archived.'</span><span class="desc">'.$story->metadata->description.'</span></a></label></li>';195 echo '<li class="story ' . $story_selected . '"><label><input name="story_id" type="radio" value="' . $story->id . '" ' . $selected . ' /><img width="150" src="' . $baseurl . $story->image . '" /><span class="title">' . $story->title . $archived . '</span><span class="desc">' . $story->metadata->description . '</span></a></label></li>'; 180 196 } 181 197 echo '</ul><div class="clear"></div>'; … … 184 200 // Noncename needed to verify where the data originated 185 201 echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' . 186 wp_create_nonce( plugin_basename(__FILE__)) . '" />';187 188 ?>202 wp_create_nonce(plugin_basename(__FILE__)) . '" />'; 203 204 ?> 189 205 <script> 190 jQuery('li.story input:radio').click(function(){191 jQuery('li.story').removeClass('selected');192 jQuery(this).parent().parent().addClass('selected');193 jQuery('label#title-prompt-text').text('');194 jQuery('input#title').val(jQuery(this).parent().find('span.title').text());195 if (jQuery('textarea#abstract').val() === '') {196 jQuery('textarea#abstract').val(jQuery(this).parent().find('span.desc').text());197 }198 });206 jQuery('li.story input:radio').click(function() { 207 jQuery('li.story').removeClass('selected'); 208 jQuery(this).parent().parent().addClass('selected'); 209 jQuery('label#title-prompt-text').text(''); 210 jQuery('input#title').val(jQuery(this).parent().find('span.title').text()); 211 if (jQuery('textarea#abstract').val() === '') { 212 jQuery('textarea#abstract').val(jQuery(this).parent().find('span.desc').text()); 213 } 214 }); 199 215 </script> 200 216 <?php 201 217 } 202 218 203 function shand_wpt_shorthand_abstract() { 219 function shand_wpt_shorthand_abstract() 220 { 204 221 global $post; 205 222 $abstract = get_post_meta($post->ID, 'abstract', true); 206 223 echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' . 207 wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 208 echo '<textarea id="abstract" name="abstract">'.esc_textarea($abstract).'</textarea>'; 209 } 210 211 function shand_wpt_shorthand_extra_html() { 224 wp_create_nonce(plugin_basename(__FILE__)) . '" />'; 225 echo '<textarea id="abstract" name="abstract">' . esc_textarea($abstract) . '</textarea>'; 226 } 227 228 function shand_wpt_shorthand_extra_html() 229 { 212 230 global $post; 213 231 $extra_html = get_post_meta($post->ID, 'extra_html', true); 214 232 echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' . 215 wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 216 echo '<textarea id="codearea" name="extra_html">'.esc_textarea($extra_html).'</textarea>'; 217 } 218 219 function shand_add_shorthand_metaboxes() { 233 wp_create_nonce(plugin_basename(__FILE__)) . '" />'; 234 echo '<textarea id="codearea" name="extra_html">' . esc_textarea($extra_html) . '</textarea>'; 235 } 236 237 function shand_add_shorthand_metaboxes() 238 { 220 239 global $version; 221 240 global $post; … … 223 242 $selected_story = get_post_meta($post->ID, 'story_id', true); 224 243 if ($selected_story) { 225 add_meta_box('shand_wpt_shorthand_story', 'Update Shorthand Story - ' .$version.' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default');226 } else {227 add_meta_box('shand_wpt_shorthand_story', 'Select Shorthand Story - '.$version.' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default');228 }229 if (!$noabstract) {230 add_meta_box('shand_wpt_shorthand_abstract', 'Add story abstract', 'shand_wpt_shorthand_abstract', 'shorthand_story', 'normal', 'default');231 }232 add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default');233 } 234 add_action( 'add_meta_boxes', 'shand_add_shorthand_metaboxes');244 add_meta_box('shand_wpt_shorthand_story', 'Update Shorthand Story - ' . $version . ' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default'); 245 } else { 246 add_meta_box('shand_wpt_shorthand_story', 'Select Shorthand Story - ' . $version . ' (<a href="options-general.php?page=shorthand-options">change version</a>)', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default'); 247 } 248 if (!$noabstract) { 249 add_meta_box('shand_wpt_shorthand_abstract', 'Add story abstract', 'shand_wpt_shorthand_abstract', 'shorthand_story', 'normal', 'default'); 250 } 251 add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default'); 252 } 253 add_action('add_meta_boxes', 'shand_add_shorthand_metaboxes'); 235 254 236 255 237 256 /* Save the shorthand story */ 238 function shand_save_shorthand_story( $post_id, $post, $update ) { 257 function shand_save_shorthand_story($post_id, $post, $update) 258 { 239 259 global $noabstract; 240 260 $slug = 'shorthand_story'; 241 if ( $slug != $post->post_type ) { 242 return; 243 } 244 245 if (!$noabstract && isset($_REQUEST['abstract'])) { 246 update_post_meta( $post_id, 'abstract', wp_kses_post($_REQUEST['abstract']) ); 247 } else if ($noabstract && get_post_meta( $post_id, 'abstract' )) { 248 delete_post_meta( $post_id, 'abstract' ); 249 } 250 251 if (isset($_REQUEST['extra_html'])) { 252 update_post_meta( $post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html']) ); 253 } 254 255 if (isset($_REQUEST['story_id'])) { 256 $safe_story_id = $_REQUEST['story_id']; 257 update_post_meta( $post_id, 'story_id', sanitize_text_field( $safe_story_id ) ); 258 $err = sh_copy_story($post_id, $safe_story_id); 261 if ($slug != $post->post_type) { 262 return; 263 } 264 265 if (!$noabstract && isset($_REQUEST['abstract'])) { 266 update_post_meta($post_id, 'abstract', wp_kses_post($_REQUEST['abstract'])); 267 } else if ($noabstract && get_post_meta($post_id, 'abstract')) { 268 delete_post_meta($post_id, 'abstract'); 269 } 270 271 if (isset($_REQUEST['extra_html'])) { 272 update_post_meta($post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html'])); 273 } 274 275 if (isset($_REQUEST['story_id'])) { 276 $safe_story_id = preg_replace("/\W|_/", '', $_REQUEST['story_id']); 277 update_post_meta($post_id, 'story_id', sanitize_text_field($safe_story_id)); 278 $err = sh_copy_story($post_id, $safe_story_id); 279 $story_path = sh_get_story_path($post_id, $safe_story_id); 280 281 //Sometimes the story needs to be gotten twice 282 if (!isset($story_path)) { 283 $err = sh_copy_story($post_id, $safe_story_id); 259 284 $story_path = sh_get_story_path($post_id, $safe_story_id); 260 261 //Sometimes the story needs to be gotten twice 262 if(!isset($story_path)) { 263 $err = sh_copy_story($post_id, $safe_story_id); 264 $story_path = sh_get_story_path($post_id, $safe_story_id); 265 } 266 267 if(isset($story_path)) { 268 // The story has been uploaded 269 update_post_meta($post_id, 'story_path', $story_path); 270 271 // Get path to the assets 272 $assets_path = sh_get_story_url($post_id, $safe_story_id); 273 274 // Save the head and body 275 $version = get_option('sh_api_version'); 276 update_post_meta( $post_id, 'api_version', $version); 277 $head_file = $story_path.'/component_head.html'; 278 $article_file = $story_path.'/component_article.html'; 279 if (substr($safe_story_id, 0, 2) == 'v1') { 280 $version = 'v1'; 281 } 282 if ($version == 'v2') { 283 $head_file = $story_path.'/head.html'; 284 $article_file = $story_path.'/article.html'; 285 } 286 $body = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version); 287 update_post_meta($post_id, 'story_body', wp_slash($body)); 288 $head = shand_fix_content_paths($assets_path, file_get_contents($head_file), $version); 289 update_post_meta($post_id, 'story_head', wp_slash($head)); 290 291 // Save the abstract 292 if (!$noabstract) { 293 $abstract = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version); 294 remove_action( 'save_post', 'shand_save_shorthand_story', 10, 3); 295 $post = array( 296 'ID' => $post_id, 297 'post_content' => shand_abstract_template($post_id, wp_kses_post($_REQUEST['abstract']), $abstract) 298 ); 299 wp_update_post( $post ); 300 add_action( 'save_post', 'shand_save_shorthand_story', 10, 3); 301 } else { 302 remove_action( 'save_post', 'shand_save_shorthand_story', 10, 3); 303 $post = array( 304 'ID' => $post_id, 305 'post_content' => '' 306 ); 307 wp_update_post( $post ); 308 add_action( 'save_post', 'shand_save_shorthand_story', 10, 3); 309 } 310 } else { 311 echo 'Something went wrong, please try again'; 312 print_r($err); 313 die(); 314 } 315 } 316 } 317 add_action( 'save_post', 'shand_save_shorthand_story', 10, 3); 285 } 286 287 if (isset($story_path)) { 288 // The story has been uploaded 289 update_post_meta($post_id, 'story_path', $story_path); 290 291 // Get path to the assets 292 $assets_path = sh_get_story_url($post_id, $safe_story_id); 293 294 // Save the head and body 295 $version = get_option('sh_api_version'); 296 update_post_meta($post_id, 'api_version', $version); 297 $head_file = $story_path . '/component_head.html'; 298 $article_file = $story_path . '/component_article.html'; 299 if (substr($safe_story_id, 0, 2) == 'v1') { 300 $version = 'v1'; 301 } 302 if ($version == 'v2') { 303 $head_file = $story_path . '/head.html'; 304 $article_file = $story_path . '/article.html'; 305 } 306 $body = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version); 307 update_post_meta($post_id, 'story_body', wp_slash($body)); 308 $head = shand_fix_content_paths($assets_path, file_get_contents($head_file), $version); 309 update_post_meta($post_id, 'story_head', wp_slash($head)); 310 311 // Save the abstract 312 if (!$noabstract) { 313 $abstract = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version); 314 remove_action('save_post', 'shand_save_shorthand_story', 10, 3); 315 $post = array( 316 'ID' => $post_id, 317 'post_content' => shand_abstract_template($post_id, wp_kses_post($_REQUEST['abstract']), $abstract) 318 ); 319 wp_update_post($post); 320 add_action('save_post', 'shand_save_shorthand_story', 10, 3); 321 } else { 322 remove_action('save_post', 'shand_save_shorthand_story', 10, 3); 323 $post = array( 324 'ID' => $post_id, 325 'post_content' => '' 326 ); 327 wp_update_post($post); 328 add_action('save_post', 'shand_save_shorthand_story', 10, 3); 329 } 330 } else { 331 echo 'Something went wrong, please try again'; 332 print_r($err); 333 die(); 334 } 335 } 336 } 337 add_action('save_post', 'shand_save_shorthand_story', 10, 3); 318 338 319 339 320 340 /* Load Shorthand Template Hook */ 321 function shand_load_single_shorthand_template($template) { 322 global $post; 323 if ($post->post_type == "shorthand_story"){ 324 $path = locate_template(array('single-shorthand_story.php', 'templates/single-shorthand_story.php', 'template-parts/single-shorthand_story.php')); 325 if($path) { 326 return $path; 327 } 328 $plugin_path = plugin_dir_path( __FILE__ ); 329 $template_name = 'templates/single-shorthand_story.php'; 330 if($template === get_stylesheet_directory() . '/' . $template_name 331 || !file_exists($plugin_path . $template_name)) { 332 return $template; 333 } 334 return $plugin_path . $template_name; 335 } 336 return $template; 341 function shand_load_single_shorthand_template($template) 342 { 343 global $post; 344 if ($post->post_type == "shorthand_story") { 345 $path = locate_template(array('single-shorthand_story.php', 'templates/single-shorthand_story.php', 'template-parts/single-shorthand_story.php')); 346 if ($path) { 347 return $path; 348 } 349 $plugin_path = plugin_dir_path(__FILE__); 350 $template_name = 'templates/single-shorthand_story.php'; 351 if ( 352 $template === get_stylesheet_directory() . '/' . $template_name 353 || !file_exists($plugin_path . $template_name) 354 ) { 355 return $template; 356 } 357 return $plugin_path . $template_name; 358 } 359 return $template; 337 360 } 338 361 add_filter('single_template', 'shand_load_single_shorthand_template'); 339 362 340 363 341 function hook_css() { 342 if ( is_single() && 'shorthand_story' == get_post_type() ) { 364 function hook_css() 365 { 366 if (is_single() && 'shorthand_story' == get_post_type()) { 343 367 $meta = get_post_meta(get_post()->ID); 344 368 echo trim($meta['story_head'][0]); … … 349 373 350 374 /* Get Posts Hook */ 351 function shand_shorthand_get_posts( $query ) { 352 if ( is_home() && $query->is_main_query() ) 353 $query->set( 'post_type', array( 'post', 'shorthand_story' ) ); 375 function shand_shorthand_get_posts($query) 376 { 377 if (is_home() && $query->is_main_query()) 378 $query->set('post_type', array('post', 'shorthand_story')); 354 379 355 380 return $query; 356 381 } 357 add_filter( 'pre_get_posts', 'shand_shorthand_get_posts');382 add_filter('pre_get_posts', 'shand_shorthand_get_posts'); 358 383 359 384 360 385 /* Table Hook */ 361 function shand_add_shorthand_story_columns($columns) { 362 $cols = array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array('api_version' => __('API Version')) + array_slice($columns, 2, count($columns)-2, true); 363 return $cols; 364 } 365 add_filter('manage_shorthand_story_posts_columns' , 'shand_add_shorthand_story_columns'); 386 function shand_add_shorthand_story_columns($columns) 387 { 388 $cols = array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array('api_version' => __('API Version')) + array_slice($columns, 2, count($columns) - 2, true); 389 return $cols; 390 } 391 add_filter('manage_shorthand_story_posts_columns', 'shand_add_shorthand_story_columns'); 366 392 367 393 368 394 /* Table Hook */ 369 function shand_shorthand_show_columns($name) { 370 global $post; 371 switch ($name) { 372 case 'story_id': 373 $views = get_post_meta($post->ID, 'story_id', true); 374 echo $views; 375 break; 376 case 'api_version': 377 $views = get_post_meta($post->ID, 'api_version', true); 378 if ($views == '') { 379 // Determine the version, save it if possible; 380 $views = 'Unknown'; 381 $story_id = get_post_meta($post->ID, 'story_id', true); 382 if ($story_id) { 383 $views = determine_version_id($story_id); 384 } 385 } 386 echo $views; 387 break; 388 } 395 function shand_shorthand_show_columns($name) 396 { 397 global $post; 398 switch ($name) { 399 case 'story_id': 400 $views = get_post_meta($post->ID, 'story_id', true); 401 echo $views; 402 break; 403 case 'api_version': 404 $views = get_post_meta($post->ID, 'api_version', true); 405 if ($views == '') { 406 // Determine the version, save it if possible; 407 $views = 'Unknown'; 408 $story_id = get_post_meta($post->ID, 'story_id', true); 409 if ($story_id) { 410 $views = determine_version_id($story_id); 411 } 412 } 413 echo $views; 414 break; 415 } 389 416 } 390 417 add_action('manage_posts_custom_column', 'shand_shorthand_show_columns'); … … 392 419 393 420 /* Filter to fix post type tags */ 394 function shand_post_type_tags_fix($request) { 395 if ( isset($request['tag']) && !isset($request['post_type']) ) { 396 $request['post_type'] = 'any'; 397 } 398 if ( isset($request['category_name']) && !isset($request['post_type']) ) { 399 $request['post_type'] = 'any'; 400 } 401 return $request; 421 function shand_post_type_tags_fix($request) 422 { 423 if (isset($request['tag']) && !isset($request['post_type'])) { 424 $request['post_type'] = 'any'; 425 } 426 if (isset($request['category_name']) && !isset($request['post_type'])) { 427 $request['post_type'] = 'any'; 428 } 429 return $request; 402 430 } 403 431 add_filter('request', 'shand_post_type_tags_fix'); … … 405 433 406 434 /* Activation Hook */ 407 function shand_shorthand_activate() { 435 function shand_shorthand_activate() 436 { 408 437 shand_create_post_type(); 409 438 flush_rewrite_rules(); 410 439 } 411 register_activation_hook( __FILE__, 'shand_shorthand_activate');440 register_activation_hook(__FILE__, 'shand_shorthand_activate'); 412 441 413 442 … … 415 444 416 445 /* Fix content paths */ 417 function shand_fix_content_paths($assets_path, $content, $version) { 446 function shand_fix_content_paths($assets_path, $content, $version) 447 { 418 448 if ($version == 'v2') { 419 $content = str_replace('./assets/', $assets_path .'/assets/', $content);420 $content = str_replace('./static/', $assets_path .'/static/', $content);421 $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path .'$1', $content);449 $content = str_replace('./assets/', $assets_path . '/assets/', $content); 450 $content = str_replace('./static/', $assets_path . '/static/', $content); 451 $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path . '$1', $content); 422 452 } else { 423 $content = str_replace('./static/', $assets_path .'/static/', $content);424 $content = str_replace('./media/', $assets_path .'/media/', $content);453 $content = str_replace('./static/', $assets_path . '/static/', $content); 454 $content = str_replace('./media/', $assets_path . '/media/', $content); 425 455 } 426 456 return $content; 427 457 } 428 458 429 function determine_version_id($story_id) { 459 function determine_version_id($story_id) 460 { 430 461 if (substr($story_id, 0, 2) == 'v1') { 431 462 return 'v1';
Note: See TracChangeset
for help on using the changeset viewer.