| @@ -14,9 +14,10 @@ | ||
| 14 | 14 | # the_content フィルタを実行しない状態 |
| 15 | 15 | $this->do_not_filter_the_content = false; |
| 16 | 16 | |
| 17 | 17 | // paywall用の本文非表示化とcodocタグへの属性追加 |
| 18 | - $priority = 10; | |
| 18 | + #$priority = 999999999; | |
| 19 | + $priority = 100000; # フィルターは最後に実施する default 10 | |
| 19 | 20 | $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME); |
| 20 | 21 | if (isset($CODOC_SETTINGS["debug_params"])) { |
| 21 | 22 | $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true); |
| 22 | 23 | if (isset($params_decoded["the_content_filter_priority"])) { |
| @@ -55,14 +56,40 @@ | ||
| 55 | 56 | $this->add_mce(); |
| 56 | 57 | } else { // ブログ画面 |
| 57 | 58 | // codocのJS登録 |
| 58 | 59 | add_action( 'wp_enqueue_scripts', function() { |
| 59 | - wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' ); | |
| 60 | + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME); | |
| 61 | + $load_script_condition = ''; | |
| 62 | + if (isset($CODOC_SETTINGS["debug_params"]) and | |
| 63 | + $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true) and | |
| 64 | + isset($params_decoded["load_script_condition"]) | |
| 65 | + ) { | |
| 66 | + $load_script_condition = $params_decoded["load_script_condition"]; | |
| 67 | + } | |
| 68 | + if ($load_script_condition == 'not_list_page') { | |
| 69 | + // not_list_pageの場合はトップページ等でスクリプトをロードしない | |
| 70 | + if (!(is_archive() or is_category() or is_home() or is_front_page())) { | |
| 71 | + wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' ); | |
| 72 | + } | |
| 73 | + } else { | |
| 74 | + wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' ); | |
| 75 | + } | |
| 60 | 76 | }); |
| 61 | - // 登録したscriptタグに属性をつける | |
| 77 | + //登録したscriptタグに属性をつける | |
| 62 | 78 | add_filter('script_loader_tag', [$this,'modifier_script_tag'],10,2); |
| 63 | 79 | // tinymce用のショートコード |
| 64 | 80 | add_shortcode('codoc', [$this, 'injector_shortcode']); |
| 81 | + // テーマをbodyにも反映 | |
| 82 | + add_filter('body_class', function($classes) { | |
| 83 | + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME); | |
| 84 | + $css_path = 'blue'; | |
| 85 | + if (isset($CODOC_SETTINGS["css_path"]) and $CODOC_SETTINGS["css_path"]) { | |
| 86 | + $css_path = $CODOC_SETTINGS["css_path"]; | |
| 87 | + } | |
| 88 | + array_push($classes,sprintf( "codoc-theme-%s",$css_path)); | |
| 89 | + return $classes; | |
| 90 | + }); | |
| 91 | + | |
| 65 | 92 | } |
| 66 | 93 | return $this; |
| 67 | 94 | } |
| 68 | 95 | public function get_codoc_url() { |
| @@ -83,10 +110,32 @@ | ||
| 83 | 110 | $data_css = ''; |
| 84 | 111 | if ($css_path = $CODOC_SETTINGS['css_path']) { |
| 85 | 112 | $data_css = sprintf(' data-css="%s" ',$css_path); |
| 86 | 113 | } |
| 114 | + // connect用パラメータ | |
| 115 | + $connect_attributes = ''; | |
| 116 | + if (isset($CODOC_SETTINGS["codoc_connect_code"])) { | |
| 117 | + $connect_code = $CODOC_SETTINGS["codoc_connect_code"]; | |
| 118 | + $connect_attributes = sprintf(' data-connect-code="%s"',$connect_code); | |
| 119 | + $tag = preg_replace('/cms\.js/','cms-connect.js',$tag); | |
| 120 | + } | |
| 121 | + if (isset($CODOC_SETTINGS["codoc_connect_registration_mode"]) and $CODOC_SETTINGS["codoc_connect_registration_mode"]) { | |
| 122 | + $connect_attributes = $connect_attributes . | |
| 123 | + sprintf(' data-connect-registration-mode="%s"',$CODOC_SETTINGS["codoc_connect_registration_mode"]); | |
| 124 | + } | |
| 125 | + | |
| 126 | + $usercode_attributes = ''; | |
| 127 | + $user_code = get_option(CODOC_USERCODE_OPTION_NAME); | |
| 128 | + if ($user_code) { | |
| 129 | + $usercode_attributes = sprintf(' data-usercode="%s"',$user_code); | |
| 130 | + } | |
| 131 | + | |
| 132 | + $setting_attributes = ''; | |
| 133 | + if ($CODOC_SETTINGS['codoc_script_tag_attributes']) { | |
| 134 | + $setting_attributes = $CODOC_SETTINGS['codoc_script_tag_attributes']; | |
| 135 | + } | |
| 87 | 136 | //return str_replace(' src=', $data_css . ' defer src=', $tag); |
| 88 | - return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . ' defer',$tag); | |
| 137 | + return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . $connect_attributes . $usercode_attributes . $setting_attributes . ' defer',$tag); | |
| 89 | 138 | } |
| 90 | 139 | public function injector_shortcode($atts) { |
| 91 | 140 | global $post; |
| 92 | 141 | ob_start(); |
| @@ -116,9 +165,8 @@ | ||
| 116 | 165 | add_action('admin_print_styles', 'codoc_admin_styles'); |
| 117 | 166 | function codoc_admin_styles($hook) { |
| 118 | 167 | wp_enqueue_style('codoc-options-style', plugins_url( 'codoc/css/codoc-options.css', __DIR__ )); |
| 119 | 168 | } |
| 120 | - | |
| 121 | 169 | add_action( "admin_init", function() { |
| 122 | 170 | // codocからの認証データ処理 |
| 123 | 171 | if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['fetch_token_key'])) { |
| 124 | 172 | $key = sanitize_text_field($_GET['fetch_token_key']); |
| @@ -130,12 +178,9 @@ | ||
| 130 | 178 | update_option(CODOC_TOKEN_OPTION_NAME,$token); |
| 131 | 179 | //$data = $this->callAPI('GET',''); |
| 132 | 180 | $data = $this->util->get_user_info([],["usercode" => $usercode, "token" => $token]); |
| 133 | 181 | if ($data->status and $user = $data->user) { |
| 134 | - update_option(CODOC_AUTHINFO_OPTION_NAME,[ | |
| 135 | - 'email' => $user->email, | |
| 136 | - 'name' => $user->name, | |
| 137 | - ]); | |
| 182 | + $this->update_codoc_authinfo($user); | |
| 138 | 183 | } |
| 139 | 184 | #$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
| 140 | 185 | #$current_url = preg_replace('/(.*)fetch_token_key.*/','${1}&codoc_auth_finished=1',$current_url); |
| 141 | 186 | //add_settings_error( 'general', 'settings_updated', __( 'OK' ), 'success' ); |
| @@ -216,12 +261,20 @@ | ||
| 216 | 261 | |
| 217 | 262 | if (!isset($CODOC_SETTINGS['codoc_tag_attributes'])) { |
| 218 | 263 | $CODOC_SETTINGS['codoc_tag_attributes'] = ''; |
| 219 | 264 | } |
| 265 | + if (!isset($CODOC_SETTINGS['codoc_script_tag_attributes'])) { | |
| 266 | + $CODOC_SETTINGS['codoc_script_tag_attributes'] = ''; | |
| 267 | + } | |
| 268 | + if (!isset($CODOC_SETTINGS['codoc_connect_code'])) { | |
| 269 | + $CODOC_SETTINGS['codoc_connect_code'] = ''; | |
| 270 | + } | |
| 271 | + if (!isset($CODOC_SETTINGS['codoc_connect_registration_mode'])) { | |
| 272 | + $CODOC_SETTINGS['codoc_connect_registration_mode'] = ''; | |
| 273 | + } | |
| 220 | 274 | if (!isset($CODOC_SETTINGS['debug_params'])) { |
| 221 | 275 | $CODOC_SETTINGS['debug_params'] = ''; |
| 222 | 276 | } |
| 223 | - | |
| 224 | 277 | add_settings_section( |
| 225 | 278 | 'setting_section_id', // id |
| 226 | 279 | 'codoc 設定ページ', // title |
| 227 | 280 | function (){}, // callback |
| @@ -228,8 +281,19 @@ | ||
| 228 | 281 | 'codoc' // page |
| 229 | 282 | ); |
| 230 | 283 | // 認証がある場合 |
| 231 | 284 | if ($CODOC_AUTHINFO) { |
| 285 | + // クリエイター情報だけ更新 (POST時に同期をとる) | |
| 286 | + if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['settings-updated'])) { | |
| 287 | + $data = $this->util->get_user_info([],[ | |
| 288 | + "usercode" => get_option(CODOC_USERCODE_OPTION_NAME), | |
| 289 | + "token" => get_option(CODOC_TOKEN_OPTION_NAME), | |
| 290 | + ]); | |
| 291 | + if ($data->status and $user = $data->user) { | |
| 292 | + $this->update_codoc_authinfo($user); | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 232 | 296 | register_setting( |
| 233 | 297 | 'codoc_option_group', // option group |
| 234 | 298 | CODOC_SETTINGS_OPTION_NAME // option name(DB) |
| 235 | 299 | ); |
| @@ -245,9 +309,11 @@ | ||
| 245 | 309 | ' function gen_css_path(select) { ' . |
| 246 | 310 | ' if (select.value == "dark") { ' . |
| 247 | 311 | ' document.getElementById("darkmode-caution").style.display="block";' . |
| 248 | 312 | ' } else { ' . |
| 249 | - ' document.getElementById("darkmode-caution").style.display="none";' . | |
| 313 | + ' if (document.getElementById("darkmode-caution")) { ' . | |
| 314 | + ' document.getElementById("darkmode-caution").style.display="none";' . | |
| 315 | + ' } ' . | |
| 250 | 316 | ' } ' . |
| 251 | 317 | ' if (select.value == "path") { ' . |
| 252 | 318 | ' document.getElementById("codoc_css_path").readOnly=false; ' . |
| 253 | 319 | ' if (!document.getElementById("codoc_css_path").value.match(/\//g)) {' . |
| @@ -260,9 +326,9 @@ | ||
| 260 | 326 | ' } ' . |
| 261 | 327 | '</script> ' ; |
| 262 | 328 | |
| 263 | 329 | echo sprintf('<select name="theme_name" onChange="gen_css_path(this)" id="codoc_theme_select">'); |
| 264 | - foreach (["blue","red","green","black","dark"] as $theme) { | |
| 330 | + foreach (["blue","red","green","black","dark","blue-square","red-square","green-square","black-square","dark-square"] as $theme) { | |
| 265 | 331 | if ($theme == "blue") { |
| 266 | 332 | echo sprintf('<option value="%s" %s>青</option>', $theme, ($CODOC_SETTINGS["css_path"] == "blue" ? "selected" : "")); |
| 267 | 333 | } |
| 268 | 334 | if ($theme == "red") { |
| @@ -276,8 +342,23 @@ | ||
| 276 | 342 | } |
| 277 | 343 | if ($theme == "dark") { |
| 278 | 344 | echo sprintf('<option value="%s" %s>ダークモード</option>', $theme, ($CODOC_SETTINGS["css_path"] == "dark" ? "selected" : "")); |
| 279 | 345 | } |
| 346 | + if ($theme == "blue-square") { | |
| 347 | + echo sprintf('<option value="%s" %s>青(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "blue-square" ? "selected" : "")); | |
| 348 | + } | |
| 349 | + if ($theme == "red-square") { | |
| 350 | + echo sprintf('<option value="%s" %s>赤(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "red-square" ? "selected" : "")); | |
| 351 | + } | |
| 352 | + if ($theme == "green-square") { | |
| 353 | + echo sprintf('<option value="%s" %s>緑(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "green-square" ? "selected" : "")); | |
| 354 | + } | |
| 355 | + if ($theme == "black-square") { | |
| 356 | + echo sprintf('<option value="%s" %s>黒(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "black-square" ? "selected" : "")); | |
| 357 | + } | |
| 358 | + if ($theme == "dark-square") { | |
| 359 | + echo sprintf('<option value="%s" %s>ダークモード(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "dark-square" ? "selected" : "")); | |
| 360 | + } | |
| 280 | 361 | } |
| 281 | 362 | echo sprintf('<option value="path" %s>パス指定</option>', (preg_match("/\//",$CODOC_SETTINGS["css_path"]) ? "selected" : "")); |
| 282 | 363 | echo '<script type="text/javascript">gen_css_path(document.getElementById(\'codoc_theme_select\'))</script>'; |
| 283 | 364 | echo sprintf('</select></div>'); |
| @@ -344,10 +425,20 @@ | ||
| 344 | 425 | }, |
| 345 | 426 | 'codoc', //page |
| 346 | 427 | 'setting_section_id' //Section |
| 347 | 428 | ); |
| 348 | - | |
| 349 | 429 | add_settings_field( |
| 430 | + 'codoc_script_tag_attributes', // id | |
| 431 | + 'codoc scriptタグの属性', // title | |
| 432 | + function() { | |
| 433 | + global $CODOC_SETTINGS; | |
| 434 | + echo '<div class="excerpt">codoc scriptタグに特定の属性を追加することができます。</div>'; | |
| 435 | + echo sprintf('<input type="text" name="%s[codoc_script_tag_attributes]" value="%s">',CODOC_SETTINGS_OPTION_NAME,htmlspecialchars($CODOC_SETTINGS['codoc_script_tag_attributes'])); | |
| 436 | + }, | |
| 437 | + 'codoc', //page | |
| 438 | + 'setting_section_id' //Section | |
| 439 | + ); | |
| 440 | + add_settings_field( | |
| 350 | 441 | 'str_replace_binded_url', // id |
| 351 | 442 | 'パーマリンク', // title |
| 352 | 443 | function() { |
| 353 | 444 | global $CODOC_SETTINGS; |
| @@ -427,8 +518,32 @@ | ||
| 427 | 518 | 'codoc', //page |
| 428 | 519 | 'setting_section_id' //Section |
| 429 | 520 | ); |
| 430 | 521 | |
| 522 | + add_settings_field( | |
| 523 | + 'cretor_info', // id | |
| 524 | + 'クリエイター情報', // title | |
| 525 | + function() { | |
| 526 | + global $CODOC_SETTINGS; | |
| 527 | + global $CODOC_AUTHINFO; | |
| 528 | + echo sprintf('<p><font id="codoc-update-creator-info-message"></font></p>',""); | |
| 529 | + // 変更を保存時に常に同期するのでこの表示は必要ないがUI上保持しておく | |
| 530 | + $script = "document.getElementById('codoc-update-creator-info-message').innerText='情報を更新するには変更を保存してください';document.getElementById('codoc-update-creator-info-message').color='red';"; | |
| 531 | + if (isset($CODOC_AUTHINFO['profile_image_url'])) { | |
| 532 | + echo sprintf('<img src="%s" width="40" height="40" />',$CODOC_AUTHINFO['profile_image_url']); | |
| 533 | + } | |
| 534 | + echo sprintf('<p>%s</p>',$CODOC_AUTHINFO['name']); | |
| 535 | + if ($connect_code = $CODOC_SETTINGS['codoc_connect_code']) { | |
| 536 | + echo sprintf('<p>%s外部サービス連携済(連携コード:%s)</p>', | |
| 537 | + ($CODOC_SETTINGS['codoc_connect_registration_mode'] == 'dedicated' ? '専用ユーザーモードで' : ''), | |
| 538 | + $connect_code); | |
| 539 | + } | |
| 540 | + echo sprintf('<p>情報を<a href="javascript:void(0);" onClick="' . $script . '">更新する</a></p>'); | |
| 541 | + echo ('<p>codoc側でロゴやカバー画像を変更した場合は都度更新を行ってください</p>'); | |
| 542 | + }, | |
| 543 | + 'codoc', //page | |
| 544 | + 'setting_section_id' //Section | |
| 545 | + ); | |
| 431 | 546 | |
| 432 | 547 | register_setting( |
| 433 | 548 | 'codoc_option_group', // option group |
| 434 | 549 | CODOC_USERCODE_OPTION_NAME |
| @@ -468,13 +583,17 @@ | ||
| 468 | 583 | add_settings_field( |
| 469 | 584 | 'codoc_auth', |
| 470 | 585 | '認証', |
| 471 | 586 | function() { |
| 472 | - | |
| 587 | + $theme = wp_get_theme(); | |
| 588 | + $from = 'wp'; | |
| 589 | + if ($theme->get('Name') === 'codoc') { | |
| 590 | + $from = 'wp_codoc'; | |
| 591 | + } | |
| 473 | 592 | //$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
| 474 | 593 | $current_url = admin_url('options-general.php') . '?page=codoc'; |
| 475 | - $login_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/me/token?from=wp&return_url=' . urlencode($current_url)); | |
| 476 | - $register_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/register?from=wp&return_url=' . urlencode($current_url)); | |
| 594 | + $login_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/me/token?from=' . $from . '&return_url=' . urlencode($current_url)); | |
| 595 | + $register_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/register?from=' . $from . '&return_url=' . urlencode($current_url)); | |
| 477 | 596 | // submitを消しておく |
| 478 | 597 | echo ('<script type="text/javascript">window.onload=function(){document.getElementById(\'submit\').style.display = \'none\'}</script>'); |
| 479 | 598 | echo ('codocをWordPressでご利用いただくには認証が必要です。<br />'); |
| 480 | 599 | echo sprintf('ユーザーコードとAPIトークンを<a href="%s&auth_by_myself=1">直接入力</a>することでも認証できます。<br /><br />',$current_url); |
| @@ -547,9 +666,9 @@ | ||
| 547 | 666 | } elseif(isset($CODOC_SETTINGS['always_show_support']) and !$CODOC_SETTINGS['always_show_support']) { |
| 548 | 667 | update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,''); |
| 549 | 668 | } |
| 550 | 669 | }); |
| 551 | - | |
| 670 | + | |
| 552 | 671 | add_action('updated_option',function(){ |
| 553 | 672 | global $CODOC_RE_AUTHORIZE; |
| 554 | 673 | if ($CODOC_RE_AUTHORIZE) { |
| 555 | 674 | //$data = $this->callAPI('GET',''); |
| @@ -557,12 +676,9 @@ | ||
| 557 | 676 | "usercode" => get_option(CODOC_USERCODE_OPTION_NAME), |
| 558 | 677 | "token" => get_option(CODOC_TOKEN_OPTION_NAME), |
| 559 | 678 | ]); |
| 560 | 679 | if ($data->status and $user = $data->user) { |
| 561 | - update_option(CODOC_AUTHINFO_OPTION_NAME,[ | |
| 562 | - 'email' => $user->email, | |
| 563 | - 'name' => $user->name, | |
| 564 | - ]); | |
| 680 | + $this->update_codoc_authinfo($user); | |
| 565 | 681 | } else { |
| 566 | 682 | update_option(CODOC_AUTHINFO_OPTION_NAME,''); |
| 567 | 683 | } |
| 568 | 684 | } |
| @@ -624,13 +740,51 @@ | ||
| 624 | 740 | add_filter( 'mce_buttons', function( $buttons ) { |
| 625 | 741 | array_push( $buttons, "|", "codoc" ); |
| 626 | 742 | return $buttons; |
| 627 | 743 | } ); |
| 744 | + // 非SSL環境の場合、なぜかhttps -> httpsになってしまうので対策 | |
| 745 | + // コメントタグが除去されることがあるらしいのでvalid_elementsに必要なタグを追加 (EXPERIMENTAL) | |
| 746 | + add_filter( 'tiny_mce_before_init', function($settings) { | |
| 747 | + $settings['external_plugins'] = preg_replace('/"codoc":"http:/','"codoc":"https:',$settings['external_plugins']); | |
| 748 | + foreach (['valid_elements','extended_valid_elements'] as $valid_elements) { | |
| 749 | + if (isset($settings[$valid_elements])) { | |
| 750 | + $settings[$valid_elements] = $settings[$valid_elements] . ',div[*],p[*],img[*],--[*]'; | |
| 751 | + } | |
| 752 | + } | |
| 753 | + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME); | |
| 754 | + if (isset($CODOC_SETTINGS["debug_params"])) { | |
| 755 | + $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true); | |
| 756 | + if (isset($params_decoded["mce_valid_elements"])) { | |
| 757 | + $settings['valid_elements'] = $params_decoded["mce_valid_elements"]; | |
| 758 | + $settings['extended_valid_elements'] = $params_decoded["mce_valid_elements"]; | |
| 759 | + } | |
| 760 | + } | |
| 628 | 761 | |
| 762 | + return $settings; | |
| 763 | + },1000000); | |
| 629 | 764 | } |
| 630 | 765 | } |
| 631 | 766 | } ); |
| 632 | 767 | } |
| 768 | + function update_codoc_authinfo($user) { | |
| 769 | + global $CODOC_SETTINGS; | |
| 770 | + global $CODOC_AUTHINFO; | |
| 771 | + if (property_exists($user,'connect_code') and $user->connect_code) { | |
| 772 | + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME); | |
| 773 | + $CODOC_SETTINGS['codoc_connect_code'] = $user->connect_code; | |
| 774 | + $CODOC_SETTINGS['codoc_connect_registration_mode'] = $user->connect_has_permission_dedicated_account ? 'dedicated' : ''; | |
| 775 | + update_option(CODOC_SETTINGS_OPTION_NAME,$CODOC_SETTINGS); | |
| 776 | + } | |
| 777 | + return update_option(CODOC_AUTHINFO_OPTION_NAME,[ | |
| 778 | + 'email' => $user->email, | |
| 779 | + 'name' => $user->name, | |
| 780 | + 'profile_image_url' => $user->profile_image_url, | |
| 781 | + 'cover_image_url' => $user->cover_image_url, | |
| 782 | + 'connect_code' => property_exists($user,'connect_code') ? $user->connect_code : '', | |
| 783 | + 'connect_image_url' => property_exists($user,'connect_image_url') ? $user->connect_image_url : '', | |
| 784 | + ]); | |
| 785 | + $CODOC_AUTHINFO = get_option(CODOC_AUTHINFO_OPTION_NAME); | |
| 786 | + } | |
| 633 | 787 | public function get_filtered_content($post_emulated) { |
| 634 | 788 | // 記事ページであることをエミュレートしてフィルター実行 |
| 635 | 789 | $post_backuped = null; |
| 636 | 790 | if (isset($GLOBALS['post'])) { |
| @@ -641,10 +795,15 @@ | ||
| 641 | 795 | $wp_query_backuped = null; |
| 642 | 796 | if (isset($GLOBALS['wp_query'])) { |
| 643 | 797 | $wp_query_backuped = $GLOBALS['wp_query']; |
| 644 | 798 | $wp_query = $GLOBALS['wp_query']; |
| 645 | - $is_single_backuped = $wp_query->is_single; | |
| 646 | 799 | $wp_query->is_single = true; |
| 800 | + $wp_query->is_singular = true; | |
| 801 | + # in_the_loop は記事ページでは通常有効っぽいので true指定 ex: wp_ulike | |
| 802 | + $wp_query->in_the_loop = true; | |
| 803 | + # これも追加しておく | |
| 804 | + $wp_query->is_main_query = true; | |
| 805 | + | |
| 647 | 806 | $wp_query->post = $post_emulated; |
| 648 | 807 | $wp_query->queried_object = $post_emulated; |
| 649 | 808 | $wp_query->queried_object_id = $post_emulated->id; |
| 650 | 809 | |
| @@ -669,9 +828,8 @@ | ||
| 669 | 828 | $content_filtered = preg_replace( |
| 670 | 829 | '/ (\/)?wptmp:codoc\/codoc-block /',' \\1wp:codoc/codoc-block ', |
| 671 | 830 | $content_filtered |
| 672 | 831 | ); |
| 673 | - | |
| 674 | 832 | return $content_filtered; |
| 675 | 833 | } |
| 676 | 834 | |
| 677 | 835 | public function save_post($post_ID,$post,$update) { |
| @@ -684,9 +842,10 @@ | ||
| 684 | 842 | $post->post_content : $this->get_filtered_content($post); |
| 685 | 843 | $res = $this->util->sync_entry([ |
| 686 | 844 | "post_title" => $post->post_title, |
| 687 | 845 | "post_content" => $post_content, |
| 688 | - "post_status" => ($post->post_status == 'publish' ? 1 : 0), | |
| 846 | + // password が設定されてる場合は限定公開にする | |
| 847 | + "post_status" => $post->post_status == 'publish' ? ($post->post_password ? 2 : 1) : 0, | |
| 689 | 848 | "post_permalink" => get_permalink($post_ID), |
| 690 | 849 | "codoc_entry_code" => $entryCode, |
| 691 | 850 | "codoc_settings" => $codoc_settings, |
| 692 | 851 | ],[ |
| @@ -696,16 +855,25 @@ | ||
| 696 | 855 | |
| 697 | 856 | if (is_object($res) and $res->status and !$entryCode) { |
| 698 | 857 | update_post_meta($post_ID,'codoc_entry_code',$res->entry->code); |
| 699 | 858 | } |
| 700 | - | |
| 701 | 859 | return true; |
| 702 | 860 | } |
| 703 | 861 | function updated_post_meta( $meta_ID, $post_ID, $meta_key ) { |
| 704 | - if ($meta_key != '_thumbnail_id') { | |
| 862 | + // スルーされてる場合は他のメタ情報更新のタイミングにサムネイルをアップロード | |
| 863 | + $has_to_resend = get_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',true); | |
| 864 | + $has_to_resendi = get_post_meta($post_ID,'icodoc_post_thumbnail_invoking_entry_code',true); | |
| 865 | + if ($has_to_resend != 1 and $meta_key != '_thumbnail_id') { | |
| 705 | 866 | return; |
| 706 | 867 | } |
| 707 | 868 | if ( has_post_thumbnail($post_ID) ) { |
| 869 | + // 新規投稿の場合、タイミングによってはcodocEntryCodeが取得できないので一旦スルーする | |
| 870 | + if (!get_post_meta($post_ID,'codoc_entry_code',true)) { | |
| 871 | + update_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',1); | |
| 872 | + return; | |
| 873 | + } else { | |
| 874 | + update_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',0); | |
| 875 | + } | |
| 708 | 876 | $attachment = wp_get_attachment_metadata( get_post_thumbnail_id($post_ID)); |
| 709 | 877 | $upload_dir = wp_upload_dir(); |
| 710 | 878 | $file_path = sprintf ('%s/%s',$upload_dir['basedir'],$attachment['file']); |
| 711 | 879 | |