{"id":164249,"date":"2015-03-15T14:38:16","date_gmt":"2015-03-15T14:38:16","guid":{"rendered":"https:\/\/ru.wordpress.org\/support\/2015\/03\/15\/%d0%9d%d0%b5-%d0%b7%d0%b0%d0%bf%d1%83%d1%81%d0%ba%d0%b0%d0%b5%d1%82%d1%81%d1%8f-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d1%8f-%d0%bf%d0%be-%d0%ba%d1%80%d0%be%d0%bd%d1%83\/"},"modified":"2015-03-15T14:38:16","modified_gmt":"2015-03-15T14:38:16","slug":"%d0%9d%d0%b5-%d0%b7%d0%b0%d0%bf%d1%83%d1%81%d0%ba%d0%b0%d0%b5%d1%82%d1%81%d1%8f-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d1%8f-%d0%bf%d0%be-%d0%ba%d1%80%d0%be%d0%bd%d1%83","status":"closed","type":"topic","link":"https:\/\/ru.wordpress.org\/support\/topic\/%d0%9d%d0%b5-%d0%b7%d0%b0%d0%bf%d1%83%d1%81%d0%ba%d0%b0%d0%b5%d1%82%d1%81%d1%8f-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d1%8f-%d0%bf%d0%be-%d0%ba%d1%80%d0%be%d0%bd%d1%83\/","title":{"rendered":"\u041d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e \u043a\u0440\u043e\u043d\u0443"},"content":{"rendered":"<p>\u041f\u0438\u0448\u0443 \u043f\u0430\u0440\u0441\u0435\u0440 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043e\u043f\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0449\u0443\u044e \u0433\u0430\u043b\u043e\u0447\u043a\u0443.<\/p>\n<pre><code>function bgp_add_options_page() {\n    add_options_page(&#039;\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u0430&#039;, &#039;\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u0430&#039;, 8, &#039;bgp_settings_page&#039;, &#039;bgp_options_page&#039;);\n}\nadd_action(&#039;admin_menu&#039;, &#039;bgp_add_options_page&#039;);\n\nfunction bgp_register_settings() {\n    add_settings_section(&#039;bgp_settings_section&#039;, &#039;&#039;, &#039;&#039;, __FILE__);\n\n    register_setting(&#039;bgp_settings_group&#039;, &#039;bgp_auto_parse_enable&#039;, &#039;bgp_settings_scheduler&#039;);\n\n    $field_params = array(\n        &#039;name&#039; =&gt; &#039;bgp_auto_parse_enable&#039;,\n        &#039;type&#039; =&gt; &#039;checkbox&#039;\n    );\n    add_settings_field(&#039;bgp_auto_parse_enable&#039;, &#039;\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433&#039;, &#039;bgp_display_settings&#039;, __FILE__, &#039;bgp_settings_section&#039;, $field_params);\n}\nadd_action(&#039;admin_init&#039;, &#039;bgp_register_settings&#039;);\n\nfunction bgp_display_settings($params) {\n    extract($params);\n    $val = get_option($name);\n\n    switch($type) {\n        case &#039;checkbox&#039;:\n            $checked = $val ? &#039;checked=&quot;checked&quot;&#039; : &#039;&#039;;\n            echo &quot;&lt;input type=\\&quot;checkbox\\&quot; name=\\&quot;$name\\&quot; $checked \/&gt;&quot;;\n            break;\n    }\n}\n\nfunction bgp_settings_sanitize_checkbox($input) {\n    return $input == &#039;on&#039; ? 1 : 0;\n}\n\nfunction bgp_settings_scheduler($input) {\n    $input = bgp_settings_sanitize_checkbox($input);\n    if ($input) {\n        if (!wp_next_scheduled(&#039;bgp_new_posts_scheduler&#039;)) {\n            wp_schedule_event(time() + 10, &#039;ten_min&#039;, &#039;bgp_new_posts_scheduler&#039;);\n        }\n    } else {\n        if (wp_next_scheduled(&#039;bgp_new_posts_scheduler&#039;)) {\n            wp_clear_scheduled_hook(&#039;bgp_new_posts_scheduler&#039;);\n        }\n    }\n    return $input;\n}\n\nfunction bgp_options_page() {\n?&gt;\n    &lt;div class=&quot;wrap&quot;&gt;\n        &lt;h2&gt;\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438&lt;\/h2&gt;\n        &lt;br \/&gt;\n        &lt;form action=&quot;options.php&quot; method=&quot;post&quot;&gt;\n            &lt;?php settings_fields(&#039;bgp_settings_group&#039;); ?&gt;\n            &lt;?php do_settings_sections(__FILE__); ?&gt;\n            &lt;?php submit_button(); ?&gt;\n        &lt;\/form&gt;\n    &lt;\/div&gt;\n&lt;?php\n}\n\nfunction bgp_get_new_posts() {\nif (!wp_next_scheduled(&#039;bgp_new_posts_scheduler&#039;)) {\n        wp_schedule_event(time() + 10, &#039;ten_min&#039;, &#039;bgp_new_posts_scheduler&#039;);\n    }\n\n    \/\/\/ ... \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 ...\n\n}\n\nadd_filter( &#039;cron_schedules&#039;, &#039;cron_add_ten_min&#039; );\nfunction cron_add_ten_min( $schedules ) {\n    $schedules[&#039;ten_min&#039;] = array(\n        &#039;interval&#039; =&gt; 60 * 10,\n        &#039;display&#039; =&gt; &#039;\u0420\u0430\u0437 \u0432 10 \u043c\u0438\u043d\u0443\u0442&#039;\n    );\n    return $schedules;\n}\n\nadd_action(&#039;bgp_new_posts_scheduler&#039;, &#039;bgp_get_new_posts&#039;);<\/code><\/pre>\n<p>\u041d\u043e \u0430\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u0434\u0443\u043c\u0430\u043b, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 wp cron, \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b \u0435\u0433\u043e<\/p>\n<pre><code>define(&#039;DISABLE_WP_CRON&#039;, true);\ndefine(&#039;ALTERNATE_WP_CRON&#039;, false);<\/code><\/pre>\n<p>\u0430 \u0432 crontab \u0434\u043e\u0431\u0430\u0432\u0438\u043b:<br \/>\n<code>*\/1 * * * * php5 -q \/home\/artem\/www\/wordpress\/wp-cron.php<\/code><\/p>\n<p>\u0438 \u0442\u0430\u043a<br \/>\n<code>*\/1 * * * * wget -q -O \u2014 http:\/\/localhost\/wordpress\/wp-cron.php?doing_wp_cron &gt;\/dev\/null 2&gt;&amp;<\/code><\/p>\n<p>\u041d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u043e. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u043a\u0440\u043e\u043d\u0435 \u0438\u043b\u0438 \u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u044e? \u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n","protected":false},"template":"","class_list":["post-164249","topic","type-topic","status-closed","hentry","topic-tag-cron","topic-tag-29","topic-tag-plugin"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/164249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/164249\/revisions"}],"wp:attachment":[{"href":"https:\/\/ru.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=164249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}