This document provides instructions for creating a WordPress plugin called Post Products from scratch. The plugin allows adding product data to posts through features like a settings page, widget, post meta box, and shortcode. It outlines setting up the plugin files and header, then defines functions to register hooks, initialize the plugin, create a menu item, save meta box data, and more. The document includes code examples for key functions to build out the plugin functionality.
A quick run through explaining actions and filters that are used throughout WordPress (with useful metaphors) and some examples. It is intended to demonstrate that actions and filters are not as scary as people might think and that they can very easily make significant changes with only a few lines of code.
Want to give the WordPress admin area some professional polish? Want to make it super easy for your clients to locate and work with their most critical data? How about making it super easy for your client to contact you? This talk will provide theme developers with ideas to do just that along with the PHP code snippets to make it a reality. Take the WordPress admin experience to the next level!
This document discusses using pluggable applications with TurboGears2. It provides an overview of TurboGears2 features like object dispatch, declarative models, and XML template engines. It then demonstrates how to quickly start an application and explore options to add photo galleries, blogs, and wiki pages by plugging in additional applications and customizing templates and models.
The document discusses the architecture of a shopping cart system and how to make it easily testable and extensible. It recommends separating the core logic from session and database handling, and making frequently changing features into plugins. It also suggests simplifying the structure for easier testing by using storage instead of sessions, and DAO instead of databases during tests. The storage abstraction layer is implemented to operate on different mediums like arrays or sessions.
The document provides instructions for setting up a basic Sencha Touch application, including downloading the SDK, creating the base HTML structure, including CSS and JavaScript files, setting up the application and viewport, creating a data model and store to retrieve tweets from an API, and displaying the tweets in a list view.
Symfony2 - extending the console componentHugo Hamon
The goal of this session is to explain how to take benefit from the Symfony2 command line interface tool. First, I have a closer look at the most interesting commands to generate code and help you reduce your development time. Then, I will show you how to create your own commands to extend the Symfony CLI tool and automate your tedious and redundant tasks. This part of the talk will also explain how to create interactive tasks, interact with the database, generating links or send emails from the command line. Of course, there will be a focus on how to design your commands the best way to make them as much testable as possible.
This document discusses WordPress plugins and database tables. It covers hooks, which allow plugins to connect functions to events. Hooks are either actions or filters. Database tables in WordPress use a metadata structure, with meta tables containing key-value pairs that provide flexibility. Taxonomies classify terms and allow terms to be associated with posts through term relationships and term taxonomies. Next week's topics will include adding admin menus and handling POST data for plugins.
Have you heard WP-CLI, an about open source WordPress management tool that can make your development flow a lot easier? If you’ve heard about it or already use, you probably wondered how it it be extended to support custom commands. This talk will give you a short overview how to accomplish this and make your own magic with WP-CLI.
A quick run through explaining actions and filters that are used throughout WordPress (with useful metaphors) and some examples. It is intended to demonstrate that actions and filters are not as scary as people might think and that they can very easily make significant changes with only a few lines of code.
Want to give the WordPress admin area some professional polish? Want to make it super easy for your clients to locate and work with their most critical data? How about making it super easy for your client to contact you? This talk will provide theme developers with ideas to do just that along with the PHP code snippets to make it a reality. Take the WordPress admin experience to the next level!
This document discusses using pluggable applications with TurboGears2. It provides an overview of TurboGears2 features like object dispatch, declarative models, and XML template engines. It then demonstrates how to quickly start an application and explore options to add photo galleries, blogs, and wiki pages by plugging in additional applications and customizing templates and models.
The document discusses the architecture of a shopping cart system and how to make it easily testable and extensible. It recommends separating the core logic from session and database handling, and making frequently changing features into plugins. It also suggests simplifying the structure for easier testing by using storage instead of sessions, and DAO instead of databases during tests. The storage abstraction layer is implemented to operate on different mediums like arrays or sessions.
The document provides instructions for setting up a basic Sencha Touch application, including downloading the SDK, creating the base HTML structure, including CSS and JavaScript files, setting up the application and viewport, creating a data model and store to retrieve tweets from an API, and displaying the tweets in a list view.
Symfony2 - extending the console componentHugo Hamon
The goal of this session is to explain how to take benefit from the Symfony2 command line interface tool. First, I have a closer look at the most interesting commands to generate code and help you reduce your development time. Then, I will show you how to create your own commands to extend the Symfony CLI tool and automate your tedious and redundant tasks. This part of the talk will also explain how to create interactive tasks, interact with the database, generating links or send emails from the command line. Of course, there will be a focus on how to design your commands the best way to make them as much testable as possible.
This document discusses WordPress plugins and database tables. It covers hooks, which allow plugins to connect functions to events. Hooks are either actions or filters. Database tables in WordPress use a metadata structure, with meta tables containing key-value pairs that provide flexibility. Taxonomies classify terms and allow terms to be associated with posts through term relationships and term taxonomies. Next week's topics will include adding admin menus and handling POST data for plugins.
Have you heard WP-CLI, an about open source WordPress management tool that can make your development flow a lot easier? If you’ve heard about it or already use, you probably wondered how it it be extended to support custom commands. This talk will give you a short overview how to accomplish this and make your own magic with WP-CLI.
The road to <> styled-components: CSS in component-based systems by Max S...React London 2017
There's been a revolution; welcome the Component Age! Now what about styles? Max sat down with Glen Maddern (CSS modules) to think about how styles fit into our post-revolution world. They took the best of CSS and the web to create a fantastic new way to style component-based systems.
Shortcodes are commonplace in WordPress themes, plugins and even WordPress core. Whether you are a new developer looking to implement a shortcode for the first time, or are a seasoned pro; come join us as we delve into the pros, cons, gotchas, best practices and creative approaches to shortcodes.
Being involved in performance audits on systems of every size, from start-up sites hacked together overnight, to a ginormous applications built by world-recognized brand companies, I’ve seen a lot of interesting (and sometimes very unique) performance issues in every level of the stack: code, architecture, databases (sometimes all of the above). But there are a few particular, very “Performance 101″, issues that (unfortunately) appear in a lot of code bases. In this talk I'll present the most common database-related performance bottlenecks that can happen in most applications.
The document discusses object-oriented programming concepts in PHP such as classes, objects, inheritance, visibility, static methods and properties, abstract classes, interfaces, design patterns, and singleton patterns. It provides examples of creating classes for products and writers, using inheritance between product classes, and implementing a singleton pattern. The document concludes by stating the learner's progress is 20% complete and recommends further studying object-oriented concepts and patterns at home.
This document discusses the Data::FormValidator module, which provides a simplified way to validate form data in Perl. It allows defining validation profiles that specify required and optional fields, as well as custom and built-in constraint methods. The module takes request parameters, runs validation according to the profile, and returns results that can be easily integrated into templates to display error messages.
WP_Query, pre_get_posts, and eliminating query_posts()Erick Hitter
At the heart of WordPress is the WP_Query class, used to retrieve practically all content from the database and prepare it for display. In this presentation, I’ll discuss the myriad arguments available with WP_Query, the various properties and methods that are automatically populated, and the advanced queries made possible through filters within the class. I’ll also review the pre_get_posts action, detail how it can be used to modify standard WordPress queries and completely eliminate query_posts(), and explain why you’d want to do so in the first place.
The document discusses unit testing Zend Framework applications. It begins by explaining the importance of testing and some common excuses for not testing. It then provides examples of setting up PHPUnit configuration and bootstrap files for testing Zend Framework applications. The document demonstrates how to write tests for Zend Forms and models, including testing with both valid and invalid data. It shows how to modify models to add validation filters and validators.
The document discusses different ways to fetch posts and related data in WordPress, including query_posts(), new WP_Query(), and get_posts(). It explains that query_posts() alters the main query and requires wp_reset_query() to reset it. New WP_Query() runs 4 separate queries, while arguments can reduce these. The main query can be modified using pre_get_posts, checking is_main_query() to target specific pages like the home page. In summary, the document provides tips on properly using different WordPress post querying methods and hooks.
Bernhard Schussek gave a presentation on leveraging Symfony2 forms at the Symfony Live conference in March 2011. He discussed the evolution of the Symfony form component, its service-oriented architecture, and how forms are decoupled from business logic. He provided an example of an online sausage shop order form to demonstrate how form data is bound to objects and submitted. The presentation covered the form configuration class, form processing, field types, validation, embedding forms, and form themes.
The document discusses best practices for building robust jQuery plugins, including testing plugins with QUnit, implementing plugins by extending jQuery's prototype, releasing plugins with documentation and examples, and maintaining plugins over time by tracking issues and communicating with users.
The document discusses unit testing Zend Framework applications. It provides an overview of setting up PHPUnit for testing, including creating a phpunit.xml file and TestHelper bootstrap file. It also discusses testing Zend Forms and Models, including writing tests to validate form data and test that models are empty on construction. Code examples are provided for writing tests for a CommentForm and CommentModel class.
Scalability != performance. In fact, having to scale your architecture significantly with growth may be a symptom of a poor application performance. Yet, with the rise of cloud and the abundance of automation and container tools that simplify scalability aspect of your system, performance considerations are often pushed to the back row. Building systems for high performance is not easy. It requires a lot of considerations - from technology selection to design decisions. And "the cloud" does not magically solve those problems for you. In this talk I'll discuss common performance pitfalls across the stack and talk about useful techniques and examples that every application could benefit from.
The document provides an overview of Smarty, a widely used PHP templating system. It discusses that Smarty was created by Andrei Zmievski and separates display logic from controller logic for improved security and ease of use. Key features covered include literal tags, modifiers, and capture/cycle functions that allow for powerful templating capabilities. Examples demonstrate how to output variables, format dates, and alternate content display. Resources listed provide more documentation on Smarty syntax and usage.
The document discusses Symfony2 and how it can be used to build PHP applications. It covers Symfony concepts like the MVC pattern, routing, bundles, environments, and caching. Code examples are provided for controllers, templates, routing configuration, and more to illustrate how Symfony applications work.
Back in the ’40s, Samuel Eilenberg and Saunders Mac Lane started developing an entire new branch of mathematics: Category Theory. This was 10 years after Lambda calculus and 10 years before Lisp. Mathematics offers a powerful and concise language; we can represent a lot of complexity with short equations like E=mc2.
This session will explore how programming can harness maths’ capacity for conciseness and expression, borrowing from Category Theory. We’ll discover algebraic data types that can impact the way we code tremendously. You’ll also learn about functors, monads, applicatives, semigroups and monoids and how they can be used in a PHP context.
The document discusses various techniques for managing CSS in React applications in a maintainable way. It describes how CSS modules, Styled Components, and other libraries can help avoid issues like unused CSS selectors and classes by scoping styles and preventing dead code. It also discusses how style components and snapshots can help test CSS rules.
PHP performance 101: so you need to use a databaseLeon Fayer
Being involved in performance audits on systems of every size, from start-up sites hacked together overnight, to a ginormous applications built by world-recognized brand companies, I’ve seen a lot of interesting (and sometimes very unique) performance issues in every level of the stack: code, architecture, databases (sometimes all of the above). But there are a few particular, very “Performance 101″, issues that (unfortunately) appear in a lot of code bases. In this talk I present the most common database-related performance bottlenecks that can happen in most PHP applications.
The document provides an overview of useful PHP functions for including files, validating user input, and creating custom functions. It discusses the include() and require() functions for including external files. It also demonstrates how to validate user input using functions like strlen(), ereg(), and regular expressions. Finally, it shows how to create custom functions to encapsulate repeated blocks of code and handle errors gracefully.
In 2010, I told everyone how to start unit testing Zend Framework applications. In 2011, let’s take this a step further by testing services, work flows and performance. Looking to raise the bar on quality? Let this talk be the push you need to improve your Zend Framework projects.
The document discusses Symfony2, an open-source PHP web application framework. It provides an overview of its components including routing, dependency injection, and templating. It also describes how Symfony uses an MVC architecture and emphasizes loose coupling and flexibility.
Yasuo Harada is a PHP developer in Osaka who blogs about slyly walking PHP techniques. He gave a presentation about using plugins in three stages: 1) Organize functionality into plugins by feature, 2) Share generic plugins between applications, and 3) Gradually improve plugins during development and repair. Plugins can be used to add features like debugging, user management, mailing, and theming. Templates, assets, and translations can be included in plugins and used in applications. Custom dispatchers can be created to handle asset loading from plugins.
This document provides instructions for creating a simple blog using Django. It includes steps to:
1) Set up the Django project and install necessary apps like the admin interface.
2) Create a blog application with a Post model to store blog posts and configure the admin interface to manage posts.
3) Add templates to display list and detail views of posts and enable pagination for post lists.
4) Create a form to allow adding and editing blog posts from the admin and templates.
5) Provide instructions for deleting posts and include a link to download the full code files.
The road to <> styled-components: CSS in component-based systems by Max S...React London 2017
There's been a revolution; welcome the Component Age! Now what about styles? Max sat down with Glen Maddern (CSS modules) to think about how styles fit into our post-revolution world. They took the best of CSS and the web to create a fantastic new way to style component-based systems.
Shortcodes are commonplace in WordPress themes, plugins and even WordPress core. Whether you are a new developer looking to implement a shortcode for the first time, or are a seasoned pro; come join us as we delve into the pros, cons, gotchas, best practices and creative approaches to shortcodes.
Being involved in performance audits on systems of every size, from start-up sites hacked together overnight, to a ginormous applications built by world-recognized brand companies, I’ve seen a lot of interesting (and sometimes very unique) performance issues in every level of the stack: code, architecture, databases (sometimes all of the above). But there are a few particular, very “Performance 101″, issues that (unfortunately) appear in a lot of code bases. In this talk I'll present the most common database-related performance bottlenecks that can happen in most applications.
The document discusses object-oriented programming concepts in PHP such as classes, objects, inheritance, visibility, static methods and properties, abstract classes, interfaces, design patterns, and singleton patterns. It provides examples of creating classes for products and writers, using inheritance between product classes, and implementing a singleton pattern. The document concludes by stating the learner's progress is 20% complete and recommends further studying object-oriented concepts and patterns at home.
This document discusses the Data::FormValidator module, which provides a simplified way to validate form data in Perl. It allows defining validation profiles that specify required and optional fields, as well as custom and built-in constraint methods. The module takes request parameters, runs validation according to the profile, and returns results that can be easily integrated into templates to display error messages.
WP_Query, pre_get_posts, and eliminating query_posts()Erick Hitter
At the heart of WordPress is the WP_Query class, used to retrieve practically all content from the database and prepare it for display. In this presentation, I’ll discuss the myriad arguments available with WP_Query, the various properties and methods that are automatically populated, and the advanced queries made possible through filters within the class. I’ll also review the pre_get_posts action, detail how it can be used to modify standard WordPress queries and completely eliminate query_posts(), and explain why you’d want to do so in the first place.
The document discusses unit testing Zend Framework applications. It begins by explaining the importance of testing and some common excuses for not testing. It then provides examples of setting up PHPUnit configuration and bootstrap files for testing Zend Framework applications. The document demonstrates how to write tests for Zend Forms and models, including testing with both valid and invalid data. It shows how to modify models to add validation filters and validators.
The document discusses different ways to fetch posts and related data in WordPress, including query_posts(), new WP_Query(), and get_posts(). It explains that query_posts() alters the main query and requires wp_reset_query() to reset it. New WP_Query() runs 4 separate queries, while arguments can reduce these. The main query can be modified using pre_get_posts, checking is_main_query() to target specific pages like the home page. In summary, the document provides tips on properly using different WordPress post querying methods and hooks.
Bernhard Schussek gave a presentation on leveraging Symfony2 forms at the Symfony Live conference in March 2011. He discussed the evolution of the Symfony form component, its service-oriented architecture, and how forms are decoupled from business logic. He provided an example of an online sausage shop order form to demonstrate how form data is bound to objects and submitted. The presentation covered the form configuration class, form processing, field types, validation, embedding forms, and form themes.
The document discusses best practices for building robust jQuery plugins, including testing plugins with QUnit, implementing plugins by extending jQuery's prototype, releasing plugins with documentation and examples, and maintaining plugins over time by tracking issues and communicating with users.
The document discusses unit testing Zend Framework applications. It provides an overview of setting up PHPUnit for testing, including creating a phpunit.xml file and TestHelper bootstrap file. It also discusses testing Zend Forms and Models, including writing tests to validate form data and test that models are empty on construction. Code examples are provided for writing tests for a CommentForm and CommentModel class.
Scalability != performance. In fact, having to scale your architecture significantly with growth may be a symptom of a poor application performance. Yet, with the rise of cloud and the abundance of automation and container tools that simplify scalability aspect of your system, performance considerations are often pushed to the back row. Building systems for high performance is not easy. It requires a lot of considerations - from technology selection to design decisions. And "the cloud" does not magically solve those problems for you. In this talk I'll discuss common performance pitfalls across the stack and talk about useful techniques and examples that every application could benefit from.
The document provides an overview of Smarty, a widely used PHP templating system. It discusses that Smarty was created by Andrei Zmievski and separates display logic from controller logic for improved security and ease of use. Key features covered include literal tags, modifiers, and capture/cycle functions that allow for powerful templating capabilities. Examples demonstrate how to output variables, format dates, and alternate content display. Resources listed provide more documentation on Smarty syntax and usage.
The document discusses Symfony2 and how it can be used to build PHP applications. It covers Symfony concepts like the MVC pattern, routing, bundles, environments, and caching. Code examples are provided for controllers, templates, routing configuration, and more to illustrate how Symfony applications work.
Back in the ’40s, Samuel Eilenberg and Saunders Mac Lane started developing an entire new branch of mathematics: Category Theory. This was 10 years after Lambda calculus and 10 years before Lisp. Mathematics offers a powerful and concise language; we can represent a lot of complexity with short equations like E=mc2.
This session will explore how programming can harness maths’ capacity for conciseness and expression, borrowing from Category Theory. We’ll discover algebraic data types that can impact the way we code tremendously. You’ll also learn about functors, monads, applicatives, semigroups and monoids and how they can be used in a PHP context.
The document discusses various techniques for managing CSS in React applications in a maintainable way. It describes how CSS modules, Styled Components, and other libraries can help avoid issues like unused CSS selectors and classes by scoping styles and preventing dead code. It also discusses how style components and snapshots can help test CSS rules.
PHP performance 101: so you need to use a databaseLeon Fayer
Being involved in performance audits on systems of every size, from start-up sites hacked together overnight, to a ginormous applications built by world-recognized brand companies, I’ve seen a lot of interesting (and sometimes very unique) performance issues in every level of the stack: code, architecture, databases (sometimes all of the above). But there are a few particular, very “Performance 101″, issues that (unfortunately) appear in a lot of code bases. In this talk I present the most common database-related performance bottlenecks that can happen in most PHP applications.
The document provides an overview of useful PHP functions for including files, validating user input, and creating custom functions. It discusses the include() and require() functions for including external files. It also demonstrates how to validate user input using functions like strlen(), ereg(), and regular expressions. Finally, it shows how to create custom functions to encapsulate repeated blocks of code and handle errors gracefully.
In 2010, I told everyone how to start unit testing Zend Framework applications. In 2011, let’s take this a step further by testing services, work flows and performance. Looking to raise the bar on quality? Let this talk be the push you need to improve your Zend Framework projects.
The document discusses Symfony2, an open-source PHP web application framework. It provides an overview of its components including routing, dependency injection, and templating. It also describes how Symfony uses an MVC architecture and emphasizes loose coupling and flexibility.
Yasuo Harada is a PHP developer in Osaka who blogs about slyly walking PHP techniques. He gave a presentation about using plugins in three stages: 1) Organize functionality into plugins by feature, 2) Share generic plugins between applications, and 3) Gradually improve plugins during development and repair. Plugins can be used to add features like debugging, user management, mailing, and theming. Templates, assets, and translations can be included in plugins and used in applications. Custom dispatchers can be created to handle asset loading from plugins.
This document provides instructions for creating a simple blog using Django. It includes steps to:
1) Set up the Django project and install necessary apps like the admin interface.
2) Create a blog application with a Post model to store blog posts and configure the admin interface to manage posts.
3) Add templates to display list and detail views of posts and enable pagination for post lists.
4) Create a form to allow adding and editing blog posts from the admin and templates.
5) Provide instructions for deleting posts and include a link to download the full code files.
The document summarizes key points from a WordPress meetup discussion on plugin development:
- Mostafa Soufi discussed why developers make plugins and what plugins are comprised of. He suggested starting a new plugin by creating directories and files and adding a readme file.
- Navid Kashani recommended focusing on support from the beginning by improving support processes, solving issues proactively, setting metrics, and using a central support channel like Slack. Hiring a support person is not necessary initially.
- The discussion covered plugin best practices like internationalization, shortcodes, activation hooks, caching with transients, security techniques, and answering questions from attendees.
Django is a high-level Python web framework that allows developers to build web applications quickly by automating common tasks and following best practices. It provides features like an object-relational mapper, form validation, security, internationalization, and more out of the box. The document then outlines how to install, configure, and build basic applications with Django.
Creating and Maintaining WordPress PluginsMark Jaquith
The document discusses best practices for creating and maintaining WordPress plugins. It recommends using classes to organize plugin code, hooking into WordPress actions and filters through class methods, storing plugin options in an array, and releasing plugins on WordPress.org for easy community support, professional credibility, and code reuse. Sanity and good coding practices like limiting options and slowing feature additions are also advised.
Gail villanueva add muscle to your wordpress sitereferences
Gail Villanueva presented ways to add functionality to WordPress websites, including creating custom post types, taxonomies, fields and templates. She demonstrated how to build a job listing site, portfolio, or online store using WordPress. Useful plugins were recommended for custom post types, portfolios, job listings and e-commerce. The presentation provided code examples for custom fields, templates and queries.
This document discusses extending the functionality of Movable Type through plugins. It provides examples of plugins that add new template tags and panels. Plugins allow developers to tap into Movable Type's existing interfaces and extend the capabilities of its core applications. The document also references additional resources for learning more about customizing Movable Type through the use of plugins and its plugin API.
This document provides information about a CakePHP workshop including the presenter, development environment setup instructions, and an overview of the workshop content. Some key points:
- The presenter is Walther Lalk, a CakePHP core team member.
- Instructions are provided for setting up a development environment using Vagrant or the built-in PHP server.
- The workshop will cover installing CakePHP, baking a database and entities, authentication, authorization, and using CRUD to generate basic CRUD functionality.
- Attendees will build an events application with members, events, and event attendance tracking. Security, validation, and associations between entities will be implemented.
- CRUD will be
This document discusses consuming a web API through HTML clients. It explains how to modify an index file to provide a GUI for displaying and interacting with product data from the web API. Code examples are provided to get, find, delete, update, and add products by calling the web API using jQuery AJAX calls. Screenshots are mentioned to demonstrate viewing all products or finding a specific product.
Using Geeklog as a Web Application FrameworkDirk Haun
Slides for the workshop "Using Geeklog as a Web Application Framework", as held at
- LinuxTag 2006, Wiesbaden, Germany, 2006-05-06
- PHP user group meeting, Stuttgart, Germany, 2006-05-10
- FrOSCon, Bonn, Germany, 2006-06-24
Mojolicious is a real-time web framework for Perl that provides a simplified single file mode through Mojolicious::Lite. It has a clean, portable, object oriented API without hidden magic. It supports HTTP, WebSockets, TLS, IPv6 and more. Templates can use embedded Perl and are automatically rendered. Helpers, sessions, routing and testing utilities are built in. The generator can create new app structures and components.
Best Practices in Plugin Development (WordCamp Seattle)andrewnacin
My talk -- officially named "Y U NO CODE WELL" -- at WordCamp Seattle 2011 on best practices during plugin development. Find the video, as it provides some good context and conversation.
Reviews the basic of creating a WordPress plugin and some of the things you can do with a plugin. Presentation prepared for the Seacoast WordPress Developers Meetup in NH.
Abstracting functionality with centralised contentMichael Peacock
Centralised content involves storing all content types (pages, blog posts, products, etc.) in a centralised database structure for easier management. This allows content to be treated similarly while still supporting type-specific fields. The document discusses implementing centralised content with PHP and MySQL using a model-view-controller approach. Core content fields are stored in one table, with type-specific fields stored in linked tables. This allows new content types to be added without changing existing code.
The document provides examples and solutions for JSP scripts. It includes 3 examples: 1) Developing a JSP script to display a product catalog, 2) Developing a JSP script demonstrating inheritance with book classes, and 3) Developing a JSP script to accept user input and save it to a file. Each example includes the JSP script code, any relevant Java classes, and a brief description of the solution.
This document summarizes blog hacking techniques from 2004 to 2011. It provides 5 hacks including using a CSS framework for layout and styling, media queries for responsive design, embedding YouTube videos, syntax highlighting for code snippets, and using pubsubhubbub for real-time updates. The document encourages continuing to blog and have fun exploring new methods.
The document discusses API design in PHP for the Ning platform. It covers how the PHP API provides an interface to the Ning REST APIs, which are used for content storage, user profiles, tagging, search, and more. Examples are given of using the PHP XN_Content class to create and save content to the REST API. The document emphasizes designing APIs that promote predictability, stability, and human performance over computer performance.
This PHP document defines functions for a WordCamp Spain plugin. It includes functions to add an image to post content, create an options page for configuring the image settings, and register a widget to display the image. The options page and widget allow configuring the image path, width, and height. The plugin filters post content and registers a widget to display the configured image.
Similar to Wordpress plugin development from Scratch (20)
Discover the benefits of outsourcing SEO to Indiadavidjhones387
"Discover the benefits of outsourcing SEO to India! From cost-effective services and expert professionals to round-the-clock work advantages, learn how your business can achieve digital success with Indian SEO solutions.
HijackLoader Evolution: Interactive Process HollowingDonato Onofri
CrowdStrike researchers have identified a HijackLoader (aka IDAT Loader) sample that employs sophisticated evasion techniques to enhance the complexity of the threat. HijackLoader, an increasingly popular tool among adversaries for deploying additional payloads and tooling, continues to evolve as its developers experiment and enhance its capabilities.
In their analysis of a recent HijackLoader sample, CrowdStrike researchers discovered new techniques designed to increase the defense evasion capabilities of the loader. The malware developer used a standard process hollowing technique coupled with an additional trigger that was activated by the parent process writing to a pipe. This new approach, called "Interactive Process Hollowing", has the potential to make defense evasion stealthier.
Ready to Unlock the Power of Blockchain!Toptal Tech
Imagine a world where data flows freely, yet remains secure. A world where trust is built into the fabric of every transaction. This is the promise of blockchain, a revolutionary technology poised to reshape our digital landscape.
Toptal Tech is at the forefront of this innovation, connecting you with the brightest minds in blockchain development. Together, we can unlock the potential of this transformative technology, building a future of transparency, security, and endless possibilities.
2. The example plugin we are going to build is called Post Products. The goal of this plugin is to create
an easy way to add product data to posts. This plugin will include the following features:
➤ settings page using the Settings API
➤ widget for displaying newest products using the Widget class
➤ post meta box for adding product data to posts
➤ Shortcode support to easily display product data in a post
The first step in creating your plugin is to create your plugin files. For this plugin you’ll have two files:
post-products.php and uninstall.php. Because your plugin contains two files you’ll need to save
these files in a separate folder for your plugin named post-products. Next you need to set up your
plugin header and license.
To start you’ll be working in post-products.php. First you want to define your plugin header as shown
here:
<?php
/*
Plugin Name: Post Products
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: Easily add product data to posts.
Version: 1. 0
Author: Fred
Author URI: http://webdevstudios.com
*/
/* Copyright 2010 Fred (email : brad@webdevstudios.com)
This program 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
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc. , 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
As you can see you created the appropriate plugin header for your new plugin. Because you will be
releasing this plugin you’ll want to include the GPL software license below your plugin header.
3. Creating a Plugin Example
Next you are going to register all of the Action hooks needed for your plugin to work. It’s generally a
good idea to group all hook calls together. This helps other developers follow the logic of the plugin.
// Call function when plugin is activated
register_activation_hook( _ _FILE_ _,’pp_install’ );
// Action hook to initialize the plugin
add_action(’admin_init’ , ‘pp_init’);
// Action hook to register our option settings
add_action( ‘admin_init’ , ‘pp_register_settings’ );
// Action hook to add the post products menu item
add_action(’admin_menu’ , ‘pp_menu’);
// Action hook to save the meta box data when the post is saved
add_action(’save_post’,’pp_save_meta_box’ );
// Action hook to create the post products shortcode
add_shortcode(’pp’ , ‘pp_shortcode’);
// Action hook to create plugin widget
add_action( ‘widgets_init’ , ‘pp_register_widgets’ );
First you call the register_activation_hook function to set up your default plugin settings. Next
you call the admin_init hook to initialize your plugin, register your settings, and create your plugin
submenu item. You’ll be creating the functions for each Action hook next.
The first function you are going to create is pp_install, which is run when your plugin is activated:
function pp_install( ) {
//setup our default option values
$pp_options_arr=array(
"currency_sign"=>’$’
);
//save our default option values
update_option(’pp_options’ , $pp_options_arr);
}
The pp_install function is used to create your default option values. In this case, you want to set the
default currency sign to the dollar sign. After you’ve created your options array you’ll save the value
using the update_option function. The next function you’ll create is pp_menu as shown in the following
code:
//create the post products sub-menu
function pp_menu( ) {
add_options_page( _ _(’Post Products Settings Page’,’pp-plugin’) ,
_ _(’Post Products Settings’,’pp-plugin’) , ‘administrator’ ,
_ _FILE_ _, ‘pp_settings_page’);
}
As you can see this function is used to create your submenu item. Using the add_options_page function
your Post Products Settings submenu item will be located at the bottom of the Settings menu in
yourDashboard. You also set this menu item to only be viewable by an administrator. The next function
you’ll create is the pp_init:
//create post meta box
4. function pp_init( ) {
// create our custom meta box
add_meta_box(’pp-meta’, _ _(’Post Product Information’,’pp-plugin’) ,
‘pp_meta_box’,’post’,’side’,’default’ );
}
This function is used to create your Post Meta Box. You give your Meta Box a title of ‘‘Post Product
Information.’’ You also set the Meta Box to display in the side just below the Post Tags Meta Box on a
default installation of WordPress. Next you’re going to set up the plugin shortcode:
//create shortcode
function pp_shortcode($atts, $content = null) {
global $post;
extract(shortcode_atts(array(
"show" => ‘ ’
) , $atts));
//load options array
$pp_options = get_option(’pp_options’);
If ($show == ‘sku’ ) {
$pp_show = get_post_meta($post->ID,’pp_sku’,true);
}elseif ($show == ‘price’ ) {
$pp_show = $pp_options[’currency_sign’].
get_post_meta($post->ID,’pp_price’,true) ;
}elseif ($show == ‘weight’ ) {
$pp_show = get_post_meta($post->ID,’pp_weight’,true) ;
}elseif ($show == ‘color’ ) {
$pp_show = get_post_meta($post->ID,’pp_color’,true) ;
}elseif ($show == ‘inventory’ ) {
$pp_show = get_post_meta($post->ID,’pp_inventory’,true) ;
}
return $pp_show;
}
The first thing you do it initialize the global variable $post. This will bring in the $post->ID value for
the post in which you are using the shortcode. Next you extract the shortcode attributes that you’ve
defined, in this case show. Next you load your options array. The plugin settings are covered later in
this section. Finally, you check what attribute value is being sent to the shortcode to determine what
value to show. Using the shortcode like [pp show=price] would display the price of the product.
Next up is creating the Post Meta Box as shown here:
//build post product meta box
function pp_meta_box($post,$box) {
// retrieve our custom meta box values
$pp_sku = get_post_meta($post->ID,’pp_sku’,true) ;
$pp_price = get_post_meta($post->ID,’pp_price’,true); $pp_weight = get_post_meta($post-
>ID,’pp_weight’,true) ;
$pp_color = get_post_meta($post->ID,’pp_color’,true) ;
6. echo ‘ </table>’;
}
Your Post Product plugin saves five different product values on every post: sku, price, weight, color,
and inventory. As you can see the first step is to load these five custom field values. Next you displaythe
Meta Box form and fill in the current values if any exist. Below the Meta Box form you display a
simple shortcode legend to show the user what shortcode options are available
Now that you’ve created your custom Meta Box you need to save the data entered in the form as shown in
the following code:
//save meta box data
function pp_save_meta_box($post_id,$post) {
// if post is a revision skip saving our meta box data
if($post->post_type == ‘revision’ ) { return; }
// process form data if $_POST is set
if(isset($_POST[’pp_sku’] ) && $_POST[’pp_sku’ ] ! = ‘’ ) {
// save the meta box data as post meta using the post ID as a unique prefix
update_post_meta($post_id,’pp_sku’ , esc_attr($_POST[’pp_sku’])) ;
update_post_meta($post_id,’pp_price’ , esc_attr($_POST[’pp_price’])) ;
update_post_meta($post_id,’pp_weight’ , esc_attr($_POST[’pp_weight’])) ;
update_post_meta($post_id,’pp_color’ , esc_attr($_POST[’pp_color’])) ;
update_post_meta($post_id,’pp_inventory’,esc_attr($_POST[’pp_inventory’]));
}
}
First you verify that the post being saved is not a revision. Next you check that the post field pp_sku
exists and is not blank. The only required field is the product sku, so if this field is blank the post will
not be treated as a product and product data will not be saved. After you have verified that a sku exists
you save your custom product fields as post meta for the post you are creating.
Next up you are going to create your latest products widget:
//register our widget
function pp_register_widgets( ) {
register_widget( ‘pp_widget’ ) ;
}
//pp_widget class
class pp_widget extends WP_Widget {
First you have to register your widget as pp_widget. Next you extend the Widget class as pp_widget.
Now you need to create the four widget functions needed to build your widget:
//process our new widget
function pp_widget( ) {
$widget_ops = array(’classname’ => ‘pp_widget’ ,
’description’ => _ _(’Display Post Products’,’pp-plugin’ ) );
$this->WP_Widget(’pp_widget’ , _ _(’Post Products Widget’,’pp-plugin’) ,
$widget_ops);
}
The first function you create is the pp_widget function, also known as the constructor.
7. Here you set the widget title, description, and class name for your custom widget.
//build our widget settings form
function form($instance) {
$defaults = array( ‘title’ => _ _(’Products’,’pp-plugin’) ,
’number_products’ => ‘ ’ );
$instance = wp_parse_args( (array) $instance, $defaults ) ;
$title = strip_tags($instance[’title’]) ;
$number_products = strip_tags($instance[’number_products’ ] ) ;
?>
<p>
<?php _e(’Title’ , ‘pp-plugin’ ) ?>:
<input class="widefat" name=" <?php echo $this->get_field_name(’title’) ; ?>"
type="text" value=" <?php echo esc_attr($title) ; ?>" />
</p>
<p>
<?php _e(’Number of Products’ , ‘pp-plugin’ ) ?>:
<input name=" <?php echo $this->get_field_name(’number_products’) ; ?>"
type="text" value=" <?php echo esc_attr($number_products) ; ?>" size="2"
maxlength="2" />
</p>
<?php
}
The second function you define is the form function. This builds the form for saving your widget
settings. You are saving two settings in your widget: the widget title and the number of products to
display. First you define the setting defaults if no settings have been saved. Next you load in the saved
values for your two settings.
Finally, you display both setting form fields with the setting values if they exist.
//save our widget settings
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance[’title’ ] = strip_tags(esc_attr($new_instance[’title’])) ;
$instance[’number_products’ ] = intval($new_instance[’number_products’ ] );
return $instance;
}
The next function you create is the update function. This function saves your widget settings. Notice
how you utilize the strip_tags and esc_attr functions to sanitize your widget title. You also use the
PHP intval function to verify the number of products value is an integer.
//display our widget
function widget($args, $instance) {
global $post;
extract($args);
echo $before_widget;
$title = apply_filters(’widget_title’ , $instance[’title’ ] ) ;
$number_products = empty($instance[’number_products’] ) ?
’ ’ : apply_filters(’widget_number_products’ , $instance[’number_products’]);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
8. $dispProducts = new WP_Query() ;
$dispProducts->query(’meta_key=pp_sku&showposts=’.$number_products) ;
while ($dispProducts->have_posts() ) : $dispProducts->the_post();
//load options array
$pp_options = get_option(’pp_options’);
//load custom meta values
$pp_price = get_post_meta($post->ID,’pp_price’,true) ;
$pp_inventory = get_post_meta($post->ID,’pp_inventory’,true) ;
?><p><a href=" <?php the_permalink( ) ?>" rel="bookmark"
title=" <?php the_title_attribute() ; ?> Product Information" >
<?php the_title() ; ?></a></p><?php
echo ‘<p>’ . _ _(’Price’ , ‘pp-plugin’) . ‘ : ‘
.$pp_options[’currency_sign’].$pp_price .’ </p>’;
//check if Show Inventory option is enabled
If ($pp_options[’show_inventory’] ) {
echo ‘<p>’ . _ _(’Stock’ , ‘pp-plugin’) . ‘ : ‘ .$pp_inventory .’ </p>’ ;
}
echo ‘<hr />’;
endwhile;
echo $after_widget;
}
}
The final function defined is the widget function. This function displays your widget on the public side
of your web site. First you initialize the global $post variable and extract the $args for the widget.
Next you display the $before_widget variable. This variable can be set by theme and plugin developers
to display specified content before and after the plugin. Next you retrieve your two setting values. If the
$title value is not empty you use it, but if it is you’ll use the default title you defined earlier.
To display the products in your widget you are creating a custom Loop using WP_Query.
Remember, because this is not your main Loop you’ll want to use WP_Query to create your custom Loop
instead of query_posts. To define your custom Loop you pass in two parameters: one for the post meta
value and one for number of products to display. The first value (meta_key=pp_sku) tells your custom
Loop to only return posts that have this custom meta value set. The second value, showposts, determines
how many post products to display. This number is pulled from the widget options value set by the user.
Next you load your option values and the custom meta values you will be displaying in your widget.
Finally you display your post product values in the widget. If the option Show Inventory is enabled the
inventory value will be displayed.
The final part to your custom plugin is creating the plugin settings page:
function pp_register_settings( ) {
//register our array of settings
register_setting( ‘pp-settings-group’ , ‘pp_options’ );
}
function pp_settings_page( ) {
//load our options array
9. $pp_options = get_option(’pp_options’);
// if the show inventory option exists the checkbox needs to be checked
If ($pp_options[’show_inventory’] ) {
$checked = ‘ checked="checked" ‘ ;
}
$pp_currency = $pp_options[’currency_sign’] ;
?>
<div class="wrap" >
<h2><?php _e(’Post Products Options’ , ‘pp-plugin’ ) ?></h2>
<form method="post" action="options.php" >
<?php settings_fields( ‘pp-settings-group’ ) ; ?>
<table class="form-table">
<tr valign="top" >
<th scope="row" ><?php _e(’Show Product Inventory’ , ‘pp-plugin’ ) ?></th>
<td><input type="checkbox" name="pp_options[show_inventory] "
<?php echo $checked; ?> /></td>
</tr>
<tr valign="top" >
<th scope="row" ><?php _e(’Currency Sign’ , ‘pp-plugin’ ) ?></th>
<td><input type="text" name="pp_options[currency_sign] " value="
<?php echo $pp_currency; ?>" size="1" maxlength="1" /></td>
</tr>
</table>
<p class="submit" >
<input type="submit" class="button-primary" value="
<?php _e(’Save Changes’ , ‘pp-plugin’ ) ?>" />
</p>
</form>
</div>
<?php
}
?>
The first function is used to register your plugin settings. In this example you are saving all of your
setting values in an array so you need only one setting to be registered: pp_options. Next you create
the function to display your settings page called pp_settings_page.
First you load your plugin options array value. Next you check if the show inventory option should
be CHECKED. You also load in the current currency value into a variable for display. Next you display
your settings page form with both option form fields listed. Notice you are using the settings_fields
function to link your settings form to your registered setting you defined. You also set the name
for your form fields to your options array name with the unique option name in brackets like
pp_options[’show_inventory’ ] . This is the proper way to save your setting options in an array using
the Settings API. When the form is submitted WordPress will use the Settings API to sanitize the form
values and save them in the database.
10. The final step to your Post Products plugin is to create your uninstall.php file:
<?php
// If uninstall/delete not called from WordPress then exit
if( ! defined( ‘ABSPATH’ ) && ! defined( ‘WP_UNINSTALL_PLUGIN’ ) )
exit ();
// Delete options array from options table
delete_option( ‘pp_options’ ) ;
?>
The first thing you check is that ABSPATH and WP_UNINSTALL_PLUGIN constants exist. This means
they were called from WordPress and adds a layer of security on the uninstaller. After you have verified
the request is valid you delete your single option value from the database. You could also define other
uninstall functionality here if needed such as removing every product post meta value you saved in the
database.
That’s it! You just successfully built an entire plugin that includes many of the features covered in this
chapter. This is a fairly basic plugin but should give you the examples and tools needed to expand
upon.
Complete source code
<?php
/*
Plugin Name: Post Products
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: Easily add product data to posts.
Version: 1. 0
Author: O.A
Author URI: http://oa.com
*/
/* Copyright 2010 Fred (email : brad@webdevstudios.com)
This program 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
(at your option) any later version.
This program 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 this program; if not, write to the Free Software.
*/
// Call function when plugin is activated
register_activation_hook( _ _FILE_ _,’pp_install’ );
// Action hook to initialize the plugin
add_action(’admin_init’ , ‘pp_init’);
// Action hook to register our option settings
add_action( ‘admin_init’ , ‘pp_register_settings’ );
11. // Action hook to add the post products menu item
add_action(’admin_menu’ , ‘pp_menu’);
// Action hook to save the meta box data when the post is saved
add_action(’save_post’,’pp_save_meta_box’);
// Action hook to create the post products shortcode
add_shortcode(’pp’ , ‘pp_shortcode’);
// Action hook to create plugin widget
add_action( ‘widgets_init’ , ‘pp_register_widgets’ ) ;
function pp_install( ) {
//setup our default option values
$pp_options_arr=array(
"currency_sign"=>’$’
);
//save our default option values
update_option(’pp_options’ , $pp_options_arr);
}
//create the post products sub-menu
function pp_menu( ) {
add_options_page( _ _(’Post Products Settings Page’,’pp-plugin’) ,
_ _(’Post Products Settings’,’pp-plugin’) , ‘administrator’ , _ _FILE_ _,
’pp_settings_page’) ;
}
//create post meta box
function pp_init( ) {
// create our custom meta box
add_meta_box(’pp-meta’, _ _(’Post Product Information’,’pp-plugin’),
‘pp_meta_box’,’post’,’side’,’default’) ;
}
//create shortcode
function pp_shortcode($atts, $content = null) {
global $post;
extract(shortcode_atts(array(
"show" => ‘ ’
) , $atts));
//load options array
$pp_options = get_option(’pp_options’);
If ($show == ‘sku’ ) {
$pp_show = get_post_meta($post->ID,’pp_sku’,true);
}elseif ($show == ‘price’ ) {
$pp_show = $pp_options[’currency_sign’] .
get_post_meta($post->ID,’pp_price’,true);
}elseif ($show == ‘weight’ ) {
$pp_show = get_post_meta($post->ID,’pp_weight’,true);
}elseif ($show == ‘color’ ) {