SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Coolfields Consulting www.coolfields.co.uk
@coolfields
Handling user-generated content
in WordPress
Graham Armfield
Web Accessibility Consultant
WordPress Developer
graham.armfield@coolfields.co.uk
@coolfields
What I’m going to cover
A way to allow your site visitors to add
content for your WordPress site – without
giving them a logon.
2
What you want to avoidAn example – a gig listing site
But could be used for -
Job Board, For Sale
Site, Etc
4
What you want to avoid
Adding all the gigs yourself
5
Advantages
More time for the important things
6
Advantages
People could be more engaged with your site
First steps
• Create a new post type – my_gig
• Create a form on a page template
• For a gig, typical information might be:
• Band name
• Band information
• Gig venue
• Gig date
• Gig time
7
It's also sensible to collect
details on the person submitting
the event – name, email, etc
People will try to spam you
Preventing spam
9
Use a simple logic
puzzle or sum to fool
the bots.
Don’t use a CAPTCHA
– they’re a usability
and accessibility
nightmare.
Security
Your server side validation needs to be good –
remember the data submitted is going straight into
your database.
Storing the information
After validation (of course)
$postAdd = array();
$postAdd['post_title'] = $clean['bandname'];
$postAdd['post_content'] = $clean['bandinfo'];
$postAdd['post_type'] = 'my_gig';
$postAdd['post_status'] = 'draft';
$gigId = wp_insert_post($postAdd);
11
Storing the custom fields
Check for success and store the other details
if ($gigId > 0) {
// Insert successful - write the custom fields
update_post_meta($gigId, 'gig_submitter_name',
$clean['submittername']);
update_post_meta($gigId, 'gig_submitter_email',
$clean['submitteremail']);
update_post_meta($gigId, 'gig_date',
$clean['startdate']);
etc...
}
12
Storing any images
What about image uploads – a photo of the band as a
featured image?
if ($_FILES and (!empty($clean['eventimg']))) {
foreach ($_FILES as $file => $array) {
$newupload =
insert_attachment($file, $gigId);
}
}
$newupload gets the attachment id of the file that was just
uploaded. Do whatever you want with that now.
13
Storing any images
function insert_attachment($file_handler,$post_id) {
//upload successful?
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) {
__return_false();
}
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload($file_handler, $post_id );
// Make this image the post thumbnail
update_post_meta($post_id,'_thumbnail_id',$attach_id);
// Return the ID of the attached image
return $attach_id;
}
14
Approving gigs
Deciding which ones to publish
Approval page
• Create in admin area or private page on front end
• Display each gig in turn
• Three buttons
• Approve
• Edit Required
• Delete
16
Approval or edit required
$postAdd = array();
$postAdd['ID'] = $gigId;
if ( $approved ) {
$postAdd['post_status'] = 'publish';
}
if ( $editReqd ) {
$postAdd['post_status'] = 'pending';
}
wp_update_post($postAdd);
17
Delete it
wp_delete_post( $gigId, true );
The second parameter determines whether the post is
deleted outright (true) or is moved to trash (false).
18
Thanks for listening
graham.armfield@coolfields.co.uk
@coolfields

Weitere ähnliche Inhalte

Ähnlich wie Handling User Generated Content in WordPress

PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
Firebase_not_really_yohoho
Firebase_not_really_yohohoFirebase_not_really_yohoho
Firebase_not_really_yohohoRoman Sachenko
 
Keeping It Small with Slim
Keeping It Small with SlimKeeping It Small with Slim
Keeping It Small with SlimRaven Tools
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkJeremy Kendall
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumberBachue Zhou
 
Drupal 8 configuration system for coders and site builders - Drupalaton 2013
Drupal 8 configuration system for coders and site builders - Drupalaton 2013Drupal 8 configuration system for coders and site builders - Drupalaton 2013
Drupal 8 configuration system for coders and site builders - Drupalaton 2013swentel
 
Firebase not really_yohoho
Firebase not really_yohohoFirebase not really_yohoho
Firebase not really_yohohoDA-14
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018Adam Tomat
 
