Ja, vēlies izveidot pats savu WordPress spraudni, tad turpini lasīt pamācību par to, kā izveidot WordPress spraudni un pamēģini pats savus spēkus vienkārša WordPress spraudņa izveidē.
Kas Tev nepieciešams?
- Koda redaktors (piemēram, Xcode, SublimeText, Notepad utt).
- Uzstādīta WordPress mājas lapa.
- Pieredze PHP programmēšanā.
Galvenā faila izveide
Sāc ar to, ka izdomā kāds būs spraudņa nosaukums. Spraudņa nosaukumam jābūt unikālam, tas nedrīkst būt tāds pats kā kādam citam spraudnim WordPress repozitorijā.
Izveido galveno spraudņa php failu un nosaukumā ievieto spraudņa nosaukumu, piemēram mans-spraudnis.php. Faila nosaukumā nedrīkst būt apakšsvītras, izmanto domuzīmes. Izveido mapi, ko nosauc tāpat kā galveno failu, piemēram mans-spraudnis un ievieto failu mapē. Visus spraudņa failus saglabā spraudņa mapē.
Readme
Izveido readme.txt failu. Vari izmantot automātsiko readme failu ģeneratoru GenerateWP.
Faila galvenes pievienošana galvenajam failam
Obligāts nosacījums, ir, ka spraudnim, jāsatur viens php fails, kas galvenē satur spraudņa komentāru galvenē:
Plugin Name: unikāls spraudņa nosaukums
Plugin URI: http://saite uz spraudņa mājas lapu
Description: Apraksts par spraudni
Version: 1.0
Author: Tavs vārds
Author URI: http://saite uz Tavu mājas lapu
License: GPL2
License URI: http://saite uz spraudņa licensi
*/
Ja spraudnī ir vairāki php faili, tad spraudņa komentārs drīkst būt tikai vienā php failā. Ja savam spraudnim izmantosi GPL2 licensi, tad pievieno galvenē šādu licenses informāciju:
/* Copyright YEAR PLUGIN_AUTHOR_NAME (email : your email address)
(Plugin Name) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
(Plugin Name) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with (Plugin Name). If not, see (http://link to your plugin license).
*/
Pēc visu failu izveides, izveido arhīvu no savas spraudņa mapes mans-spraudnis.zip.
Spraudņa izveides piemērs – pamācība
Lai gūtu aptuvenu priekšstatu par WordPress spraudņu izveides pamatiem, izveidosim spraudni, kas katras ziņas un lapas (sadaļas) apakšā pievienos tekstu.
Atver koda redaktoru, izveido php failu ar nosaukumu mans-spraudnis.php. Atver šo failu un ievieto failā šo informāciju (Pie autora rakstiet savu vārdu (Author) un pie autora saites (Author URI), ievietojiet saiti uz savu vietni):
/* Plugin Name: Mans spraudnis Plugin URI: http://dgwebfactory.com Description: Šis spraudnis, katras WordPress ziņas beigās pievienos tekstu. Version: 1.0 Author: Dagnija Author URI: http://dgwebfactory.com License: GPL2 etc License URI: https://link to your plugin license Copyright 2020 Dagnija (email : jusuepasta@adrese.lv) Mans spraudnis is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version. Mans spraudnis is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with (Plugin Name). If not, see (http://link to your plugin license). */
Saglabā failu un pievieno funkciju, kas ievietos tekstu:
function my_footer_text( $content ) { $content .= '<footer class="my-content-footer">Satura veidotājs neatbild par faktu patiesumu </footer>'; return $content; } add_filter( 'the_content', 'my_footer_text' ); ?>





