| @@ -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() { |
| @@ -90,17 +117,25 @@ | ||
| 90 | 117 | $connect_code = $CODOC_SETTINGS["codoc_connect_code"]; |
| 91 | 118 | $connect_attributes = sprintf(' data-connect-code="%s"',$connect_code); |
| 92 | 119 | $tag = preg_replace('/cms\.js/','cms-connect.js',$tag); |
| 93 | 120 | } |
| 94 | - if (isset($CODOC_SETTINGS["debug_params"])) { | |
| 95 | - $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true); | |
| 96 | - if (isset($params_decoded["connect_registration_mode"])) { | |
| 97 | - $connect_attributes = $connect_attributes . sprintf(' data-connect-registration-mode="%s"',$params_decoded["connect_registration_mode"]); | |
| 98 | - } | |
| 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"]); | |
| 99 | 124 | } |
| 100 | - | |
| 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 | + } | |
| 101 | 136 | //return str_replace(' src=', $data_css . ' defer src=', $tag); |
| 102 | - return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . $connect_attributes . ' defer',$tag); | |
| 137 | + return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . $connect_attributes . $usercode_attributes . $setting_attributes . ' defer',$tag); | |
| 103 | 138 | } |
| 104 | 139 | public function injector_shortcode($atts) { |
| 105 | 140 | global $post; |
| 106 | 141 | ob_start(); |
| @@ -130,9 +165,8 @@ | ||
| 130 | 165 | add_action('admin_print_styles', 'codoc_admin_styles'); |
| 131 | 166 | function codoc_admin_styles($hook) { |
| 132 | 167 | wp_enqueue_style('codoc-options-style', plugins_url( 'codoc/css/codoc-options.css', __DIR__ )); |
| 133 | 168 | } |
| 134 | - | |
| 135 | 169 | add_action( "admin_init", function() { |
| 136 | 170 | // codocからの認証データ処理 |
| 137 | 171 | if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['fetch_token_key'])) { |
| 138 | 172 | $key = sanitize_text_field($_GET['fetch_token_key']); |
| @@ -144,12 +178,9 @@ | ||
| 144 | 178 | update_option(CODOC_TOKEN_OPTION_NAME,$token); |
| 145 | 179 | //$data = $this->callAPI('GET',''); |
| 146 | 180 | $data = $this->util->get_user_info([],["usercode" => $usercode, "token" => $token]); |
| 147 | 181 | if ($data->status and $user = $data->user) { |
| 148 | - update_option(CODOC_AUTHINFO_OPTION_NAME,[ | |
| 149 | - 'email' => $user->email, | |
| 150 | - 'name' => $user->name, | |
| 151 | - ]); | |
| 182 | + $this->update_codoc_authinfo($user); | |
| 152 | 183 | } |
| 153 | 184 | #$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
| 154 | 185 | #$current_url = preg_replace('/(.*)fetch_token_key.*/','${1}&codoc_auth_finished=1',$current_url); |
| 155 | 186 | //add_settings_error( 'general', 'settings_updated', __( 'OK' ), 'success' ); |
| @@ -230,15 +261,20 @@ | ||
| 230 | 261 | |
| 231 | 262 | if (!isset($CODOC_SETTINGS['codoc_tag_attributes'])) { |
| 232 | 263 | $CODOC_SETTINGS['codoc_tag_attributes'] = ''; |
| 233 | 264 | } |
| 265 | + if (!isset($CODOC_SETTINGS['codoc_script_tag_attributes'])) { | |
| 266 | + $CODOC_SETTINGS['codoc_script_tag_attributes'] = ''; | |
| 267 | + } | |
| 234 | 268 | if (!isset($CODOC_SETTINGS['codoc_connect_code'])) { |
| 235 | 269 | $CODOC_SETTINGS['codoc_connect_code'] = ''; |
| 236 | 270 | } |
| 271 | + if (!isset($CODOC_SETTINGS['codoc_connect_registration_mode'])) { | |
| 272 | + $CODOC_SETTINGS['codoc_connect_registration_mode'] = ''; | |
| 273 | + } | |
| 237 | 274 | if (!isset($CODOC_SETTINGS['debug_params'])) { |
| 238 | 275 | $CODOC_SETTINGS['debug_params'] = ''; |
| 239 | 276 | } |
| 240 | - | |
| 241 | 277 | add_settings_section( |
| 242 | 278 | 'setting_section_id', // id |
| 243 | 279 | 'codoc 設定ページ', // title |
| 244 | 280 | function (){}, // callback |
| @@ -245,8 +281,19 @@ | ||
| 245 | 281 | 'codoc' // page |
| 246 | 282 | ); |
| 247 | 283 | // 認証がある場合 |
| 248 | 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 | + | |
| 249 | 296 | register_setting( |
| 250 | 297 | 'codoc_option_group', // option group |
| 251 | 298 | CODOC_SETTINGS_OPTION_NAME // option name(DB) |
| 252 | 299 | ); |
| @@ -262,9 +309,11 @@ | ||
| 262 | 309 | ' function gen_css_path(select) { ' . |
| 263 | 310 | ' if (select.value == "dark") { ' . |
| 264 | 311 | ' document.getElementById("darkmode-caution").style.display="block";' . |
| 265 | 312 | ' } else { ' . |
| 266 | - ' document.getElementById("darkmode-caution").style.display="none";' . | |
| 313 | + ' if (document.getElementById("darkmode-caution")) { ' . | |
| 314 | + ' document.getElementById("darkmode-caution").style.display="none";' . | |
| 315 | + ' } ' . | |
| 267 | 316 | ' } ' . |
| 268 | 317 | ' if (select.value == "path") { ' . |
| 269 | 318 | ' document.getElementById("codoc_css_path").readOnly=false; ' . |
| 270 | 319 | ' if (!document.getElementById("codoc_css_path").value.match(/\//g)) {' . |
| @@ -377,19 +426,18 @@ | ||
| 377 | 426 | 'codoc', //page |
| 378 | 427 | 'setting_section_id' //Section |
| 379 | 428 | ); |
| 380 | 429 | add_settings_field( |
| 381 | - 'codoc_connect_code', // id | |
| 382 | - 'サービス連携コード', // title | |
| 430 | + 'codoc_script_tag_attributes', // id | |
| 431 | + 'codoc scriptタグの属性', // title | |
| 383 | 432 | function() { |
| 384 | 433 | global $CODOC_SETTINGS; |
| 385 | - echo '<div class="excerpt">サービス連携ウィジェットを利用するためにはアカウント設定でサービス連携を有効化し、サービス連携コードを指定してください</div>'; | |
| 386 | - echo sprintf('<input type="text" name="%s[codoc_connect_code]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['codoc_connect_code'])); | |
| 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'])); | |
| 387 | 436 | }, |
| 388 | 437 | 'codoc', //page |
| 389 | 438 | 'setting_section_id' //Section |
| 390 | 439 | ); |
| 391 | - | |
| 392 | 440 | add_settings_field( |
| 393 | 441 | 'str_replace_binded_url', // id |
| 394 | 442 | 'パーマリンク', // title |
| 395 | 443 | function() { |
| @@ -470,8 +518,32 @@ | ||
| 470 | 518 | 'codoc', //page |
| 471 | 519 | 'setting_section_id' //Section |
| 472 | 520 | ); |
| 473 | 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 | + ); | |
| 474 | 546 | |
| 475 | 547 | register_setting( |
| 476 | 548 | 'codoc_option_group', // option group |
| 477 | 549 | CODOC_USERCODE_OPTION_NAME |
| @@ -511,13 +583,17 @@ | ||
| 511 | 583 | add_settings_field( |
| 512 | 584 | 'codoc_auth', |
| 513 | 585 | '認証', |
| 514 | 586 | function() { |
| 515 | - | |
| 587 | + $theme = wp_get_theme(); | |
| 588 | + $from = 'wp'; | |
| 589 | + if ($theme->get('Name') === 'codoc') { | |
| 590 | + $from = 'wp_codoc'; | |
| 591 | + } | |
| 516 | 592 | //$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
| 517 | 593 | $current_url = admin_url('options-general.php') . '?page=codoc'; |
| 518 | - $login_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/me/token?from=wp&return_url=' . urlencode($current_url)); | |
| 519 | - $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)); | |
| 520 | 596 | // submitを消しておく |
| 521 | 597 | echo ('<script type="text/javascript">window.onload=function(){document.getElementById(\'submit\').style.display = \'none\'}</script>'); |
| 522 | 598 | echo ('codocをWordPressでご利用いただくには認証が必要です。<br />'); |
| 523 | 599 | echo sprintf('ユーザーコードとAPIトークンを<a href="%s&auth_by_myself=1">直接入力</a>することでも認証できます。<br /><br />',$current_url); |
| @@ -590,9 +666,9 @@ | ||
| 590 | 666 | } elseif(isset($CODOC_SETTINGS['always_show_support']) and !$CODOC_SETTINGS['always_show_support']) { |
| 591 | 667 | update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,''); |
| 592 | 668 | } |
| 593 | 669 | }); |
| 594 | - | |
| 670 | + | |
| 595 | 671 | add_action('updated_option',function(){ |
| 596 | 672 | global $CODOC_RE_AUTHORIZE; |
| 597 | 673 | if ($CODOC_RE_AUTHORIZE) { |
| 598 | 674 | //$data = $this->callAPI('GET',''); |
| @@ -600,12 +676,9 @@ | ||
| 600 | 676 | "usercode" => get_option(CODOC_USERCODE_OPTION_NAME), |
| 601 | 677 | "token" => get_option(CODOC_TOKEN_OPTION_NAME), |
| 602 | 678 | ]); |
| 603 | 679 | if ($data->status and $user = $data->user) { |
| 604 | - update_option(CODOC_AUTHINFO_OPTION_NAME,[ | |
| 605 | - 'email' => $user->email, | |
| 606 | - 'name' => $user->name, | |
| 607 | - ]); | |
| 680 | + $this->update_codoc_authinfo($user); | |
| 608 | 681 | } else { |
| 609 | 682 | update_option(CODOC_AUTHINFO_OPTION_NAME,''); |
| 610 | 683 | } |
| 611 | 684 | } |
| @@ -667,13 +740,51 @@ | ||
| 667 | 740 | add_filter( 'mce_buttons', function( $buttons ) { |
| 668 | 741 | array_push( $buttons, "|", "codoc" ); |
| 669 | 742 | return $buttons; |
| 670 | 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 | + } | |
| 671 | 761 | |
| 762 | + return $settings; | |
| 763 | + },1000000); | |
| 672 | 764 | } |
| 673 | 765 | } |
| 674 | 766 | } ); |
| 675 | 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 | + } | |
| 676 | 787 | public function get_filtered_content($post_emulated) { |
| 677 | 788 | // 記事ページであることをエミュレートしてフィルター実行 |
| 678 | 789 | $post_backuped = null; |
| 679 | 790 | if (isset($GLOBALS['post'])) { |
| @@ -684,10 +795,15 @@ | ||
| 684 | 795 | $wp_query_backuped = null; |
| 685 | 796 | if (isset($GLOBALS['wp_query'])) { |
| 686 | 797 | $wp_query_backuped = $GLOBALS['wp_query']; |
| 687 | 798 | $wp_query = $GLOBALS['wp_query']; |
| 688 | - $is_single_backuped = $wp_query->is_single; | |
| 689 | 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 | + | |
| 690 | 806 | $wp_query->post = $post_emulated; |
| 691 | 807 | $wp_query->queried_object = $post_emulated; |
| 692 | 808 | $wp_query->queried_object_id = $post_emulated->id; |
| 693 | 809 | |
| @@ -712,9 +828,8 @@ | ||
| 712 | 828 | $content_filtered = preg_replace( |
| 713 | 829 | '/ (\/)?wptmp:codoc\/codoc-block /',' \\1wp:codoc/codoc-block ', |
| 714 | 830 | $content_filtered |
| 715 | 831 | ); |
| 716 | - | |
| 717 | 832 | return $content_filtered; |
| 718 | 833 | } |
| 719 | 834 | |
| 720 | 835 | public function save_post($post_ID,$post,$update) { |
| @@ -727,9 +842,10 @@ | ||
| 727 | 842 | $post->post_content : $this->get_filtered_content($post); |
| 728 | 843 | $res = $this->util->sync_entry([ |
| 729 | 844 | "post_title" => $post->post_title, |
| 730 | 845 | "post_content" => $post_content, |
| 731 | - "post_status" => ($post->post_status == 'publish' ? 1 : 0), | |
| 846 | + // password が設定されてる場合は限定公開にする | |
| 847 | + "post_status" => $post->post_status == 'publish' ? ($post->post_password ? 2 : 1) : 0, | |
| 732 | 848 | "post_permalink" => get_permalink($post_ID), |
| 733 | 849 | "codoc_entry_code" => $entryCode, |
| 734 | 850 | "codoc_settings" => $codoc_settings, |
| 735 | 851 | ],[ |
| @@ -739,16 +855,25 @@ | ||
| 739 | 855 | |
| 740 | 856 | if (is_object($res) and $res->status and !$entryCode) { |
| 741 | 857 | update_post_meta($post_ID,'codoc_entry_code',$res->entry->code); |
| 742 | 858 | } |
| 743 | - | |
| 744 | 859 | return true; |
| 745 | 860 | } |
| 746 | 861 | function updated_post_meta( $meta_ID, $post_ID, $meta_key ) { |
| 747 | - 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') { | |
| 748 | 866 | return; |
| 749 | 867 | } |
| 750 | 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 | + } | |
| 751 | 876 | $attachment = wp_get_attachment_metadata( get_post_thumbnail_id($post_ID)); |
| 752 | 877 | $upload_dir = wp_upload_dir(); |
| 753 | 878 | $file_path = sprintf ('%s/%s',$upload_dir['basedir'],$attachment['file']); |
| 754 | 879 | |