Scaling business app development with Play and Scala
Scaling business app development with Play and ScalaScaling business app development with Play and Scala
Scaling business app development with Play and ScalaPeter Hilton
 
Parsing in ios to create an app
Parsing in ios to create an appParsing in ios to create an app
Parsing in ios to create an appHeaderLabs .
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkJeremy Kendall
 
PyCon APAC - Django Test Driven Development
PyCon APAC - Django Test Driven DevelopmentPyCon APAC - Django Test Driven Development
PyCon APAC - Django Test Driven DevelopmentTudor Munteanu
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Marko Heijnen
 
When you need more data in less time...
When you need more data in less time...When you need more data in less time...
When you need more data in less time...Bálint Horváth
 
NZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSNZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSCam Findlay
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonPyCon Italia
 

Ähnlich wie Handling User Generated Content in WordPress (20)

PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
Firebase_not_really_yohoho
Firebase_not_really_yohohoFirebase_not_really_yohoho
Firebase_not_really_yohoho
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Keeping It Small with Slim
Keeping It Small with SlimKeeping It Small with Slim
Keeping It Small with Slim
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 
Qpsmtpd
QpsmtpdQpsmtpd
Qpsmtpd
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
Drupal 8 configuration system for coders and site builders - Drupalaton 2013
Drupal 8 configuration system for coders and site builders - Drupalaton 2013Drupal 8 configuration system for coders and site builders - Drupalaton 2013
Drupal 8 configuration system for coders and site builders - Drupalaton 2013
 
Firebase not really_yohoho
Firebase not really_yohohoFirebase not really_yohoho
Firebase not really_yohoho
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
Scaling business app development with Play and Scala
Scaling business app development with Play and ScalaScaling business app development with Play and Scala
Scaling business app development with Play and Scala
 
2015 akure gdg dev fest
2015 akure gdg dev fest2015 akure gdg dev fest
2015 akure gdg dev fest
 
Parsing in ios to create an app
Parsing in ios to create an appParsing in ios to create an app
Parsing in ios to create an app
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
PyCon APAC - Django Test Driven Development
PyCon APAC - Django Test Driven DevelopmentPyCon APAC - Django Test Driven Development
PyCon APAC - Django Test Driven Development
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
When you need more data in less time...
When you need more data in less time...When you need more data in less time...
When you need more data in less time...
 
NZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSNZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMS
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
 

Mehr von Graham Armfield

Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Graham Armfield
 
So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...Graham Armfield
 
Useful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonUseful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonGraham Armfield
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2Graham Armfield
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2Graham Armfield
 
Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Graham Armfield
 
How to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeHow to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeGraham Armfield
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Graham Armfield
 
Useful Accessibility Tools
Useful Accessibility ToolsUseful Accessibility Tools
Useful Accessibility ToolsGraham Armfield
 
Assistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolAssistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolGraham Armfield
 
Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Graham Armfield
 
Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Graham Armfield
 
Obscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite UsefulObscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite UsefulGraham Armfield
 
Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Graham Armfield
 
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Graham Armfield
 
So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?Graham Armfield
 
WordPress and Web Accessibility - 2013
WordPress and Web Accessibility - 2013WordPress and Web Accessibility - 2013
WordPress and Web Accessibility - 2013Graham Armfield
 
Beginners Guide To Web Accessibility - WordCamp UK July 2013
Beginners Guide To Web Accessibility - WordCamp UK July 2013Beginners Guide To Web Accessibility - WordCamp UK July 2013
Beginners Guide To Web Accessibility - WordCamp UK July 2013Graham Armfield
 
Simple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress ThemeSimple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress ThemeGraham Armfield
 
WordPress and Web Accessibility - TCUK 2012
WordPress and Web Accessibility - TCUK 2012WordPress and Web Accessibility - TCUK 2012
WordPress and Web Accessibility - TCUK 2012Graham Armfield
 

Mehr von Graham Armfield (20)

Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021
 
So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...
 
Useful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonUseful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp Brighton
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2
 
Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019
 
How to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeHow to Build an Accessible WordPress Theme
How to Build an Accessible WordPress Theme
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018
 
Useful Accessibility Tools
Useful Accessibility ToolsUseful Accessibility Tools
Useful Accessibility Tools
 
Assistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolAssistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp Bristol
 
Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017
 
Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016
 
Obscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite UsefulObscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite Useful
 
Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015
 
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
 
So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?
 
WordPress and Web Accessibility - 2013
WordPress and Web Accessibility - 2013WordPress and Web Accessibility - 2013
WordPress and Web Accessibility - 2013
 
Beginners Guide To Web Accessibility - WordCamp UK July 2013
Beginners Guide To Web Accessibility - WordCamp UK July 2013Beginners Guide To Web Accessibility - WordCamp UK July 2013
Beginners Guide To Web Accessibility - WordCamp UK July 2013
 
Simple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress ThemeSimple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress Theme
 
WordPress and Web Accessibility - TCUK 2012
WordPress and Web Accessibility - TCUK 2012WordPress and Web Accessibility - TCUK 2012
WordPress and Web Accessibility - TCUK 2012
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Kürzlich hochgeladen (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Handling User Generated Content in WordPress

  • 1. Coolfields Consulting www.coolfields.co.uk @coolfields Handling user-generated content in WordPress Graham Armfield Web Accessibility Consultant WordPress Developer graham.armfield@coolfields.co.uk @coolfields
  • 2. What I’m going to cover A way to allow your site visitors to add content for your WordPress site – without giving them a logon. 2
  • 3. What you want to avoidAn example – a gig listing site But could be used for - Job Board, For Sale Site, Etc
  • 4. 4 What you want to avoid Adding all the gigs yourself
  • 5. 5 Advantages More time for the important things
  • 6. 6 Advantages People could be more engaged with your site
  • 7. First steps • Create a new post type – my_gig • Create a form on a page template • For a gig, typical information might be: • Band name • Band information • Gig venue • Gig date • Gig time 7 It's also sensible to collect details on the person submitting the event – name, email, etc
  • 8. People will try to spam you
  • 9. Preventing spam 9 Use a simple logic puzzle or sum to fool the bots. Don’t use a CAPTCHA – they’re a usability and accessibility nightmare.
  • 10. Security Your server side validation needs to be good – remember the data submitted is going straight into your database.
  • 11. Storing the information After validation (of course) $postAdd = array(); $postAdd['post_title'] = $clean['bandname']; $postAdd['post_content'] = $clean['bandinfo']; $postAdd['post_type'] = 'my_gig'; $postAdd['post_status'] = 'draft'; $gigId = wp_insert_post($postAdd); 11
  • 12. Storing the custom fields Check for success and store the other details if ($gigId > 0) { // Insert successful - write the custom fields update_post_meta($gigId, 'gig_submitter_name', $clean['submittername']); update_post_meta($gigId, 'gig_submitter_email', $clean['submitteremail']); update_post_meta($gigId, 'gig_date', $clean['startdate']); etc... } 12
  • 13. Storing any images What about image uploads – a photo of the band as a featured image? if ($_FILES and (!empty($clean['eventimg']))) { foreach ($_FILES as $file => $array) { $newupload = insert_attachment($file, $gigId); } } $newupload gets the attachment id of the file that was just uploaded. Do whatever you want with that now. 13
  • 14. Storing any images function insert_attachment($file_handler,$post_id) { //upload successful? if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) { __return_false(); } require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $attach_id = media_handle_upload($file_handler, $post_id ); // Make this image the post thumbnail update_post_meta($post_id,'_thumbnail_id',$attach_id); // Return the ID of the attached image return $attach_id; } 14
  • 15. Approving gigs Deciding which ones to publish
  • 16. Approval page • Create in admin area or private page on front end • Display each gig in turn • Three buttons • Approve • Edit Required • Delete 16
  • 17. Approval or edit required $postAdd = array(); $postAdd['ID'] = $gigId; if ( $approved ) { $postAdd['post_status'] = 'publish'; } if ( $editReqd ) { $postAdd['post_status'] = 'pending'; } wp_update_post($postAdd); 17
  • 18. Delete it wp_delete_post( $gigId, true ); The second parameter determines whether the post is deleted outright (true) or is moved to trash (false). 18