{"id":717,"date":"2013-07-02T06:27:27","date_gmt":"2013-07-02T06:27:27","guid":{"rendered":"http:\/\/musilda.cz\/?p=717"},"modified":"2013-07-02T06:27:27","modified_gmt":"2013-07-02T06:27:27","slug":"automaticka-instalace-pluginu-vyzadovanych-sablonou","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/automaticka-instalace-pluginu-vyzadovanych-sablonou\/","title":{"rendered":"Automatick\u00e1 instalace plugin\u016f vy\u017eadovan\u00fdch \u0161ablonou"},"content":{"rendered":"

Vytv\u00e1\u0159\u00edte vlastn\u00ed \u0161ablony, d\u011bl\u00e1te na zak\u00e1zku, nebo publikujete free vzhledy pro redak\u010dn\u00ed syst\u00e9m WordPress? Ur\u010dit\u011b jste se dostali do situace, kdy jste museli klientovi, nebo komukoliv jin\u00e9mu, kdo chce va\u0161i \u0161ablonu pou\u017e\u00edt, \u017ee aby se mu ty obr\u00e1zky h\u00fdbali stejn\u011b jako na demu, mus\u00ed si nainstalovat takov\u00fd a takov\u00fd plugin. M\u00e1m pro v\u00e1s tip na zaj\u00edmavou t\u0159\u00eddu, pomoc\u00ed kter\u00e9 jednodu\u0161e roz\u0161\u00ed\u0159\u00edte funk\u010dnost va\u0161\u00ed \u0161ablony o upozorn\u011bn\u00ed na nutnost instalovat pot\u0159ebn\u00e9 pluginy.<\/p>\n

T\u0159\u00edda se jmenuje TGM plugin activation a najdete ji na Github\u00a0https:\/\/github.com\/thomasgriffin\/TGM-Plugin-Activation<\/a>.<\/p>\n

Pro p\u0159id\u00e1n\u00ed t\u00e9to funk\u010dnosti nemus\u00edte stahovat zip soubor, ale sta\u010d\u00ed jen do slo\u017eky \u0161ablony um\u00edstit soubor class-tgm-plugin-activation.php. P\u0159edpokl\u00e1d\u00e1m, \u017ee v\u011bt\u0161ina z v\u00e1s chce m\u00edt v souborech po\u0159\u00e1dek, tak m\u00e1 v \u0161ablon\u011b slo\u017eku nap\u0159\u00edklad library, kam takov\u00e9 soubory um\u00eds\u0165uje. Na Githubu je tak\u00e9 soubor examples, kde je pops\u00e1na implementace t\u0159\u00eddy a kter\u00fd si doporu\u010duji proj\u00edt.<\/p>\n

Vlo\u017een\u00ed t\u0159\u00eddy a nastaven\u00ed<\/h3>\n

do souboru functions.php mus\u00edme nejprve t\u0159\u00eddu vlo\u017eit, proto do n\u011bj p\u0159id\u00e1me n\u00e1sleduj\u00edc\u00ed \u0159\u00e1dek:<\/p>\n

require_once dirname( __FILE__ ) . '\/library\/class-tgm-plugin-activation.php';<\/pre>\n

Samoz\u0159ejm\u011b, pokud m\u00e1te soubor um\u00edst\u011bn jinde, cesta bude odli\u0161n\u00e1.<\/p>\n

D\u00e1le mus\u00edme zaregistrovat funkci, pomoc\u00ed kter\u00e9 budeme t\u0159\u00eddu aktivovat:<\/p>\n

add_action( 'tgmpa_register', 'my_theme_register_required_plugins' );<\/pre>\n

Vytvo\u0159\u00edme si vlastn\u00ed funkci:<\/p>\n

function my_theme_register_required_plugins() {\n\n}\n<\/pre>\n

A do t\u00e9 za\u010dneme vkl\u00e1dat pot\u0159ebn\u00e9 \u00fadaje. Jako prvn\u00ed vytvo\u0159\u00edme pole, do kter\u00e9ho budeme vkl\u00e1dat jednotliv\u00e9 pluginy:<\/p>\n

\n$plugins = array(\n\narray(\n'name'=> 'Ourplugin',\n'slug'=> 'ourplugin',\n'source'=> get_stylesheet_directory() . '\/includes\/plugins\/our_plugin.zip',\n'required'=> true,\n'version'=> '',\n'force_activation'=> true,\n'force_deactivation'=> false,\n\t\t),\n);\n<\/pre>\n
    \n
  • Name je jm\u00e9no pluginu,<\/li>\n
  • slug je url pluginu v administraci,<\/li>\n
  • source je url zip souboru pluginu, <\/li>\n
  • required znamen\u00e1, \u017ee je plugin vy\u017eadovan\u00fd, pokud jej nastav\u00edte na false, bude jen doporu\u010den\u00fd, <\/li>\n
  • version – pokud ji vypln\u00edte, bude vy\u017eadov\u00e1na stejn\u00e1, nebo vy\u0161\u0161\u00ed verze pluginu,<\/li>\n
  • force_activation znamen\u00e1, \u017ee plugin je aktivovan\u00fd se \u0161ablonou a nejde deaktivovat, dokud je \u0161ablona aktivn\u00ed, <\/li>\n
  • force_deactivation naopak znamen\u00e1 deaktivaci pluginu p\u0159i deaktivaci \u0161ablon.<\/li>\n<\/ul>\n

    Cel\u00e9 pole s hodnotami m\u016f\u017eete opakovat pro tolik plugin\u016f, kolik budete pot\u0159ebovat. Podle toho, jak\u00e9 hodnoty nastav\u00edte, bude se po instalaci \u0161ablony zobrazovat upozorn\u011bn\u00ed, \u017ee jsou pluginy vy\u017eadov\u00e1ny, nebo doporu\u010deny. D\u00e1le se tak\u00e9 u upozorn\u011bn\u00ed zobraz\u00ed odkaz na instalaci a aktivaci plugin\u016f, tak\u017ee u\u017eivatel nemus\u00ed nic hledat. D\u00edky tomu, \u017ee je upozorn\u011bn\u00ed st\u00e1le viditeln\u00e9, bude u\u017eivatel v\u011bd\u011bt, co m\u00e1 d\u011blat.<\/p>\n

    Jako posledn\u00ed krok mus\u00edme do funkce p\u0159idat je\u0161t\u011b konfiguraci, tak\u017ee pod pole, kter\u00e9 jsme si vytvo\u0159ili p\u0159id\u00e1me n\u00e1sleduj\u00edc\u00ed \u0159\u00e1dky:<\/p>\n

    $theme_text_domain = 'tgmpa';<\/pre>\n

    Textovou dom\u00e9nu pro p\u0159\u00edpadn\u00fd p\u0159eklad a pole $config kter\u00e9 m\u016f\u017eete nechat tak jak je a nemus\u00edte na n\u011bm nic m\u011bnit:<\/p>\n

    \n$config = array(\n'domain'       \t\t=> $theme_text_domain,\n'default_path' \t\t=> '',\n'parent_menu_slug' \t=> 'themes.php',\n'parent_url_slug' \t=> 'themes.php',\n'menu'         \t\t=> 'install-required-plugins',\n'has_notices'      \t=> true,\n'is_automatic'    \t=> false,\n'message' \t\t\t=> '',\n'strings'      \t\t=> array(\n'page_title'=> __( 'Install Required Plugins', $theme_text_domain ),\n'menu_title'=> __( 'Install Plugins', $theme_text_domain ),\n'installing'=> __( 'Installing Plugin: %s', $theme_text_domain ), \/\/ %1$s = plugin name\n'oops'=> __( 'Something went wrong with the plugin API.', $theme_text_domain ),\n'notice_can_install_required'=> _n_noop( 'This theme requires the following plugin: %1$s.',\n'This theme requires the following plugins: %1$s.' ),\n'notice_can_install_recommended'=> _n_noop( 'This theme recommends the following plugin: %1$s.',\n'This theme recommends the following plugins: %1$s.' ),\n'notice_cannot_install'=> _n_noop( 'Sorry, but you do not have the correct permissions\nto install the %s plugin. Contact the administrator of this site for help on\ngetting the plugin installed.', 'Sorry, but you do not have the correct permissions\nto install the %s plugins. Contact the administrator of this site for\nhelp on getting the plugins installed.' ),\n'notice_can_activate_required'=> _n_noop( 'The following required plugin is currently\ninactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ),\n'notice_can_activate_recommended'=> _n_noop( 'The following recommended plugin is currently\ninactive: %1$s.', 'The following recommended plugins are currently\ninactive: %1$s.' ),\n'notice_cannot_activate'=> _n_noop( 'Sorry, but you do not have the correct permissions\nto activate the %s plugin. Contact the administrator of this site for help on getting the\nplugin activated.', 'Sorry, but you do not have the correct permissions to\nactivate the %s plugins. Contact the administrator of this site for help on\ngetting the plugins activated.' ),\n'notice_ask_to_update'=> _n_noop( 'The following plugin needs to be updated to its latest\nversion to ensure maximum compatibility with this theme: %1$s.', 'The following plugins\nneed to be updated to their latest version to ensure maximum compatibility\nwith this theme: %1$s.' ),\n'notice_cannot_update'=> _n_noop( 'Sorry, but you do not have the correct permissions to\nupdate the %s plugin. Contact the administrator of this site for help on getting the\nplugin updated.', 'Sorry, but you do not have the correct permissions to update the %s\n plugins. Contact the administrator of this site for help on getting\nthe plugins updated.' ),\n'install_link'=> _n_noop( 'Begin installing plugin', 'Begin installing plugins' ),\n'activate_link'=> _n_noop( 'Activate installed plugin', 'Activate installed plugins' ),\n'return'=> __( 'Return to Required Plugins Installer', $theme_text_domain ),\n'plugin_activated'=> __( 'Plugin activated successfully.', $theme_text_domain ),\n'complete'=> __( 'All plugins installed and activated successfully. %s', $theme_text_domain ),\n'nag_type'=> 'updated'\n\t\t)\n\t);\n<\/pre>\n

    P\u0159esto\u017ee vypad\u00e1 slo\u017eit\u011b, jedn\u00e1 se v\u011bt\u0161inou o v\u00fdpis r\u016fzn\u00fdch upozorn\u011bn\u00ed.<\/p>\n

    Nakonec vlo\u017e\u00edme:<\/p>\n

    tgmpa( $plugins, $config );<\/pre>\n

    Pokud jste v\u0161e ud\u011blali spr\u00e1vn\u011b, po aktivaci va\u0161\u00ed \u0161ablony by se m\u011blo zobrazit upozorn\u011bn\u00ed na nutnost instalace definovan\u00fdch plugin\u016f. <\/p>\n","protected":false},"excerpt":{"rendered":"

    Vytv\u00e1\u0159\u00edte vlastn\u00ed \u0161ablony, d\u011bl\u00e1te na zak\u00e1zku, nebo publikujete free vzhledy pro redak\u010dn\u00ed syst\u00e9m WordPress? Ur\u010dit\u011b jste se dostali do situace, kdy jste museli klientovi, nebo komukoliv jin\u00e9mu, kdo chce va\u0161i \u0161ablonu pou\u017e\u00edt, \u017ee aby se mu ty obr\u00e1zky h\u00fdbali stejn\u011b jako na demu, mus\u00ed si nainstalovat takov\u00fd a takov\u00fd plugin. M\u00e1m pro v\u00e1s tip na<\/p>\n","protected":false},"author":1,"featured_media":8624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[12],"tags":[505],"class_list":["post-717","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","tag-wordpress-pluginy"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/717"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=717"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/717\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8624"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}