{"id":5423,"date":"2020-01-31T17:33:31","date_gmt":"2020-01-31T17:33:31","guid":{"rendered":"https:\/\/musilda.cz\/?p=5423"},"modified":"2020-01-31T17:33:31","modified_gmt":"2020-01-31T17:33:31","slug":"action-scheduler","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/action-scheduler\/","title":{"rendered":"Action scheduler"},"content":{"rendered":"\n
WP Cron a Action Scheduler jsou dva zp\u016fsoby, jak ve WordPressu pl\u00e1novat \u00falohy. Prvn\u00ed z nich je obsa\u017een\u00fd ve WordPressu a druh\u00fd je distribuov\u00e1n s WooCommerce. <\/p>\n\n\n\n
O to com co je a jak funguje WP Cron<\/a> jsem ji\u017e psal d\u0159\u00edve. Dnes se pod\u00edv\u00e1me, jak funguje Action Scheduler. <\/p>\n\n\n\n V p\u0159\u00edpad\u011b, \u017ee pou\u017e\u00edv\u00e1te WooCommerce, mohli jste od jist\u00e9 verze zaznamenat v N\u00e1stroj\u00edch novou polo\u017eku nazvanou Scheduled actions. <\/p>\n\n\n\n WooCommerce ji pou\u017e\u00edv\u00e1 na napl\u00e1nov\u00e1n\u00ed \u00faloh, kter\u00e9 chce v budoucnu prov\u00e9st. V n\u011bkter\u00e9m z dal\u0161\u00edch \u010dl\u00e1nc\u00edch budu ps\u00e1t o lookup tabulk\u00e1ch produkt\u016f, v kter\u00fdch jsou nov\u011b ulo\u017eena data produkt\u016f. <\/p>\n\n\n\n Ta byla p\u016fvodn\u011b v postmeta tabulce a v\u00fdvoj\u00e1\u0159i WooCommerce se rozhodli, p\u0159esunout tato data do vlastn\u00ed tabulky. <\/p>\n\n\n\n Ur\u010dit\u011b jste po aktualizaci zaznamenali upozorn\u011bn\u00ed, \u017ee je t\u0159eba prov\u00e9st aktualizaci datab\u00e1ze WooCommerce a kdy\u017e jste aktualizaci spustili, zobrazilo se info, \u017ee aktualizace bude prob\u00edhat na pozad\u00ed. <\/p>\n\n\n\n Pokud by jste se v tu chv\u00edli pod\u00edvali do Scheduled actions, vid\u011bli by jste seznam napl\u00e1novan\u00fdch \u00faloh, s aktualizacemi dat produkt\u016f, nastaven\u00fdch na d\u00e1vky. T\u00edm WooCommerce dos\u00e1hla toho, \u017ee p\u0159esun dat prob\u00edhal postupn\u011b a v\u00fdkon e-shopu to nijak neovlivnilo. <\/p>\n\n\n\n Kdy\u017e si ve WooCommerce pluginu otev\u0159ete slo\u017eku includes\/libraries, najdete knihovnu scheduleru. Krom\u011b toho, \u017ee je knihovna distribuov\u00e1na s Woo, m\u016f\u017eete ji pou\u017e\u00edt jako samostatnou knihovnu do sv\u00e9ho pluginu, nebo jako plugin a ve vlastn\u00edch pluginech, nebo \u0161ablon\u011b jenom pl\u00e1novat \u00falohy. <\/p>\n\n\n\n K \u010demu se d\u00e1 scheduler vyu\u017e\u00edt? WooCommerce p\u0159es n\u011bj pl\u00e1nuje opakovan\u00e9 platby, aktualizace stavu objedn\u00e1vek, e-maily, kter\u00e9 se maj\u00ed odeslat s n\u011bjakou prodlevou, nebo aktualizace datab\u00e1ze po updatu. <\/p>\n\n\n\n Scheduler je dostupn\u00fd na GitHubu, kde si m\u016f\u017eete st\u00e1hnout zip soubor s releasem, kter\u00fd pot\u0159ebujete – https:\/\/github.com\/woocommerce\/action-scheduler\/releases<\/a>. Pak sta\u010d\u00ed aktivovat jako oby\u010dejn\u00fd WordPress plugin.<\/p>\n\n\n\n Dal\u0161\u00ed mo\u017enost\u00ed je vlo\u017eit knihovnu do pluginu, nebo \u0161ablony. Knihovnu pak mus\u00edte v k\u00f3du inicializovat:<\/p>\n\n\n\n Proto\u017ee action scheduler zaregistruje s\u00e1m sebe do hooku plugins_loaded s prioritou 0, vy mus\u00edte zav\u011bsit require souboru do plugins_loaded p\u0159ed prioritu 0, nap\u0159\u00edklad -10 ( negativn\u00ed priorita ). <\/p>\n\n\n\nScheduled Actions<\/h2>\n\n\n\n
Action Scheduler<\/h2>\n\n\n\n
Instalace scheduleru<\/h2>\n\n\n\n
require_once( plugin_dir_path( __FILE__ ) . '\/libraries\/action-scheduler\/action-scheduler.php' );<\/code><\/pre>\n\n\n\n
Pou\u017eit\u00ed scheduleru<\/h2>\n\n\n\n