{"id":231181,"date":"2022-12-21T12:29:00","date_gmt":"2022-12-21T09:29:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=231181"},"modified":"2022-12-07T10:29:52","modified_gmt":"2022-12-07T07:29:52","slug":"vidzheti-wordpress-refaktoring-chastina-11","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/uk\/vidzheti-wordpress-refaktoring-chastina-11\/","title":{"rendered":"\u0412\u0456\u0434\u0436\u0435\u0442\u0438 WordPress: \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433, \u0447\u0430\u0441\u0442\u0438\u043d\u0430 11"},"content":{"rendered":"\n<p>\u0423 \u043f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u0456\u0439 \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0457 \u043c\u0438 \u043f\u0440\u043e\u0439\u0448\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u0433\u0430\u0442\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0443, \u044f\u043a\u0438\u0439 \u0440\u043e\u0437\u0434\u0456\u043b\u0438\u0432 \u043a\u043e\u043d\u0446\u0435\u0440\u043d\u0438 \u043d\u0430 \u0432\u043b\u0430\u0441\u043d\u0456 \u043a\u043b\u0430\u0441\u0438.<\/p>\n<p>\u0417\u0440\u0435\u0448\u0442\u043e\u044e, \u0446\u0435 \u0434\u043e\u043f\u043e\u043c\u0430\u0433\u0430\u0454 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0438, \u044f\u043a \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u043f\u0456\u0434\u0442\u0440\u0438\u043c\u0443\u0432\u0430\u0442\u0438 \u0432\u0438\u0441\u043e\u043a\u0438\u0439 \u0440\u0456\u0432\u0435\u043d\u044c \u0437\u0433\u0443\u0440\u0442\u043e\u0432\u0430\u043d\u043e\u0441\u0442\u0456, \u043d\u0435 \u043b\u0438\u0448\u0435 \u043f\u0440\u0430\u0446\u044e\u044e\u0447\u0438 \u0437 \u043a\u043b\u0430\u0441\u0430\u043c\u0438 \u0432 WordPress, \u0430\u043b\u0435 \u0439 \u0440\u043e\u0431\u043b\u044f\u0447\u0438 \u0446\u0435 \u0440\u0430\u0437\u043e\u043c \u0456\u0437 \u0443\u0436\u0435 \u0456\u0441\u043d\u0443\u044e\u0447\u0438\u043c\u0438 API.<\/p>\n<p>\u041e\u0441\u043a\u0456\u043b\u044c\u043a\u0438 \u043a\u0456\u043b\u044c\u043a\u0430 \u043e\u0441\u0442\u0430\u043d\u043d\u0456\u0445 \u0434\u043e\u043f\u0438\u0441\u0456\u0432 \u043f\u0440\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u0430\u0437\u0438 \u043a\u043e\u0434\u0443 \u0431\u0443\u043b\u0438 \u0434\u0443\u0436\u0435 \u0434\u043e\u0432\u0433\u0438\u043c\u0438, \u043f\u043e\u0442\u043e\u0447\u043d\u0438\u0439 \u043d\u0430\u0431\u0456\u0440 \u0434\u043e\u043f\u0438\u0441\u0456\u0432 \u0437\u043e\u0441\u0435\u0440\u0435\u0434\u0436\u0435\u043d\u043e \u043d\u0430 \u043d\u0435\u0432\u0435\u043b\u0438\u043a\u0438\u0445, \u043f\u043e\u0441\u0442\u0443\u043f\u043e\u0432\u0438\u0445 \u0437\u043c\u0456\u043d\u0430\u0445 \u0456, \u043e\u0442\u0436\u0435, \u043a\u043e\u0440\u043e\u0442\u0448\u0438\u0445, \u0431\u0456\u043b\u044c\u0448 \u0437\u043e\u0441\u0435\u0440\u0435\u0434\u0436\u0435\u043d\u0438\u0445.<\/p>\n<p>\u042f\u043a \u0437\u0433\u0430\u0434\u0443\u0432\u0430\u043b\u043e\u0441\u044f \u0432 \u043f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u0456\u0439 \u0441\u0442\u0430\u0442\u0442\u0456:<\/p>\n<blockquote>\n<p>\u0410\u043b\u0435 \u044f\u043a\u0449\u043e \u0432\u0438 \u043e\u043d\u043e\u0432\u0438\u0442\u0435 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043c\u0456\u0442\u0438\u0442\u0438, \u0449\u043e \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u0442\u0430 \u0441\u0435\u0440\u0456\u0430\u043b\u0456\u0437\u0430\u0446\u0456\u044f \u043d\u0435 \u043f\u0440\u0430\u0446\u044e\u044e\u0442\u044c \u043f\u0456\u0434 \u0447\u0430\u0441 \u043e\u0442\u0440\u0438\u043c\u0430\u043d\u043d\u044f \u0434\u0430\u043d\u0438\u0445. \u0406 \u0441\u0430\u043c\u0435 \u0446\u0435 \u043c\u0438 \u0440\u043e\u0437\u0433\u043b\u044f\u043d\u0435\u043c\u043e \u0432 \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0456\u0439 \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0457.<\/p>\n<\/blockquote>\n<p>\u041e\u0441\u044c \u0447\u043e\u043c\u0443 \u043c\u0438 \u0437\u0431\u0438\u0440\u0430\u0454\u043c\u043e\u0441\u044f \u0437\u0443\u043f\u0438\u043d\u0438\u0442\u0438\u0441\u044f \u0432 \u0446\u0456\u0439 \u0441\u0442\u0430\u0442\u0442\u0456.<\/p>\n<h2>\u0428\u0430\u0431\u043b\u043e\u043d \u0432\u0456\u0434\u0436\u0435\u0442\u0430 WordPress: \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433, \u0447\u0430\u0441\u0442\u0438\u043d\u0430 11<\/h2>\n<p>\u041f\u0435\u0440\u0448 \u043d\u0456\u0436 \u043f\u0438\u0441\u0430\u0442\u0438 \u0431\u0443\u0434\u044c-\u044f\u043a\u0438\u0439 \u043a\u043e\u0434, \u043f\u0435\u0440\u0448\u0435, \u043d\u0430 \u0449\u043e \u0441\u043b\u0456\u0434 \u0437\u0432\u0435\u0440\u043d\u0443\u0442\u0438 \u0443\u0432\u0430\u0433\u0443, \u0446\u0435 \u0442\u0435, \u0449\u043e \u044f\u043a\u0449\u043e \u0432\u0438 \u0437\u0430\u043f\u043e\u0432\u043d\u044e\u0454\u0442\u0435 \u043e\u0434\u043d\u0443 \u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u0432\u043c\u0456\u0441\u0442\u0443 \u0432\u0456\u0434\u0436\u0435\u0442\u0430 (\u043d\u0430\u043f\u0440\u0438\u043a\u043b\u0430\u0434, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a) \u0447\u0438\u043c\u043e\u0441\u044c <a href=\"https:\/\/gist.github.com\/tommcfarlin\/39038338730b7141a19c3d2f48801dac#file-00-example-title-js\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u043e\u0434\u0456\u0431\u043d\u0438\u043c \u0434\u043e \u0446\u044c\u043e\u0433\u043e<\/a> :<\/p>\n<pre><code>&lt;script type=\"text\/javascript\"&gt;This is the Title&lt;\/script&gt;<\/code><\/pre>\n<p>\u0410 \u043f\u043e\u0442\u0456\u043c \u043d\u0430\u0442\u0438\u0441\u043d\u0456\u0442\u044c \u00ab\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438\u00bb, \u0444\u0430\u043a\u0442\u0438\u0447\u043d\u0438\u0439 \u0432\u043c\u0456\u0441\u0442 \u0431\u0443\u0434\u0435 \u043e\u0447\u0438\u0449\u0435\u043d\u043e \u0442\u0430 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u0438\u0445. \u0412\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u0446\u0435 \u043f\u0440\u0430\u0432\u0434\u0430, \u043f\u043e\u0434\u0438\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044f \u0432\u0456\u0434\u0436\u0435\u0442\u0430 \u0432 \u0431\u0430\u0437\u0456 \u0434\u0430\u043d\u0438\u0445.<\/p>\n<p>\u041a\u0440\u0456\u043c \u0442\u043e\u0433\u043e, \u043d\u0430 \u043f\u0435\u0440\u0448\u0438\u0439 \u043f\u043e\u0433\u043b\u044f\u0434 \u0434\u0430\u043d\u0456 \u0432\u0438\u0433\u043b\u044f\u0434\u0430\u044e\u0442\u044c \u0434\u043e\u0431\u0440\u0435, \u0430\u043b\u0435 \u044f\u043a\u0449\u043e \u0432\u0438 \u043e\u043d\u043e\u0432\u0438\u0442\u0435 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0437&#8217;\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043e\u0447\u0438\u0449\u0435\u043d\u0438\u0439 \u0432\u043c\u0456\u0441\u0442. \u042f\u043a\u0449\u043e \u0432\u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442\u0435 \u043d\u0430 \u0456\u043d\u0448\u0443 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u044f\u043a-\u043e\u0442 \u043c\u0435\u043d\u044e, \u0430 \u043f\u043e\u0442\u0456\u043c \u043f\u043e\u0432\u0435\u0440\u043d\u0435\u0442\u0435\u0441\u044c, \u0432\u043c\u0456\u0441\u0442 \u0432\u0456\u0434\u0436\u0435\u0442\u0430 \u0437\u2019\u044f\u0432\u0438\u0442\u044c\u0441\u044f, \u0430\u043b\u0435 \u0431\u0443\u0434\u0435 \u043d\u0430\u043b\u0435\u0436\u043d\u0438\u043c \u0447\u0438\u043d\u043e\u043c \u043e\u0447\u0438\u0449\u0435\u043d\u043e.<\/p>\n<p>\u0427\u043e\u043c\u0443 \u0442\u043e\u0434\u0456 \u043f\u0456\u0434 \u0447\u0430\u0441 \u0432\u0438\u043a\u043e\u043d\u0430\u043d\u043d\u044f \u043f\u0435\u0432\u043d\u0438\u0445 \u043a\u0440\u043e\u043a\u0456\u0432 \u0432\u0456\u043d \u043f\u043e\u043a\u0430\u0437\u0443\u0454 \u043e\u0434\u043d\u0435 \u0432 \u0431\u0430\u0437\u0456 \u0434\u0430\u043d\u0438\u0445 \u0456 \u043e\u0434\u043d\u0435 \u0432 \u0456\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0456 \u043e\u0431\u043b\u0430\u0441\u0442\u0456 \u0430\u0434\u043c\u0456\u043d\u0456\u0441\u0442\u0440\u0443\u0432\u0430\u043d\u043d\u044f?<\/p>\n<p>\u0426\u0435 \u043f\u043e\u0432\u2019\u044f\u0437\u0430\u043d\u043e \u0437 \u043a\u0435\u0448-\u043f\u0430\u043c\u2019\u044f\u0442\u0442\u044e \u0432\u0456\u0434\u0436\u0435\u0442\u0456\u0432, \u0456, \u043d\u0430 \u0449\u0430\u0441\u0442\u044f, \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u043e\u0447\u0438\u0449\u0430\u0442\u0438 \u0446\u0435\u0439 \u043a\u0435\u0448 \u0437\u0430 \u0432\u043b\u0430\u0441\u043d\u0438\u043c \u0431\u0430\u0436\u0430\u043d\u043d\u044f\u043c, \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e\u0447\u0438 \u0431\u0443\u0434\u044c-\u044f\u043a\u0456 \u043f\u0435\u0440\u0435\u0445\u043e\u043f\u043b\u044e\u0432\u0430\u0447\u0456, \u044f\u043a\u0456 \u0437\u0430\u0431\u0430\u0436\u0430\u0454\u043c\u043e (\u0442\u043e\u0431\u0442\u043e \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u043f\u0456\u0434\u043f\u0438\u0441\u0430\u0442\u0438\u0441\u044f \u043d\u0430 \u0431\u0443\u0434\u044c-\u044f\u043a\u0443 \u043f\u043e\u0434\u0456\u044e, \u0430 \u043f\u043e\u0442\u0456\u043c \u043d\u0430\u0434\u0430\u0442\u0438 \u0457\u0439 \u043e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u043a\u0435\u0448\u0443).<\/p>\n<\/p>\n<p>\u0417 \u043f\u043e\u0441\u0438\u043b\u0430\u043d\u043d\u044f \u043d\u0430 <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_cache_delete\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043a\u043e\u0434<\/a> :<\/p>\n<blockquote>\n<p>\u0412\u0438\u0434\u0430\u043b\u044f\u0454 \u0432\u043c\u0456\u0441\u0442 \u043a\u0435\u0448\u0443, \u044f\u043a\u0438\u0439 \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0430\u0454 \u043a\u043b\u044e\u0447\u0443 \u0442\u0430 \u0433\u0440\u0443\u043f\u0456.<\/p>\n<\/blockquote>\n<p>\u041e\u0434\u043d\u0430\u043a \u0437\u0430\u0443\u0432\u0430\u0436\u0442\u0435, \u0449\u043e \u0434\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u043d\u0430\u0434\u0430\u0442\u0438 \u043a\u043b\u044e\u0447 \u0456 \u043d\u0435\u043e\u0431\u043e\u0432\u2019\u044f\u0437\u043a\u043e\u0432\u0443 \u0433\u0440\u0443\u043f\u0443. \u0423 Boilerplate \u043c\u0438 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u043b\u0438 \u0441\u043b\u0430\u0433 \u0432\u0456\u0434\u0436\u0435\u0442\u0430 \u044f\u043a \u043a\u043b\u044e\u0447, \u0430 \u0433\u0440\u0443\u043f\u0430 \u2014 \u0432\u0456\u0434\u0436\u0435\u0442.<\/p>\n<h3>\u041e\u0447\u0438\u0449\u0435\u043d\u043d\u044f \u043a\u0435\u0448\u0443<\/h3>\n<p>\u041e\u0441\u043a\u0456\u043b\u044c\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0456\u044e \u043c\u043e\u0436\u043d\u0430 \u043f\u0456\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0438 \u0434\u043e \u0431\u0443\u0434\u044c-\u044f\u043a\u043e\u0457 \u043f\u043e\u0434\u0456\u0457, \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u0441\u0442\u0432\u043e\u0440\u0438\u0442\u0438 \u043f\u0456\u0434\u043f\u0438\u0441\u043d\u0438\u043a\u0430, \u044f\u043a\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u0430 \u043f\u0456\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0438 \u0434\u043e \u0431\u0443\u0434\u044c-\u044f\u043a\u043e\u0457 \u043f\u043e\u0434\u0456\u0457. \u0426\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0454 <a href=\"https:\/\/gist.github.com\/tommcfarlin\/39038338730b7141a19c3d2f48801dac#file-01-delete-widget-cache-subscriber-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">, \u0449\u043e \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u0441\u0442\u0432\u043e\u0440\u0438\u0442\u0438 \u043f\u0435\u0440\u0435\u0434\u043f\u043b\u0430\u0442\u043d\u0438\u043a\u0430 DeleteWidgetCache \u0443 \u043d\u0430\u0448\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0456 \u0456\u043c\u0435\u043d Subscriber:<\/a><\/p>\n<pre><code>&lt;?php\n\n&lt;?php\n\n\/*\n * This file is part of WordPress Widget Boilerplate\n * (c) Tom McFarlin &lt;tom@tommcfarlin.com&gt;\n *\n * This source file is subject to the GPL license that is bundled\n * with this source code in the file LICENSE.\n *\/\n\nnamespace WordPressWidgetBoilerplateSubscriber;\n\n\/**\n * Deletes the cached contents of the widget.\n *\/\nclass DeleteWidgetCacheSubscriber extends AbstractSubscriber\n{\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function __construct(string $hook)\n    {\n        parent::__construct($hook);\n    }\n\n    \/**\n     * Flushes the widget's cache based on the key that's specified in the function arguments.\n     *\/\n    public function load()\n    {\n        \/* Because we're implementing an abstract class, we'll parse arguments from the\n         * func_get_args().\n         *\/\n        $args = func_get_args();\n        if (!$this-&gt;hasValidArguments($args)) {\n            return;\n        }\n\n        \/\/ TODO: More to come...\n    }\n\n    \/**\n     * Verifies that we have valid arguments with which to work.\n     *\n     * @param array $args the array of arguments we are validating\n     *\n     * @return bool true if the arguments are valid; otherwise, false\n     *\/\n    private function hasValidArguments(array $args): bool\n    {\n        \/\/ First, check the initial index of the arguments.\n        if (!isset($args[0])) {\n            return false;\n        }\n\n        \/\/ Next, check the values of the arguments for the widget key and group.\n        $args = $args[0];\n        if (!isset($args[0]) &amp;&amp; !isset($args[1])) {\n            return false;\n        }\n\n        return true;\n    }\n}\n<\/code><\/pre>\n<p>\u041f\u043e\u0442\u0456\u043c \u043c\u0438 <a href=\"https:\/\/gist.github.com\/tommcfarlin\/39038338730b7141a19c3d2f48801dac#file-02-wordpress-widget-plugin-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043e\u043d\u043e\u0432\u0438\u043c\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0443 \u043f\u043e\u0447\u0430\u0442\u043a\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f<\/a>, \u0449\u043e\u0431 \u0434\u043e\u0434\u0430\u0442\u0438 \u043f\u0456\u0434\u043f\u0438\u0441\u043d\u0438\u043a\u0430 \u0434\u043e \u0440\u0435\u0454\u0441\u0442\u0440\u0443, \u0456 \u043c\u0438 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u0430\u0454\u043c\u043e \u0441\u043f\u0435\u0446\u0456\u0430\u043b\u044c\u043d\u0438\u0439 \u0445\u0443\u043a, flush_widget_cache, \u044f\u043a\u0438\u0439 \u043c\u0438 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u0430\u0454\u043c\u043e \u043c\u0438\u0442\u0442\u0454\u0432\u043e.<\/p>\n<pre><code>&lt;?php\n\/**\n * WordPress Widget Boilerplate\n *\n * The WordPress Widget Boilerplate is an organized, maintainable boilerplate for building\n * widgets using WordPress best practices.\n *\n * @package   WordPressWidgetBoilerplate\n * @author    Your Name &lt;email@example.com&gt;\n * @license   GPL-3.0+\n * @link      http:\/\/example.com\n * @copyright 2018 - 2019 Your Name or Company Name\n *\n * @wordpress-plugin\n * Plugin Name:       WordPress Widget Boilerplate\n * Plugin URI:        https:\/\/github.com\/tommcfarlin\/wordpress-widget-boilerplate\n * Description:       An object-oriented foundation for building WordPress Widgets.\n * Version:           1.0.0\n * Author:            Tom McFarlin\n * Author URI:        https:\/\/tommcfarlin.com\n * Text Domain:       widget-name\n * License:           GPL-3.0+\n * License URI:       http:\/\/www.gnu.org\/licenses\/gpl-3.0.txt\n * Domain Path:       \/lang\n *\/\n\nnamespace WordPressWidgetBoilerplate;\n\nuse WordPressWidgetBoilerplateUtilitiesRegistry;\nuse WordPressWidgetBoilerplatePlugin;\nuse WordPressWidgetBoilerplateSubscriberWidgetSubscriber;\nuse WordPressWidgetBoilerplateSubscriberDeleteWidgetCacheSubscriber;\n\n\/\/ Prevent this file from being called directly.\ndefined('WPINC') || die;\n\n\/\/ Include the autoloader.\nrequire_once __DIR__. '\/vendor\/autoload.php';\n\n\/\/ Setup a filter so we can retrieve the registry throughout the plugin.\n$registry = new Registry();\nadd_filter('wpwBoilerplateRegistry', function() use ($registry) {\n    return $registry;\n});\n\n\/\/ Add subscribers.\n$registry-&gt;add('deleteWidgetCacheSubscriber', new DeleteWidgetCacheSubscriber('flush_widget_cache'));\n\n\/\/ Add the Widget base class to the Registry.\n$registry-&gt;add('widgetSubscriber', new WidgetSubscriber('widgets_init'));\n\n\/\/ Start the machine.\n(new Plugin($registry))-&gt;start();\n<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0446\u0456\u043b\u0435\u0439 Boilerplate \u043c\u0438 \u0431\u0443\u0434\u0435\u043c\u043e \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u0442\u0438 \u0441\u043f\u0435\u0446\u0456\u0430\u043b\u044c\u043d\u0443 \u043f\u043e\u0434\u0456\u044e \u043a\u043e\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0443, \u043a\u043e\u043b\u0438 \u0431\u0443\u0434\u0435 \u0432\u0438\u043a\u043b\u0438\u043a\u0430\u043d\u043e \u043a\u043e\u0434 \u0441\u0435\u0440\u0456\u0430\u043b\u0456\u0437\u0430\u0446\u0456\u0457 \u0432\u0456\u0434\u0436\u0435\u0442\u0430.<\/p>\n<p>\u0421\u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u043c\u0438 \u0432\u0438\u0437\u043d\u0430\u0447\u0438\u043c\u043e\u00a0 \u0432\u0438\u043a\u043b\u0438\u043a <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/do_action\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">do_action<\/a>, \u0432\u0438\u0437\u043d\u0430\u0447\u0438\u043c\u043e \u0439\u043e\u0433\u043e \u044f\u043a flush_widget_cache, \u0430 \u043f\u043e\u0442\u0456\u043c <a href=\"https:\/\/gist.github.com\/tommcfarlin\/39038338730b7141a19c3d2f48801dac#file-03-widget-serialization-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u0435\u0440\u0435\u0434\u0430\u043c\u043e \u043d\u0435\u043e\u0431\u0445\u0456\u0434\u043d\u0456 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0438<\/a> \u043f\u043e\u0434\u0456\u0457, \u0449\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u043f\u043b\u0430\u0442\u043d\u0438\u043a \u043c\u0456\u0433 \u0457\u0445 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u0438:<\/p>\n<pre><code>&lt;?php\n\n\/*\n * This file is part of WordPress Widget Boilerplate\n * (c) Tom McFarlin &lt;tom@tommcfarlin.com&gt;\n *\n * This source file is subject to the GPL license that is bundled\n * with this source code in the file LICENSE.\n *\/\n\nnamespace WordPressWidgetBoilerplateWordPress;\n\n\/**\n * Santiizes and saves the data for the widget.\n *\/\nclass WidgetSerializer\n{\n    \/**\n     * @var string a reference to the slug of the widget to which the serialier is associated\n     *\/\n    private $widgetSlug;\n\n    \/**\n     * Initializes the class.\n     *\n     * @param string a reference to the slug of the widget to which the serialier is associated\n     *\/\n    public function __construct(string $widgetSlug)\n    {\n        $this-&gt;widgetSlug = $widgetSlug;\n    }\n\n    \/**\n     * Updates the values of the widget. Sanitizes the information before saving it.\n     *\n     * @param array $newInstance the array of new options to save\n     *\/\n    public function update($newInstance)\n    {\n        $instance = [];\n        foreach ($newInstance as $key =&gt; $value) {\n            $instance[$key] = strip_tags(\n                stripslashes($value)\n            );\n        }\n\n        do_action('flush_widget_cache', [$this-&gt;widgetSlug, 'widget']);\n\n        return $instance;\n    }\n}\n<\/code><\/pre>\n<p>\u0410 \u043f\u043e\u0442\u0456\u043c \u0443 \u043f\u0456\u0434\u043f\u0438\u0441\u043d\u0438\u043a\u0443 <a href=\"https:\/\/gist.github.com\/tommcfarlin\/39038338730b7141a19c3d2f48801dac#file-04-delete-widget-cache-subscriber-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043c\u0438 \u043e\u0447\u0438\u0441\u0442\u0438\u043c\u043e \u043a\u0435\u0448<\/a> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0456 \u0432\u0445\u0456\u0434\u043d\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0456\u0432:<\/p>\n<pre><code>&lt;?php\n\n&lt;?php\n\n\/*\n * This file is part of WordPress Widget Boilerplate\n * (c) Tom McFarlin &lt;tom@tommcfarlin.com&gt;\n *\n * This source file is subject to the GPL license that is bundled\n * with this source code in the file LICENSE.\n *\/\n\nnamespace WordPressWidgetBoilerplateSubscriber;\n\n\/**\n * Deletes the cached contents of the widget.\n *\/\nclass DeleteWidgetCacheSubscriber extends AbstractSubscriber\n{\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function __construct(string $hook)\n    {\n        parent::__construct($hook);\n    }\n\n    \/**\n     * Flushes the widget's cache based on the key that's specified in the function arguments.\n     *\/\n    public function load()\n    {\n        \/* Because we're implementing an abstract class, we'll parse arguments from the\n         * func_get_args().\n         *\/\n        $args = func_get_args();\n        if (!$this-&gt;hasValidArguments($args)) {\n            return;\n        }\n\n        $args = $args[0];\n        wp_cache_delete($args[0], $args[1]);\n    }\n\n    \/**\n     * Verifies that we have valid arguments with which to work.\n     *\n     * @param array $args the array of arguments we are validating\n     *\n     * @return bool true if the arguments are valid; otherwise, false\n     *\/\n    private function hasValidArguments(array $args): bool\n    {\n        \/\/ First, check the initial index of the arguments.\n        if (!isset($args[0])) {\n            return false;\n        }\n\n        \/\/ Next, check the values of the arguments for the widget key and group.\n        $args = $args[0];\n        if (!isset($args[0]) &amp;&amp; !isset($args[1])) {\n            return false;\n        }\n\n        return true;\n    }\n}\n<\/code><\/pre>\n<p>\u0406 \u0446\u0435 \u0440\u043e\u0431\u0438\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u0413\u043e\u0442\u043e\u0432\u0438\u0439 \u0434\u043e Front-End<\/h2>\n<p>\u041d\u0430 \u0434\u0430\u043d\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443 \u043d\u0430\u0441 \u0454 \u043c\u0435\u0445\u0430\u043d\u0456\u0437\u043c, \u044f\u043a\u0438\u0439 \u043c\u043e\u0436\u0435 \u043e\u0447\u0438\u0449\u0430\u0442\u0438 \u043a\u0435\u0448 \u0432\u0456\u0434\u0436\u0435\u0442\u0456\u0432 \u0443 \u0431\u0443\u0434\u044c-\u044f\u043a\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u043d\u0435 \u043b\u0438\u0448\u0435 \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u0441\u043f\u0435\u0446\u0456\u0430\u043b\u044c\u043d\u043e\u0457 \u043f\u043e\u0434\u0456\u0457 \u2014 \u0430\u043b\u0435 \u0439 \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u0431\u0443\u0434\u044c-\u044f\u043a\u043e\u0457 \u043f\u043e\u0434\u0456\u0457, \u0437\u0430\u043f\u0440\u043e\u043f\u043e\u043d\u043e\u0432\u0430\u043d\u043e\u0457 WordPress.<\/p>\n<p>\u0426\u0435 \u043c\u043e\u0436\u0435 \u0441\u0442\u0430\u0442\u0438 \u0432 \u043d\u0430\u0433\u043e\u0434\u0456, \u044f\u043a\u0449\u043e \u0432\u0438 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0454\u0442\u0435 Boilerplate \u0434\u043b\u044f \u0447\u043e\u0433\u043e\u0441\u044c, \u0449\u043e \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u0442\u0438\u043c\u0435 \u043a\u0435\u0448\u043e\u0432\u0430\u043d\u0438\u0439 \u0437\u0430\u043f\u0438\u0442 \u0430\u0431\u043e \u0431\u0443\u0434\u044c-\u044f\u043a\u0438\u0439 \u0456\u043d\u0448\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0456\u0437\u043c \u043a\u0435\u0448\u0443\u0432\u0430\u043d\u043d\u044f, \u044f\u043a\u0449\u043e \u043d\u0430 \u0442\u0435 \u043f\u0456\u0448\u043b\u043e, \u0456 \u0445\u043e\u0447\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u0432\u043c\u0456\u0441\u0442 \u0437\u0440\u043e\u0437\u0443\u043c\u0456\u043b\u0438\u0439.<\/p>\n<p>\u0414\u0430\u043b\u0456 \u043c\u0438 \u0440\u043e\u0437\u0433\u043b\u044f\u043d\u0435\u043c\u043e \u0432\u0456\u0434\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f \u0432\u043c\u0456\u0441\u0442\u0443 \u043d\u0430 \u0456\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0456. \u041c\u0438 \u043d\u0430\u0431\u043b\u0438\u0436\u0430\u0454\u043c\u043e\u0441\u044c \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0443 Boilerplate, \u0430\u043b\u0435 \u0437\u0430\u043b\u0438\u0448\u0438\u043b\u043e\u0441\u044f \u0449\u0435 \u0442\u0440\u043e\u0445\u0438 \u0437\u0440\u043e\u0431\u0438\u0442\u0438, \u043f\u0435\u0440\u0448 \u043d\u0456\u0436 \u043c\u0438 \u0431\u0443\u0434\u0435\u043c\u043e \u0433\u043e\u0442\u043e\u0432\u0456 \u043e\u0431\u2019\u0454\u0434\u043d\u0430\u0442\u0438 \u0439\u043e\u0433\u043e \u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u044e \u0433\u0456\u043b\u043a\u043e\u044e \u043a\u043e\u0434\u043e\u0432\u043e\u0457 \u0431\u0430\u0437\u0438.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0414\u0436\u0435\u0440\u0435\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0443:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/tommcfarlin.com\" class=\"external external_icon\">tommcfarlin.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0427\u043e\u043c\u0443 \u0442\u043e\u0434\u0456 WordPress \u043f\u043e\u043a\u0430\u0437\u0443\u0454 \u043e\u0434\u043d\u0435 \u0432 \u0431\u0430\u0437\u0456 \u0434\u0430\u043d\u0438\u0445 \u0456 \u043e\u0434\u043d\u0435 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0456 \u0430\u0434\u043c\u0456\u043d\u0456\u0441\u0442\u0440\u0443\u0432\u0430\u043d\u043d\u044f? \u0426\u0435 \u043f\u043e\u0432\u2019\u044f\u0437\u0430\u043d\u043e \u0437 \u043a\u0435\u0448-\u043f\u0430\u043c\u2019\u044f\u0442\u0442\u044e \u0432\u0456\u0434\u0436\u0435\u0442\u0456\u0432.<\/p>\n","protected":false},"author":1,"featured_media":235955,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[839,902,725],"tags":[1174],"class_list":["post-231181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kerivnytstvo-dlia-pochatkivtsiv","category-kod-3","category-rozrobnyk","tag-affiai-uk"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/231181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/comments?post=231181"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/231181\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media\/235955"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media?parent=231181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/categories?post=231181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/tags?post=231181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}