SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
Erfahrungsbericht
aus der Plugin-Entwicklung
Nico Danneberg [ @nida78 ]
Inhalt
• me, myself & WP
• Plugins in WP
– Interaktion mit WP
• Backend für Plugins
– Integration mit mehreren Plugins
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 2
about.me/nida78
Ich…
• 37J-v-2K
• Unternehmer
• Entwickler
• Dozent
• Netzwerker
• Sportler
…und WordPress
• 2004
– eigener Blog
• 2011
– erstes WP-Projekt bei
VCAT
• 2012
– #wpdm += @nida78
• 2013
– VCAT EDULABS mit WP-
Plugin für Geo-Locations
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 3
Plugins in WP
• Basis / Grundlagen / Einführung
– Bernhards Workshop [ @2ndKauBoy ]
– codex.wordpress.org/Writing_a_Plugin
• Unterm Strich
– Datei im Verzeichnis /wp-content/plugins
– Ordner möglich, meist auch sinnvoll
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 4
Beispiel
vcat-reverse-text.php
<?php
/*
Plugin Name: VCAT Reverse Text
Plugin URI: http://www.vcat.de/edulabs/projekte/wordpress/reverse-text/
Description: Dieses Plugin dreht Text um :)
Version: 0.0.1
Author: VCAT Consulting GmbH (Nico Danneberg)
Author URI: http://www.vcat.de
*/
…
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 5
Interaktion 1
Actions
• Liste aller Action Hooks verfügbar
– http://codex.wordpress.org/Plugin_API/Action_Reference
• Wichtige Funktionen:
– add_action
– remove_action
– has_action
– did_action
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 6
Beispiel Actions
vcat-reverse-text.php
function vrt_save_post( $post_id ) {
$title = get_the_title( $post_id );
add_post_meta( $post_id, "vcat_reverse_title",
strrev( $title ), true );
}
add_action( 'save_post', 'vrt_save_post' );
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 7
Interaktion 2
Filters
• Liste aller Filters verfügbar
– http://codex.wordpress.org/Plugin_API/Filter_Reference
• Wichtige Funktionen:
– add_filter
– remove_filter
– has_filter
– apply_filters
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 8
Beispiel Filters
vcat-reverse-text.php
function vrt_reverse_title( $title, $id = null ) {
return ( is_admin() ) ? $title : strrev( $title );
}
add_filter( 'the_title', 'vrt_reverse_title' );
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 9
Interaktion 3
Shortcodes
• Shortcode API verfügbar
– https://codex.wordpress.org/Shortcode_API
• Wichtige Funktionen:
– add_shortcode
– remove_shortcode
– do_shortcode
– shortcode_atts
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 10
Beispiel Shortcode
vcat-reverse-text.php
function vrt_reverse_shortcode( $atts, $content = "" ) {
$atts = shortcode_atts( array( 'bold' => false ),
$atts, 'reverse' );
if( $atts[ 'bold' ] ) {
return "<strong>" . strrev( $content ) . "</strong>";
} else {
return strrev( $content );
}
}
add_shortcode( 'reverse', 'vrt_reverse_shortcode' );
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 11
Beispiel Shortcode
Editor & Ausgabe
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 12
Eigenes Plugin-Backend
• Eintrag im Menü erzeugen
add_menu_page( 'VCAT EDULABS', // Titel der Seite
'VCAT EDULABS', // Titel im Menü
'manage_options', // Rolle
'vcat-options', // Slug
'vcat_core_options_page', // Funktion
'images/favicon.ico', // Icon
26 // Position
);
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 13
Eigenes Plugin-Backend
• Funktion mit Leben füllen
function vcat_core_main_options_page() {
echo '<div class="wrap vcat-edulabs">';
screen_icon( 'vcat-edulabs' );
echo '<h2>VCAT EDULABS Optionen</h2>';
/*** TODO ***/
• Eigene Optionen über Settings
verwalten
– http://codex.wordpress.org/Settings_API
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 14
Hauptseite
für mehrere Plugins
• Untermenü erzeugen
– Funktion add_submenu_page() erwartet
„parent_slug“
• Gemeinsame Funktionen definieren
– Menü, Seite, Kopf & Fuß, (rechte) Sidebar
• Kern auslagern & einbinden
– Unterordner, eigenes Plugin, o.ä.
– Prüfen, ob Funktion bereits vorhanden
if( !function_exists( 'vcat_core_create_main…' ) ) {
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 15
Gemeinsame Startseite
für mehrere Plugins
• Jedes Plugin benutzt einen Filter…
add_filter( 'vcat_plugins_list',
'vcat_geo_add_plugins_list_info' );
• …und schreibt Daten in ein Array
function vcat_geo_add_plugins_list_info( $list ) {
array_push( $list, array(
'name' => 'VCAT EDULABS Posts at Google Maps (GEO-Plugin)',
'image' => plugins_url( 'vcat-posts-google-maps.png', __FILE__ ),
'settings' => 'admin.php?page=vcat_geo_settings'
) );
return $list;
}
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 16
Gemeinsame Startseite
für mehrere Plugins
• Hauptseite ruft die Filter der Plugins…
$vcat_plugins_data = apply_filters(
'vcat_plugins_list', array() );
• …und wertet die Rückgabe aus
if( sizeof( $vcat_plugins_data ) == 0 ) {
/*** Schade, nix da! ***/
} else {
foreach( $vcat_plugins_data as $vcat_plugin ) {
/*** Ausgaben pro Plugin ***/
}
}
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 17
Fragen? Fragen!
privat
• M nico@danneberg.de
• W n1da.net
• T @nida78
dienstlich
• M nico.danneberg@vcat.de
• W vcat.de
• T @VCATconsulting
21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 18

Más contenido relacionado

Destacado

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destacado (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

#wpdm - Erfahrungsbericht aus der Plugin-Entwicklung

  • 2. Inhalt • me, myself & WP • Plugins in WP – Interaktion mit WP • Backend für Plugins – Integration mit mehreren Plugins 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 2
  • 3. about.me/nida78 Ich… • 37J-v-2K • Unternehmer • Entwickler • Dozent • Netzwerker • Sportler …und WordPress • 2004 – eigener Blog • 2011 – erstes WP-Projekt bei VCAT • 2012 – #wpdm += @nida78 • 2013 – VCAT EDULABS mit WP- Plugin für Geo-Locations 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 3
  • 4. Plugins in WP • Basis / Grundlagen / Einführung – Bernhards Workshop [ @2ndKauBoy ] – codex.wordpress.org/Writing_a_Plugin • Unterm Strich – Datei im Verzeichnis /wp-content/plugins – Ordner möglich, meist auch sinnvoll 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 4
  • 5. Beispiel vcat-reverse-text.php <?php /* Plugin Name: VCAT Reverse Text Plugin URI: http://www.vcat.de/edulabs/projekte/wordpress/reverse-text/ Description: Dieses Plugin dreht Text um :) Version: 0.0.1 Author: VCAT Consulting GmbH (Nico Danneberg) Author URI: http://www.vcat.de */ … 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 5
  • 6. Interaktion 1 Actions • Liste aller Action Hooks verfügbar – http://codex.wordpress.org/Plugin_API/Action_Reference • Wichtige Funktionen: – add_action – remove_action – has_action – did_action 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 6
  • 7. Beispiel Actions vcat-reverse-text.php function vrt_save_post( $post_id ) { $title = get_the_title( $post_id ); add_post_meta( $post_id, "vcat_reverse_title", strrev( $title ), true ); } add_action( 'save_post', 'vrt_save_post' ); 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 7
  • 8. Interaktion 2 Filters • Liste aller Filters verfügbar – http://codex.wordpress.org/Plugin_API/Filter_Reference • Wichtige Funktionen: – add_filter – remove_filter – has_filter – apply_filters 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 8
  • 9. Beispiel Filters vcat-reverse-text.php function vrt_reverse_title( $title, $id = null ) { return ( is_admin() ) ? $title : strrev( $title ); } add_filter( 'the_title', 'vrt_reverse_title' ); 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 9
  • 10. Interaktion 3 Shortcodes • Shortcode API verfügbar – https://codex.wordpress.org/Shortcode_API • Wichtige Funktionen: – add_shortcode – remove_shortcode – do_shortcode – shortcode_atts 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 10
  • 11. Beispiel Shortcode vcat-reverse-text.php function vrt_reverse_shortcode( $atts, $content = "" ) { $atts = shortcode_atts( array( 'bold' => false ), $atts, 'reverse' ); if( $atts[ 'bold' ] ) { return "<strong>" . strrev( $content ) . "</strong>"; } else { return strrev( $content ); } } add_shortcode( 'reverse', 'vrt_reverse_shortcode' ); 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 11
  • 12. Beispiel Shortcode Editor & Ausgabe 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 12
  • 13. Eigenes Plugin-Backend • Eintrag im Menü erzeugen add_menu_page( 'VCAT EDULABS', // Titel der Seite 'VCAT EDULABS', // Titel im Menü 'manage_options', // Rolle 'vcat-options', // Slug 'vcat_core_options_page', // Funktion 'images/favicon.ico', // Icon 26 // Position ); 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 13
  • 14. Eigenes Plugin-Backend • Funktion mit Leben füllen function vcat_core_main_options_page() { echo '<div class="wrap vcat-edulabs">'; screen_icon( 'vcat-edulabs' ); echo '<h2>VCAT EDULABS Optionen</h2>'; /*** TODO ***/ • Eigene Optionen über Settings verwalten – http://codex.wordpress.org/Settings_API 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 14
  • 15. Hauptseite für mehrere Plugins • Untermenü erzeugen – Funktion add_submenu_page() erwartet „parent_slug“ • Gemeinsame Funktionen definieren – Menü, Seite, Kopf & Fuß, (rechte) Sidebar • Kern auslagern & einbinden – Unterordner, eigenes Plugin, o.ä. – Prüfen, ob Funktion bereits vorhanden if( !function_exists( 'vcat_core_create_main…' ) ) { 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 15
  • 16. Gemeinsame Startseite für mehrere Plugins • Jedes Plugin benutzt einen Filter… add_filter( 'vcat_plugins_list', 'vcat_geo_add_plugins_list_info' ); • …und schreibt Daten in ein Array function vcat_geo_add_plugins_list_info( $list ) { array_push( $list, array( 'name' => 'VCAT EDULABS Posts at Google Maps (GEO-Plugin)', 'image' => plugins_url( 'vcat-posts-google-maps.png', __FILE__ ), 'settings' => 'admin.php?page=vcat_geo_settings' ) ); return $list; } 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 16
  • 17. Gemeinsame Startseite für mehrere Plugins • Hauptseite ruft die Filter der Plugins… $vcat_plugins_data = apply_filters( 'vcat_plugins_list', array() ); • …und wertet die Rückgabe aus if( sizeof( $vcat_plugins_data ) == 0 ) { /*** Schade, nix da! ***/ } else { foreach( $vcat_plugins_data as $vcat_plugin ) { /*** Ausgaben pro Plugin ***/ } } 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 17
  • 18. Fragen? Fragen! privat • M nico@danneberg.de • W n1da.net • T @nida78 dienstlich • M nico.danneberg@vcat.de • W vcat.de • T @VCATconsulting 21.04.2015 WP Meetup Potsdam - Erfahrungsbericht aus der Plugin-Entwicklung 18