Требуется устранение неполадок при разборе атрибутов шорткода - PullRequest
0 голосов
/ 29 февраля 2020

Это часть сложной функции, которую я написал 2 года go, и я не могу вспомнить, как передать дату и время в шорткоде. В результате сообщение не публикуется sh.

. Я не понимаю, почему оно не работает, поэтому я подумал, что множество глаз может увидеть причину.

Ниже представлен проблемный раздел кода c, шорткод в сообщении и журнал отладки.

Пожалуйста, посмотрите и дайте мне знать, если вы видите причину. Большое спасибо !!

См. Стрелку в коде, где ошибка появляется в строке 272 для каждого журнала отладки:

//Parse the attributes passed from the shortcode for use downstream. Use default where no attribute was passed. Ignore any passed attribute for which there is no default.
    $auc_start = $parsed_atts['auc_start'];
    $auc_end = $parsed_atts['auc_end'];
    $starting_bid = $parsed_atts['start_bid'];
    $bid_increment = $parsed_atts['bid_increment'];
    $human_answer = $parsed_atts['human_answer'];
    $math_sum = $parsed_atts['human_sum'];
    $sell_price = $parsed_atts['sell_price'];

    //Set the time zone for the auction
    date_default_timezone_set("America/Denver");
    //Assign current server time (which is a unix timestamp), adjusted for time zone, to a variable.
    $now = new DateTime();
    //Convert the auction START shortcode attribute (which is a date/time string) to a unix timestamp and assign to a variable.
LINE 272———->>  $auction_start = new DateTime("$auc_start");
    //Convert the auction END shortcode attribute (which is a date/time string) to a unix timestamp and assign to a variable.
    $auction_end = new DateTime("$auc_end");

Это то, что я передаю в шорткоде:

[jwp_auction auc_start=“2020-02-28 16:15:00" auc_end=“2020-03-01 16:15:00”]

Это содержимое журнала отладки:

[28-Feb-2020 16:27:02 America/Denver] PHP Fatal error:  
Uncaught Exception: DateTime::__construct(): 
Failed to parse time string (“2020-02-28) at position 0 (�):
 Unexpected character in 
/var/www/html/wp-content/plugins/jwp_functionality_plugin/jwp_functionality_plugin.php:272

Stack trace:
#0 /var/www/html/wp-content/plugins/jwp_functionality_plugin/jwp_functionality_plugin.php(272): DateTime->__construct('\xE2\x80\x9C2020-02-28')
#1 /var/www/html/wp-includes/shortcodes.php(325): bid_form_display(Array, '', 'jwp_auction')
#2 [internal function]: do_shortcode_tag(Array)
#3 /var/www/html/wp-includes/shortcodes.php(199): preg_replace_callback('/\\[(\\[?)(jwp_au...', 'do_shortcode_ta...', '\n<figure class=...')
#4 /var/www/html/wp-includes/class-wp-hook.php(288): do_shortcode('\n<figure class=...')
#5 /var/www/html/wp-includes/plugin.php(206): WP_Hook->apply_filters('\n<figure class=...', Array)
#6 /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(1550): apply_filters('the_content', '<!-- wp:image {...')
#7 /var/www/html/wp-includes/re in /var/www/html/wp-content/plugins/jwp_functionality_plugin/jwp_functionality_plugin.php on line 272
...