SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
WORDPRESS 
CUZTOM 
HELPER 
- A helper to make the life of Wordpress developers easier. 
_ Ante Primorac (@anteprimorac) 
_ Web Developer @ Slicejack 
_ 2nd WordPress Meetup Split
WHAT DO WE USE 
CUZTOM FOR? 
_ Post types 
_ Taxonomies 
_ Meta Boxes 
_ Post meta 
_ Term meta 
_ User meta
HOW TO USE CUZTOM? 
1 CLONE REPOSITORY TO INC/CUZTOM/ 
slicejack:inc ante$ git clone https://github.com/gizburdt/wp-cuztom.git cuztom 
2 CREATE CUZTOM.PHP AND LET THE MAGIC BEGIN 
<?php 
define( 'CUZTOM_TEXTDOMAIN', 'slicejack' ); 
define( 'CUZTOM_URL', get_template_directory_uri() . '/inc/cuztom' ); 
require( 'cuztom/cuztom.php' );
BOOKS LIBRARY 
1 CREATE CUSTOM POST TYPE - BOOK 
$books = new Cuztom_Post_Type( 'book', array( 
'has_archive' => true, 
'rewrite' => array( 
'slug' => 'books' 
), 
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ) 
) );
BOOKS LIBRARY 
2 CREATE CUSTOM TAXONOMY - BOOK CATEGORY 
$book_category = new Cuztom_Taxonomy( 'Book Category', 'book' );
BOOKS LIBRARY 
3 CREATE METABOX - INFO 
$books->add_meta_box( 
'info', 
'Info', 
array( 
array( 
'name' => 'author', 
'label' => 'Author', 
'type' => 'text' 
), 
array( 
'name' => 'date', 
'label' => 'Date', 
'type' => 'date' 
), 
array( 
'name' => 'price', 
'label' => 'Price', 
'type' => 'text' 
), 
array( 
'name' => 'number_of_pages', 
'label' => 'Number of pages', 
'type' => 'text' 
), 
array( 
'name' => 'bind_type', 
'label' => 'Bind type', 
'type' => 'select', 
'options' => array( 
'hardcover' => 'Hardcover', 
'double-wire' => 'Double wire', 
'spiral' => 'Spiral' 
), 
'default_value' => 'hardcover' 
), 
array( 
'name' => 'size', 
'label' => 'Size', 
'type' => 'select', 
'options' => array( 
'a5' => 'A5', 
'a4' => 'A4', 
'a3' => 'A3' 
), 
'default_value' => 'a4' 
) 
) 
);
FIELD TYPES 
_ text - a simple text field 
_ textarea - a large textarea for multiple lines of text 
_ checkbox - a simple boolean entry 
_ yesno - allows choice of yes/no (pre-made extension of radio) 
_ select - combo box selection 
_ multi_select - multi select selection 
_ checkboxes - a checkbox group 
_ radios - a radio group 
_ wysiwyg - an editor with the same controls as the standard WordPress editor 
_ image - image upload box 
_ file - file upload box 
_ date - date selection 
_ datetime - date and time (hour+minutes) selection 
_ time - time (hour+minutes) selection 
_ color - color selection 
_ post_select - allows inner-post references via a combo-box 
_ post_checkboxes - allows inner-post references via a checkbox group 
_ term_select - allows category references via a combo-box 
_ term_checkboxes - allows category references via a checkbox group 
_ hidden - a hidden field (oſten used to store information not visible to the user).
BOOKS LIBRARY 
4 TEMPLATE 
<div class="entry-content"> 
<?php 
$bind_types = array( 
'hardcover' => __( 'Hardcover', 'slicejack' ), 
'double-wire' => __( 'Double wire', 'slicejack' ), 
'spiral' => __( 'Spiral', 'slicejack' ) 
); 
$sizes = array( 
'a5' => __( 'A5', 'slicejack' ), 
'a4' => __( 'A4', 'slicejack' ), 
'a3' => __( 'A3', 'slicejack' ) 
); 
?> 
<strong><?php _e( 'Author:', 'slicejack' ); ?></strong> <?php echo get_post_meta( get_the_id(), 
'_info_author', true ); ?><br /> 
<strong><?php _e( 'Date:', 'slicejack' ); ?></strong> <?php echo date( 'd.m.Y.', 
get_post_meta( get_the_id(), '_info_date', true ) ); ?><br /> 
<strong><?php _e( 'Price:', 'slicejack' ); ?></strong> $<?php echo get_post_meta( get_the_id(), 
'_info_price', true ); ?><br /> 
<strong><?php _e( 'Number of pages:', 'slicejack' ); ?></strong> <?php echo 
get_post_meta( get_the_id(), '_info_number_of_pages', true ); ?><br /> 
<strong><?php _e( 'Bind type:', 'slicejack' ); ?></strong> <?php echo 
$bind_types[ get_post_meta( get_the_id(), '_info_bind_type', true ) ]; ?><br /> 
<strong><?php _e( 'Size:', 'slicejack' ); ?></strong> <?php echo 
$sizes[ get_post_meta( get_the_id(), '_info_size', true ) ]; ?> 
</div><!-- .entry-content -->
FEATURED LIBRARY 
1 ADD METABOX TO PAGE TEMPLATE 
if ( is_admin() ) : 
$pid = 0; 
if( array_key_exists( 'post', $_GET ) ) 
$pid = $_GET['post']; 
elseif ( array_key_exists( 'post_ID', $_POST ) ) 
$pid = $_POST['post_ID']; 
$page_template = basename( get_post_meta( $pid, '_wp_page_template', true ) ); 
if ( 'featured-library.php' == $page_template ) : $cpage = new Cuztom_Post_Type( 'page' ); 
$cpage 
->remove_post_type_support( array( 'editor', 'thumbnail' ) ) 
->add_meta_box( 
'library', 
'Library', 
array( 
'bundle', 
array( 
array( 
'name' => 'book', 
'label' => 'Book', 
'type' => 'post_select', 
'args' => array( 
'post_type' => 'book', 
'show_option_none' => 'None' 
) 
)
FEATURED LIBRARY 
2 PAGE TEMPLATE 
<?php 
// Start the Loop. 
while ( have_posts() ) : the_post(); 
?> 
<?php 
the_title( '<header class="entry-header"><h1 class="entry-title">', '</h1></ 
header><!-- .entry-header -->' ); 
?> 
<?php 
$library = get_post_meta( get_the_id(), '_library', true ); 
foreach( $library as $book ) : 
$post = get_post( $book['_book'] ); 
setup_postdata( $post ); 
get_template_part( 'book' ); 
endforeach; 
wp_reset_postdata(); 
endwhile; 
?>
CUSTOM FIELD TYPE 
1 CREATE YOURFIELD.CLASS.PHP AND SAVE IT TO 
<?php 
if( ! defined( 'ABSPATH' ) ) exit; 
class Cuztom_Field_Ip extends Cuztom_Field 
{ 
var $_supports_repeatable = true; 
var $_supports_bundle = true; 
var $_supports_ajax = true; 
var $css_classes = array( 'cuztom-input', 'cuztom-ip' ); 
function _output( $value ) 
{ 
$output = ''; 
$output .= '<input type="text" ' . $this->output_name() . ' ' . $this->output_id() . ' ' . 
$this->output_css_class() . ' value="' . ( ! empty( $value ) ? $value : '0.0.0.0' ) . '" />'; 
$output .= $this->output_explanation(); 
return $output; 
} 
INC/CUZTOM/CLASSES/FIELDS
CUSTOM FIELD TYPE 
1 CREATE YOURFIELD.CLASS.PHP AND SAVE IT TO 
function save_value( $value ) { 
return filter_var( $value, FILTER_VALIDATE_IP ) ? $value : '0.0.0.0'; 
} 
} 
INC/CUZTOM/CLASSES/FIELDS
CUSTOM FIELD TYPE 
2 INCLUDE FIELD TYPE CLASS 
private function includes() 
{ 
/*...*/ 
include( CUZTOM_DIR . 'classes/fields/ip.class.php' ); 
}
CONTRIBUTE ON GITHUB 
https://github.com/gizburdt/wp-cuztom
THANK 
YOU! 
_ Ante Primorac (@anteprimorac) 
_ Web Developer @ Slicejack 
_ 2nd WordPress Meetup Split

Contenu connexe

Tendances

OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with Moose
Nelo Onyiah
 
My sql presentation
My sql presentationMy sql presentation
My sql presentation
Nikhil Jain
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
Olaf Alders
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
Kris Wallsmith
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 

Tendances (20)

Introduction to Moose
Introduction to MooseIntroduction to Moose
Introduction to Moose
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
OO Perl with Moose
OO Perl with MooseOO Perl with Moose
OO Perl with Moose
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
An (Inaccurate) Introduction to Python
An (Inaccurate) Introduction to PythonAn (Inaccurate) Introduction to Python
An (Inaccurate) Introduction to Python
 
Wsomdp
WsomdpWsomdp
Wsomdp
 
My sql presentation
My sql presentationMy sql presentation
My sql presentation
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
PHP Tutorial (funtion)
PHP Tutorial (funtion)PHP Tutorial (funtion)
PHP Tutorial (funtion)
 
performance vamos dormir mais?
performance vamos dormir mais?performance vamos dormir mais?
performance vamos dormir mais?
 
PHP 1
PHP 1PHP 1
PHP 1
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
 

Similaire à WordPress Cuztom Helper

Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
iKlaus
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
Tammy Hart
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
camp_drupal_ua
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 

Similaire à WordPress Cuztom Helper (20)

Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
[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
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An Analysis
 
WordPress as an application framework
WordPress as an application frameworkWordPress as an application framework
WordPress as an application framework
 
Speed Things Up with Transients
Speed Things Up with TransientsSpeed Things Up with Transients
Speed Things Up with Transients
 
Quality code by design
Quality code by designQuality code by design
Quality code by design
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Lettering js
Lettering jsLettering js
Lettering js
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

WordPress Cuztom Helper

  • 1. WORDPRESS CUZTOM HELPER - A helper to make the life of Wordpress developers easier. _ Ante Primorac (@anteprimorac) _ Web Developer @ Slicejack _ 2nd WordPress Meetup Split
  • 2. WHAT DO WE USE CUZTOM FOR? _ Post types _ Taxonomies _ Meta Boxes _ Post meta _ Term meta _ User meta
  • 3. HOW TO USE CUZTOM? 1 CLONE REPOSITORY TO INC/CUZTOM/ slicejack:inc ante$ git clone https://github.com/gizburdt/wp-cuztom.git cuztom 2 CREATE CUZTOM.PHP AND LET THE MAGIC BEGIN <?php define( 'CUZTOM_TEXTDOMAIN', 'slicejack' ); define( 'CUZTOM_URL', get_template_directory_uri() . '/inc/cuztom' ); require( 'cuztom/cuztom.php' );
  • 4. BOOKS LIBRARY 1 CREATE CUSTOM POST TYPE - BOOK $books = new Cuztom_Post_Type( 'book', array( 'has_archive' => true, 'rewrite' => array( 'slug' => 'books' ), 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ) ) );
  • 5.
  • 6. BOOKS LIBRARY 2 CREATE CUSTOM TAXONOMY - BOOK CATEGORY $book_category = new Cuztom_Taxonomy( 'Book Category', 'book' );
  • 7.
  • 8. BOOKS LIBRARY 3 CREATE METABOX - INFO $books->add_meta_box( 'info', 'Info', array( array( 'name' => 'author', 'label' => 'Author', 'type' => 'text' ), array( 'name' => 'date', 'label' => 'Date', 'type' => 'date' ), array( 'name' => 'price', 'label' => 'Price', 'type' => 'text' ), array( 'name' => 'number_of_pages', 'label' => 'Number of pages', 'type' => 'text' ), array( 'name' => 'bind_type', 'label' => 'Bind type', 'type' => 'select', 'options' => array( 'hardcover' => 'Hardcover', 'double-wire' => 'Double wire', 'spiral' => 'Spiral' ), 'default_value' => 'hardcover' ), array( 'name' => 'size', 'label' => 'Size', 'type' => 'select', 'options' => array( 'a5' => 'A5', 'a4' => 'A4', 'a3' => 'A3' ), 'default_value' => 'a4' ) ) );
  • 9. FIELD TYPES _ text - a simple text field _ textarea - a large textarea for multiple lines of text _ checkbox - a simple boolean entry _ yesno - allows choice of yes/no (pre-made extension of radio) _ select - combo box selection _ multi_select - multi select selection _ checkboxes - a checkbox group _ radios - a radio group _ wysiwyg - an editor with the same controls as the standard WordPress editor _ image - image upload box _ file - file upload box _ date - date selection _ datetime - date and time (hour+minutes) selection _ time - time (hour+minutes) selection _ color - color selection _ post_select - allows inner-post references via a combo-box _ post_checkboxes - allows inner-post references via a checkbox group _ term_select - allows category references via a combo-box _ term_checkboxes - allows category references via a checkbox group _ hidden - a hidden field (oſten used to store information not visible to the user).
  • 10.
  • 11. BOOKS LIBRARY 4 TEMPLATE <div class="entry-content"> <?php $bind_types = array( 'hardcover' => __( 'Hardcover', 'slicejack' ), 'double-wire' => __( 'Double wire', 'slicejack' ), 'spiral' => __( 'Spiral', 'slicejack' ) ); $sizes = array( 'a5' => __( 'A5', 'slicejack' ), 'a4' => __( 'A4', 'slicejack' ), 'a3' => __( 'A3', 'slicejack' ) ); ?> <strong><?php _e( 'Author:', 'slicejack' ); ?></strong> <?php echo get_post_meta( get_the_id(), '_info_author', true ); ?><br /> <strong><?php _e( 'Date:', 'slicejack' ); ?></strong> <?php echo date( 'd.m.Y.', get_post_meta( get_the_id(), '_info_date', true ) ); ?><br /> <strong><?php _e( 'Price:', 'slicejack' ); ?></strong> $<?php echo get_post_meta( get_the_id(), '_info_price', true ); ?><br /> <strong><?php _e( 'Number of pages:', 'slicejack' ); ?></strong> <?php echo get_post_meta( get_the_id(), '_info_number_of_pages', true ); ?><br /> <strong><?php _e( 'Bind type:', 'slicejack' ); ?></strong> <?php echo $bind_types[ get_post_meta( get_the_id(), '_info_bind_type', true ) ]; ?><br /> <strong><?php _e( 'Size:', 'slicejack' ); ?></strong> <?php echo $sizes[ get_post_meta( get_the_id(), '_info_size', true ) ]; ?> </div><!-- .entry-content -->
  • 12.
  • 13. FEATURED LIBRARY 1 ADD METABOX TO PAGE TEMPLATE if ( is_admin() ) : $pid = 0; if( array_key_exists( 'post', $_GET ) ) $pid = $_GET['post']; elseif ( array_key_exists( 'post_ID', $_POST ) ) $pid = $_POST['post_ID']; $page_template = basename( get_post_meta( $pid, '_wp_page_template', true ) ); if ( 'featured-library.php' == $page_template ) : $cpage = new Cuztom_Post_Type( 'page' ); $cpage ->remove_post_type_support( array( 'editor', 'thumbnail' ) ) ->add_meta_box( 'library', 'Library', array( 'bundle', array( array( 'name' => 'book', 'label' => 'Book', 'type' => 'post_select', 'args' => array( 'post_type' => 'book', 'show_option_none' => 'None' ) )
  • 14. FEATURED LIBRARY 2 PAGE TEMPLATE <?php // Start the Loop. while ( have_posts() ) : the_post(); ?> <?php the_title( '<header class="entry-header"><h1 class="entry-title">', '</h1></ header><!-- .entry-header -->' ); ?> <?php $library = get_post_meta( get_the_id(), '_library', true ); foreach( $library as $book ) : $post = get_post( $book['_book'] ); setup_postdata( $post ); get_template_part( 'book' ); endforeach; wp_reset_postdata(); endwhile; ?>
  • 15. CUSTOM FIELD TYPE 1 CREATE YOURFIELD.CLASS.PHP AND SAVE IT TO <?php if( ! defined( 'ABSPATH' ) ) exit; class Cuztom_Field_Ip extends Cuztom_Field { var $_supports_repeatable = true; var $_supports_bundle = true; var $_supports_ajax = true; var $css_classes = array( 'cuztom-input', 'cuztom-ip' ); function _output( $value ) { $output = ''; $output .= '<input type="text" ' . $this->output_name() . ' ' . $this->output_id() . ' ' . $this->output_css_class() . ' value="' . ( ! empty( $value ) ? $value : '0.0.0.0' ) . '" />'; $output .= $this->output_explanation(); return $output; } INC/CUZTOM/CLASSES/FIELDS
  • 16. CUSTOM FIELD TYPE 1 CREATE YOURFIELD.CLASS.PHP AND SAVE IT TO function save_value( $value ) { return filter_var( $value, FILTER_VALIDATE_IP ) ? $value : '0.0.0.0'; } } INC/CUZTOM/CLASSES/FIELDS
  • 17. CUSTOM FIELD TYPE 2 INCLUDE FIELD TYPE CLASS private function includes() { /*...*/ include( CUZTOM_DIR . 'classes/fields/ip.class.php' ); }
  • 18. CONTRIBUTE ON GITHUB https://github.com/gizburdt/wp-cuztom
  • 19. THANK YOU! _ Ante Primorac (@anteprimorac) _ Web Developer @ Slicejack _ 2nd WordPress Meetup Split