Upgrade to Pro — share decks privately, control downloads, hide ads and more …

functions.phpからプラグインへ

A73ed5cefbbd84abd2c5e14a5eb4a339?s=47 Ippei Sumida
February 26, 2021

 functions.phpからプラグインへ

WP ZoomUP 59『はじめてのプラグイン作成』でお話ししたスライドです。

#WordPress #WPZoomUP

A73ed5cefbbd84abd2c5e14a5eb4a339?s=128

Ippei Sumida

February 26, 2021
Tweet

Transcript

  1. Ippei Sumida 2020.02.26 functions.php͔ΒϓϥάΠϯ΁ ϓϥάΠϯΛ࡞ͬͯΈΑ͏

  2. ϓϥάΠϯ ςʔϚ functions.php

  3. ϓϥάΠϯ޲͖ͳΧελϚΠζ 
 ɹɹςʔϚ޲͖ͳΧελϚΠζ

  4. • จࣈͷ૷০ • ը૾ͷ૷০ʢnot Ճ޻ʣ • ϨΠΞ΢τͷௐ੔ • ςʔϚݻ༗ͷΧελϜϒϩοΫ •

    ςʔϚͷઃఆ • ͦͷςʔϚͷΧελϚΠζ ςʔϚ޲͖ ςʔϚʹґଘ
  5. • ؅ཧը໘ͷΧελϚΠζ • αΠτઃఆɾػೳͷ௥Ճɾมߋ • γϣʔτίʔυ • ΧςΰϦ • ΧελϜϒϩοΫ

    • REST API • ڞ௨ͳද੍ࣔޚ • ͦͷαΠτͷΧελϚΠζ ϓϥάΠϯ޲͖
  6. ϓϥάΠϯ ςʔϚ functions.php ςʔϚʹؔΘΔ͜ͱ αΠτʹؔΘΔ͜ͱ

  7. ϓϥάΠϯ ςʔϚ functions.php ςʔϚʹؔΘΔ͜ͱ αΠτʹؔΘΔ͜ͱ Ͳͬͪʹॻ͍ͯ΋ಈ͘

  8. ͳͥϓϥάΠϯͳͷ͔

  9. ςʔϚʹґଘ

  10. ΧελϚΠζ ͠Α͏ʂ

  11. ΧελϚΠζ ͠Α͏ʂ functions.php ࡞੒ɾमਖ਼ˍΞοϓϩʔυ

  12. ΧελϚΠζ ͠Α͏ʂ functions.php

  13. ΧελϚΠζ ͠Α͏ʂ functions.php ςʔϚA

  14. ςʔϚม͍͑ͨʂ functions.php ςʔϚA

  15. ςʔϚม͍͑ͨʂ functions.php ςʔϚB functions.php ςʔϚA

  16. ςʔϚม͍͑ͨʂ functions.php ςʔϚB functions.php ςʔϚA ΧελϚΠζ͕ফ͑Δʂ

  17. functions.php ίϐʔʂ functions.php ςʔϚB functions.php ίϐʔ

  18. functions.php ίϐʔʂ functions.php ςʔϚB functions.php ίϐʔ ςʔϚBݻ༗ͷΧελϚΠζ͕ 
 ফ͑Δʂ

  19. ΧελϚΠζ ՕॴҠ২ʂ functions.php ςʔϚB functions.php Ҡ২

  20. ΧελϚΠζ ՕॴҠ২ʂ functions.php ςʔϚB functions.php Ҡ২ ΧελϚΠζͨ͠Օॴ͚ͩ 
 Ҡ২Ͱ͖Δࣗ৴͋Δʁ

  21. None
  22. ΧελϚΠζͯ͠ ࡞ͬͨؔ਺

  23. ςʔϚͷؔ਺Λ ࢖ͬͯΔ

  24. ΧελϚΠζ ͠Α͏ʂ plugin.php ࡞੒ɾमਖ਼ˍΞοϓϩʔυ ϓϥάΠϯC

  25. ΧελϚΠζ ͠Α͏ʂ plugin.php ϓϥ΢ΠϯC

  26. ςʔϚม͍͑ͨʂ functions.php ςʔϚB functions.php ςʔϚA plugin.php ϓϥ΢ΠϯC αΠτʹӨڹͳ͠

  27. functions.php͔Β 
 ϓϥάΠϯ΁

  28. ྫɿμογϡϘʔυɹɹ ɹɹ΢ΟδΣοτ

  29. wp-content/themes/some-theme/functions.php

  30. ϓϥάΠϯ ςʔϚ functions.php μογϡϘʔυͷ΢ΟδΣοτ͸ςʔϚ͕ มΘͬͯ΋දࣔ͠ଓ͚ΔʰαΠτͷΧελϚΠζʱ ςʔϚʹؔΘΔ͜ͱ αΠτʹؔΘΔ͜ͱ

  31. Ͱ΋Ή͔͍ͣ͠ΜͰ͠ΐʁ

  32. ϓϥάΠϯ࡞੒ɺ࣮͸͜Μͳʹ؆୯ʂ MajiͰKantan 5εςοϓ 1.ϓϥάΠϯσΟϨΫτϦΛ࡞Δ 2.readme.txtΛࢦఆͷϑΥʔϚοτͰͭ͘Δ 3.[ϓϥάΠϯσΟϨΫτϦ໊].phpʹࢦఆͷϑΥʔϚοτͰίϝϯτΛॻ͘ 4.ίʔυΛॻ͘ •functions.phpͷίʔυΛΧοτˍϖʔετ͢Δ 5.ϓϥάΠϯσΟϨΫτϦΛΞοϓϩʔυ͢Δ •ߋ৽͍ͯ͠Ε͹ɺςʔϚͷfunctions.php΋Ξοϓϩʔυ͢Δ

  33. 1. ϓϥάΠϯσΟϨΫτϦΛ࡞Δ

  34. wp-content plugins dashboard-widget σΟϨΫτϦΛͭ͘Δʂ ऴ ੍࡞ɾஶ࡞ ━━━━━ ⡹⡲⡼

  35. •wp-content/plugins/ ʹ͓޷Έͷ໊͓લͰ •খจࣈͱϋΠϑϯͱ਺ࣈͷ૊Έ߹Θ͕ͤແ೉ •ඞͣҰҙʹͳΔΑ͏ʹʂʂ wp-content plugins dashboard-widget σΟϨΫτϦΛͭ͘Δʂ ิ଍

  36. 2. readme.txtΛͭ͘Δ

  37. ެࣜʹαϯϓϧ͋Δ

  38. 3. PHPʹίϝϯτΛॻ͘

  39. wp-content plugins dashboard-widget σΟϨΫτϦͱಉҰ໊ͷPHPϑΝΠϧΛ࡞Δ dashboard-widget.php

  40. ࠷௿ݶ͸͜Ε͚ͩʂ

  41. ެࣜʹαϯϓϧ͋Δ

  42. 4. ίʔυΛॻ͘ લʹ

  43. PHPίʔσΟϯάن໿ΛकΖ͏ʂ WordPressʹ͸ίʔσΟϯάن໿ʢ= ॻ͖ํʣ͕͋ΓɺͦΕʹैͬͯ ίʔσΟϯά͢Δඞཁ͕͋Γ·͢ɻॻ͖ํ͕౷Ұ͞Εͨίʔυ͸Մಡ ੑ͕ൈ܈ʹ্͕Γ·͢ɻʢ※ 3ϲ݄લͷࣗ෼͸ଞਓʣ ίʔσΟϯάن໿͸HTML, CSS, JavaScript, PHP͝ͱʹܾ·͍ͬͯ·

    ͢ɻެࣜͷυΩϡϝϯτʹهड़ํ๏͕ެ։͞Ε͍ͯ·͢ɻ
  44. ؓ࿩ٳ୊ ※ ݸਓͷײ૝Ͱ͢

  45. ϑϨʔϜϫʔΫ ίʔσΟϯάن໿ Laravel PSR-2 Symfony PSR-12 (PSR-2ͷ֦ு) ϕʔε CakePHP PSR-2

    Yii PSR-2 ओཁPHPϑϨʔϜϫʔΫͷίʔσΟϯάن໿
  46. PSR PHP Standard Recommendation

  47. PHP-FIG PHP Framework Interoperability Group

  48. PHPʹؔ͢Δʰ͓࡞๏ʱΛܾΊ͍ͯΔάϧʔϓ https://www.php- fi g.org

  49. ࠷ۙͷPHP͸΄ͱΜͲɺ 
 PSR-2͔PSR-12

  50. WordPress͸ʁ

  51. ಠࣗ

  52. None
  53. None
  54. ͳΜͰ΍ʁ

  55. ؓ࿩ٳ୊͓ΘΓ

  56. 4. ίʔυΛॻ͘

  57. wp-content/themes/some-theme/functions.php

  58. wp-content/themes/some-theme/functions.php ʘ Χοτ! ʗ

  59. wp-content/plugins/dashboard-widget/dashboard-widget.php

  60. ʘ ϖʔετ! ʗ wp-content/plugins/dashboard-widget/dashboard-widget.php

  61. ׬ ऴ ੍࡞ɾஶ࡞ ━━━━━ ⡹⡲⡼

  62. ิ଍

  63. wp-content/plugins/tutorial-widget/tutorial-widget.php ҰҙʹͳΔΑ͏ʹʂ ※઀಄ࣙʹϓϥάΠϯ໊ೖΕΔͱΑ͍ ※Ϋϥεͷϝιου໊͸ͷͧ͘

  64. 5. Ξοϓϩʔυ͢Δ લʹ

  65. ಈ࡞֬ೝͯ͠Ξοϓϩʔυ͍ͨ͠

  66. wp-env @wordpress/env

  67. WordPress։ൃ؀ڥΛ
 αΫοͱ࡞Δ΍΂ʔ΍ͭ Hi!

  68. http://localhost:8888
 ID: admin
 PW: password ΅͘͸yarn೿ʂ

  69. wp-envͷ͕͜͜ਪ͠ϙΠϯτ • ϩʔΧϧʹ͸npmʢyarnʣͱDocker͕͋Ε͹͍͍ • ෳ਺ϓϩδΣΫτ͋ͬͯ΋ɺผ෺ѻ͍Ͱ͖Δ • ʢ࡞੒࣌͸ʣৗʹ·ͬ͞Β • ͍ͭͰ΋͜ΘͤΔ •

    Dockerͷϩΰ͔Θ͍͍ • yarn΋͔Θ͍͍ υϠΝ!
  70. ࣗಈͰΠϯετʔϧࡁΈ ཁΞΫςΟϕʔτ

  71. None
  72. 5. Ξοϓϩʔυ͢Δ

  73. wp-content plugins dashboard-widget σΟϨΫτϦΛ·ΔͬͱΞοϓϩʔυʂ dashboard-widget.php

  74. wp-content themes some-theme functions.phpΛίϐϖͯͨ͠ΒςʔϚ΋ functions.php

  75. ཁΞΫςΟϕʔτ

  76. None
  77. ࢀߟɿ΅͘ͳΒ

  78. None
  79. ͜͏࡞Δ

  80. ͕࣌ؒ͋Ε͹આ໌

  81. Conclusion • functions.phpʹ͸ςʔϚͷΧελϚΠζɺ
 ϓϥάΠϯʹ͸αΠτͷΧελϚΠζΛهड़͢Δ • ϓϥάΠϯ࡞੒ʹඞཁͳͷ͸ɺͨͬͨͷ5εςοϓ • ίʔσΟϯάن໿ΛकΖ͏ • άϩʔόϧͳ΋ͷʹ͸Ұҙͳ໊લΛ͚ͭΔ

    • wp-env͸ਆɻςʔϚ࡞੒ʹ΋࢖͑ΔΑ
  82. ֯ా Ұฏ Web Developer Freelance @ippey_s ͢Έͩɹ͍ͬ΃͍