WordPress

Programmatically creating pages in WordPress and displaying them
Programmatically creating pages in WordPress and displaying them

Hello, dear blog readers!

Today we’ll cover another important topic — programmatically creating pages in the WordPress engine, and displaying them at a specified URL.

At first glance, this functionality may seem completely unnecessary. But! What if you need to add some text content on a plugin view page? Sure, we can use our plugin (for example, a contact form) in the form of a shortcode and insert it into the page content. But there are situations when a single shortcode isn’t enough. You may need to create a separate page displaying both a form (e.g., for registration or ordering) and textual instructions. And it’s very important that this text be editable through the admin panel. Why? For example, if it's an order form page, the explanation text might contain current discount information, which can change seasonally or according to the client’s preferences. I believe the idea is clear and the task is understandable (or feel free to comment).
read more...

Plugin Interaction with WordPress Database. Part 2
Plugin Interaction with WordPress Database. Part 2

Continuing our series of articles on working with the database in WordPress. Today, we’ll talk about creating, updating, deleting, and retrieving data from the database.
Please note that we are not working with WordPress system tables, but with a custom one.
The table dump is shown below:

CREATE TABLE IF NOT EXISTS `wp_plance_text_shortcodes` (
  `sh_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `sh_title` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sh_code` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sh_description` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `sh_is_lock` tinyint(1) unsigned NOT NULL,
  `sh_date_create` int(10) unsigned NOT NULL,
  PRIMARY KEY (`sh_id`)
) ENGINE=InnoDB;

This is the current structure of the table used in my plugin “My Text Shortcodes”.

read more...

Plugin interaction with WordPress database. Part 1.
Plugin interaction with WordPress database. Part 1.

Hello, dear blog readers!
Let’s expand our WordPress programming knowledge a bit and look into how plugins interact with the database.

Out of the box, WP has pretty decent capabilities. I’m referring to things like creating custom taxonomies, terms, and linking them with additional data using metadata. It’s very convenient — once you write a dozen functions, you no longer need to worry about creating interfaces or even some of the internal app logic.

But for me, as someone still "new" to WordPress, it feels more natural to work with clearly structured database tables.
So in this article, I propose to explore that approach — based on one of my plugins called “my-simple-form,” slightly simplified for the purpose of the example.

read more...

How to programmatically send an email in WordPress
How to programmatically send an email in WordPress

While developing another plugin for WP, I remembered a small issue I once ran into — programmatically sending email messages. There's really nothing complicated about it, but still, it might be useful to someone.

Usually, across the web, I’ve seen the following code:

wp_mail(
	'to_email@example.com',
	'Email Subject',
	'Email Body'
);

read more...

How to Create a Table in WordPress Admin Panel. Part 2.2.
How to Create a Table in WordPress Admin Panel. Part 2.2.

Good day, dear blog readers!
Let’s continue dissecting our table plugin “piece by piece.” In this part, we’ll take a look at our table class: “Plance_Table_Lessons2.”

When we open the class, the first method we’ll see is `prepare_items()`. It’s responsible for preparing data to be displayed. Calling this method is mandatory. Here’s the method code:

read more...