This commit is contained in:
2026-10-06 18:51:23 -06:00
parent 8424dacd03
commit e2c26b7f21
4223 changed files with 737986 additions and 53 deletions
@@ -0,0 +1,258 @@
<?php
/**
* Generate a snippet to add a custom menu to the admin bar.
*
* @package WPCode
*/
/**
* The Post Status generator.
*/
class WPCode_Generator_Admin_Bar extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'admin-bar';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'admin',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Admin Bar Menu', 'insert-headers-and-footers' );
$this->description = __( 'Add a custom admin bar menu with links or content.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Generate a snippet to add a custom menu to the admin bar by filling in a simple form.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms sections using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You could add a new admin bar menu for links you use often, a list of posts, a site you often visit when in the admin, etc.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'add_admin_bar_item',
'default' => 'add_admin_bar_item' . time(),
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Position', 'insert-headers-and-footers' ),
'description' => __( 'Select where you want the menu item to be displayed on the admin bar.', 'insert-headers-and-footers' ),
'id' => 'priority',
'default' => '1100',
'options' => array(
'1100' => __( 'Last item on the left', 'insert-headers-and-footers' ),
'30' => __( 'Before Site Name', 'insert-headers-and-footers' ),
'50' => __( 'After Site Name', 'insert-headers-and-footers' ),
'70' => __( 'Before "New" Button', 'insert-headers-and-footers' ),
'80' => __( 'After "New" Button', 'insert-headers-and-footers' ),
),
),
),
),
),
'menu' => array(
'label' => __( 'Menu Structure', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Menu ID', 'insert-headers-and-footers' ),
'description' => __( 'Unique menu id for the admin bar menu.', 'insert-headers-and-footers' ),
'id' => 'menu_id',
'placeholder' => 'custom_menu_id',
'default' => 'custom_menu_id',
),
array(
'type' => 'text',
'label' => __( 'Menu Title', 'insert-headers-and-footers' ),
'description' => __( 'Text or HTML that will show up in the admin bar top-level item. Use HTML if you want to display an image.', 'insert-headers-and-footers' ),
'id' => 'menu_title',
'placeholder' => '',
'default' => '',
),
array(
'type' => 'text',
'label' => __( 'Menu item link', 'insert-headers-and-footers' ),
'description' => __( 'If left empty, the top level menu item will not be a link, just text.', 'insert-headers-and-footers' ),
'id' => 'menu_href',
'placeholder' => '',
'default' => '',
),
array(
'type' => 'text',
'label' => __( 'Menu item target', 'insert-headers-and-footers' ),
'description' => __( 'The menu item is a link use this field to set the target attribute. Use "_blank" to open the link in a new tab.', 'insert-headers-and-footers' ),
'id' => 'menu_target',
'placeholder' => '',
'default' => '',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Submenu Item Title', 'insert-headers-and-footers' ),
'description' => __( 'Text or HTML for the submenu item.', 'insert-headers-and-footers' ),
'id' => 'submenu_title',
'name' => 'submenu_title[]',
'placeholder' => '',
'repeater' => 'submenu',
),
array(
'type' => 'text',
'label' => __( 'Submenu item link', 'insert-headers-and-footers' ),
'description' => __( 'If left empty, this menu item will not be a link, just text.', 'insert-headers-and-footers' ),
'id' => 'submenu_href',
'name' => 'submenu_href[]',
'placeholder' => '',
'repeater' => 'submenu',
),
array(
'type' => 'text',
'label' => __( 'Submenu item target attribute', 'insert-headers-and-footers' ),
'description' => __( 'If the menu item is a link use this for the target attribute. Use "_blank" to open in a new tab.', 'insert-headers-and-footers' ),
'id' => 'submenu_target',
'name' => 'submenu_target[]',
'placeholder' => '',
'repeater' => 'submenu',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add more submenu items', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add submenu item" button below to add multiple submenu items.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add submenu item', 'insert-headers-and-footers' ),
'id' => 'submenu', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$submenu_titles = $this->get_value( 'submenu_title' );
$submenu_hrefs = $this->get_value( 'submenu_href' );
$submenu_targets = $this->get_value( 'submenu_target' );
$submenus_code = '';
if ( ! empty( $submenu_titles ) ) {
foreach ( $submenu_titles as $key => $submenu_title ) {
if ( empty( $submenu_title ) ) {
continue;
}
$submenu_href = empty( $submenu_hrefs[ $key ] ) ? '' : $submenu_hrefs[ $key ];
$submenu_target = empty( $submenu_targets[ $key ] ) ? '' : $submenu_targets[ $key ];
$submenus_code .= "
\$admin_bar->add_menu(
array(
'id' => 'submenu_{$this->get_value( 'menu_id' )}_$key',
'parent' => '{$this->get_value( 'menu_id' )}',
'title' => '$submenu_title',
'href' => '$submenu_href',
'meta' => array(
'target' => '$submenu_target',
),
)
);
";
}
}
return '// Add a custom menu item.
function ' . $this->get_value( 'function_name' ) . '( $admin_bar ) {
$admin_bar->add_menu(
array(
\'id\' => \'' . $this->get_value( 'menu_id' ) . '\',
\'title\' => \'' . $this->get_value( 'menu_title' ) . '\',
\'href\' => \'' . $this->get_value( 'menu_href' ) . '\',
\'meta\' => array(
\'target\' => \'' . $this->get_value( 'menu_target' ) . '\',
),
)
);
' . $submenus_code . '
}
add_action( \'admin_bar_menu\', \'' . $this->get_value( 'function_name' ) . '\', ' . $this->get_value( 'priority' ) . ' );
';
}
}
@@ -0,0 +1,189 @@
<?php
/**
* Generate a snippet to add a extra contact methods to user profiles.
*
* @package WPCode
*/
/**
* The Contact Methods generator.
*/
class WPCode_Generator_Contact_Methods extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'contact-methods';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'admin',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Contact Methods', 'insert-headers-and-footers' );
$this->description = __( 'Add additional contact methods to WordPress user profiles.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Use this generator to create a snippet which adds more contact methods to your WordPress users profiles.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms sections using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You can add extra fields for user profiles like their extended address, city, country, phone number, social media profiles (Facebook, Twitter, etc).', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets.', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'add_custom_contact_methods',
'default' => 'add_custom_contact_methods_' . time(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'methods' => array(
'label' => __( 'Contact Methods', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Contact Method Slug', 'insert-headers-and-footers' ),
'description' => __( 'A lowercase with no spaces slug for usage in the code. For example: "facebook" or "telephone".', 'insert-headers-and-footers' ),
'id' => 'contact_method_name',
'name' => 'contact_method_name[]',
'placeholder' => '',
'repeater' => 'contact_methods',
),
array(
'type' => 'text',
'label' => __( 'Contact Method Label', 'insert-headers-and-footers' ),
'description' => __( 'This will show up as a label next to the contact method field. For example: "Facebook URL" or "Phone number".', 'insert-headers-and-footers' ),
'id' => 'contact_method_description',
'name' => 'contact_method_description[]',
'placeholder' => '',
'repeater' => 'contact_methods',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add more contact methods', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add contact method" button below to add as many contact methods as you wish.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add contact method', 'insert-headers-and-footers' ),
'id' => 'contact_methods', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$contact_method_names = $this->get_value( 'contact_method_name' );
$contact_method_descriptions = $this->get_value( 'contact_method_description' );
$contact_methods_code = '';
if ( ! empty( $contact_method_names ) ) {
foreach ( $contact_method_names as $key => $method_name ) {
if ( empty( $method_name ) ) {
continue;
}
$method_name = sanitize_title( $method_name );
$description = empty( $contact_method_descriptions[ $key ] ) ? '' : $contact_method_descriptions[ $key ];
$contact_methods_code .= "
\$contact_methods[ '$method_name' ] = __( '$description', '{$this->get_value('text_domain')}' );";
}
}
return '// Add custom contact methods
function ' . $this->get_value('function_name') . '( $contact_methods ) {
' . $contact_methods_code . '
return $contact_methods;
}
add_filter( \'user_contactmethods\', \'' . $this->get_value('function_name') . '\' );
';
}
}
@@ -0,0 +1,235 @@
<?php
/**
* Generate a snippet for scheduling a cronjob.
*
* @package WPCode
*/
/**
* WPCode_Generator_Cronjob class.
*/
class WPCode_Generator_Cronjob extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'cronjob';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'core',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Schedule a Cron Job', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet to schedule a recurring event using the WordPress cron.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => sprintf(
// Translators: Placeholders add links to the wordpress.org references.
__( 'This generator makes it easy to generate a snippet that will schedule a recurring event using %1$swp_schedule_event%2$s.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/wp_schedule_event/" target="_blank">',
'</a>'
),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You may want to run some code once every hour, day or week, for example you could use this to send an email with the number of published posts every week.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'add_custom_schedule',
'default' => 'add_custom_schedule' . time(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'schedule' => array(
'label' => __( 'Schedule', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Recurrence', 'insert-headers-and-footers' ),
'description' => __( 'Choose how often you want this event to run.', 'insert-headers-and-footers' ),
'id' => 'recurrence',
'default' => 'hourly',
'options' => array(
'hourly' => __( 'Hourly', 'insert-headers-and-footers' ),
'twicedaily' => __( 'Twice Daily', 'insert-headers-and-footers' ),
'daily' => __( 'Daily', 'insert-headers-and-footers' ),
'custom' => __( 'Custom', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Custom Recurrence Name', 'insert-headers-and-footers' ),
'description' => __( 'This is the recurrence name slug, lowercase and no space.', 'insert-headers-and-footers' ),
'id' => 'recurrence_name',
'default' => 'biweekly',
),
array(
'type' => 'text',
'label' => __( 'Custom Recurrence Label', 'insert-headers-and-footers' ),
'id' => 'recurrence_label',
'default' => 'Once every 2 weeks',
'description' => __( 'This label will be used in a list of cron events, for example.', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Custom Recurrence Interval', 'insert-headers-and-footers' ),
'id' => 'recurrence_interval',
'default' => 1209600,
'description' => __( 'The number of seconds of this interval.', 'insert-headers-and-footers' ),
),
),
),
),
'hook' => array(
'label' => __( 'Code', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Hook name', 'insert-headers-and-footers' ),
'description' => __( 'Unique name of your hook used to run when scheduled.', 'insert-headers-and-footers' ),
'id' => 'hook_name',
'default' => 'do_custom_event_' . time(),
),
),
// Column 2.
array(
array(
'type' => 'textarea',
'label' => __( 'PHP Code', 'insert-headers-and-footers' ),
'description' => __( 'Custom PHP code that will run when the event is triggered.', 'insert-headers-and-footers' ),
'id' => 'code',
'code' => true,
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$function_name = $this->sanitize_function_name( $this->get_value( 'function_name' ) );
$hook_name = $this->sanitize_function_name( $this->get_value( 'hook_name' ) );
$interval = $this->get_value( 'recurrence' );
$recurrence_interval = intval( $this->get_value( 'recurrence_interval' ) );
$custom_recurrence = '';
if ( 'custom' === $interval ) {
$recurrence_function_name = 'custom_cron_recurrence_' . time();
$recurrence_name = $this->sanitize_function_name( $this->get_value( 'recurrence_name' ) );
$interval = $recurrence_name;
$custom_recurrence = "
function $recurrence_function_name( \$schedules ) {
\$schedules['$recurrence_name'] = array(
'display' => __( '{$this->get_value('recurrence_label')}', '{$this->get_value('text_domain')}' ),
'interval' => $recurrence_interval,
);
return \$schedules;
}
add_filter( 'cron_schedules', '$recurrence_function_name' );
";
}
return '// Schedule a cron event.
function ' . $hook_name . '() {
' . $this->get_value( 'code' ) . '
}
add_action( \'' . $hook_name . '\', \'' . $hook_name . '\' );
' . $custom_recurrence . '
function ' . $function_name . '() {
if ( ! wp_next_scheduled( \'' . $hook_name . '\' ) ) {
wp_schedule_event( time(), \'' . $interval . '\', \'' . $hook_name . '\' );
}
}
add_action( \'wp\', \'' . $function_name . '\' );';
}
}
@@ -0,0 +1,190 @@
<?php
/**
* Generate a snippet for adding a custom navigation menu.
*
* @package WPCode
*/
/**
* WPCode_Generator_Menu class.
*/
class WPCode_Generator_Menu extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'menu';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'design',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Navigation Menu', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet to register new navigation menus for your website.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => sprintf(
// Translators: Placeholders add links to the wordpress.org references.
__( 'This generator makes it easy to add new navigation menus to your website using the "register_nav_menus" function.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/register_nav_menus/" target="_blank">',
'</a>'
),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You can add a new navigation menu for your website to display in a flyout menu that is not part of the theme, for example.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'add_custom_navigation_menu',
'default' => 'add_custom_navigation_menu' . time(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'schedule' => array(
'label' => __( 'Menus', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Menu name', 'insert-headers-and-footers' ),
'description' => __( 'This is the menu name slug, lowercase and no space.', 'insert-headers-and-footers' ),
'id' => 'menu_name',
'name' => 'menu_name[]',
'repeater' => 'menus',
),
array(
'type' => 'text',
'label' => __( 'Menu label', 'insert-headers-and-footers' ),
'description' => __( 'Add a descriptive label for this menu in the admin.', 'insert-headers-and-footers' ),
'id' => 'menu_description',
'name' => 'menu_description[]',
'repeater' => 'menus',
),
),
// Column 2.
array(
array(
'type' => 'description',
'label' => __( 'Add another menu', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add menu" button below to add as many menu locations as you need.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add Menu', 'insert-headers-and-footers' ),
'id' => 'menus', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$menus = $this->get_value( 'menu_name' );
$descriptions = $this->get_value( 'menu_description' );
$menus_code = '';
$textdomain = $this->get_value( 'text_domain' );
if ( ! empty( $menus ) ) {
$array_code = '';
foreach ( $menus as $key => $menu ) {
if ( empty( $menu ) ) {
continue;
}
$array_code .= "'$menu' => __( '$descriptions[$key]', '$textdomain' ),\n\t\t";
}
if ( ! empty( $array_code ) ) {
$menus_code = "\$menus = array(
$array_code);
register_nav_menus( \$menus );
";
}
}
return '// Add Custom Navigation Menus
function ' . $this->get_value( 'function_name' ) . '() {
' . $menus_code . '
}
add_action( \'init\', \'' . $this->get_value( 'function_name' ) . '\' );';
}
}
@@ -0,0 +1,229 @@
<?php
/**
* Generate a snippet to register a new post status.
*
* @package WPCode
*/
/**
* The Post Status generator.
*/
class WPCode_Generator_Post_Status extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'post-status';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'content',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Post Status', 'insert-headers-and-footers' );
$this->description = __( 'Use this tool to generate a custom post status for your posts.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Generate custom post statuses for your posts to improve the way you manage content.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You could add a new status called "Pending Review" that your authors can use before the content will be published', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'custom_post_status',
'default' => 'custom_post_status' . time(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'status' => array(
'label' => __( 'Status', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Post Status', 'insert-headers-and-footers' ),
'description' => __( 'Name of status used in the code, lowercase maximum 32 characters.', 'insert-headers-and-footers' ),
'id' => 'post_status',
'placeholder' => 'pending',
'default' => 'pending',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Name', 'insert-headers-and-footers' ),
'description' => __( 'The singular name that will be displayed in the admin. ', 'insert-headers-and-footers' ),
'id' => 'label',
'placeholder' => 'Pending',
'default' => 'Pending',
),
array(
'type' => 'text',
'label' => __( 'Name (Plural)', 'insert-headers-and-footers' ),
'description' => __( 'The post status plural name. For example: Drafts.', 'insert-headers-and-footers' ),
'id' => 'label_count',
'placeholder' => 'Pending',
'default' => 'Pending',
),
),
),
),
'visibility' => array(
'label' => __( 'Visibility', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Public', 'insert-headers-and-footers' ),
'description' => __( 'Should the posts with this status be visible in the frontend?', 'insert-headers-and-footers' ),
'id' => 'public',
'options' => array(
'true' => __( 'Yes - Default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
'default' => 'true',
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Exclude from search results', 'insert-headers-and-footers' ),
'description' => __( 'Should the posts with this status be visible in the frontend?', 'insert-headers-and-footers' ),
'id' => 'exclude_from_search',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No - Default', 'insert-headers-and-footers' ),
),
'default' => 'false',
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Show in admin all list', 'insert-headers-and-footers' ),
'description' => __( 'Show statuses in the edit listing of the post.', 'insert-headers-and-footers' ),
'id' => 'show_in_admin_all_list',
'options' => array(
'true' => __( 'Yes - Default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
'default' => 'true',
),
array(
'type' => 'select',
'label' => __( 'Show in admin status list', 'insert-headers-and-footers' ),
'description' => __( 'Show statuses list at the top of the edit listings. e.g. Published (12) Custom Status (2)', 'insert-headers-and-footers' ),
'id' => 'show_in_admin_status_list',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No - Default', 'insert-headers-and-footers' ),
),
'default' => 'false',
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
return '// Register Custom Status
function '. $this->get_value( 'function_name' ) . '() {
$args = array(
\'label\' => _x( \'' . $this->get_value( 'label' ) . '\', \'Post Status Name\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'label_count\' => _n_noop( \'' . $this->get_value( 'label' ) . ' (%s)\', \'' . $this->get_value( 'label_count' ) . ' (%s)\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'public\' => ' . $this->get_value( 'public' ) . ',
\'show_in_admin_all_list\' => ' . $this->get_value( 'show_in_admin_all_list' ) . ',
\'show_in_admin_status_list\' => ' . $this->get_value( 'show_in_admin_status_list' ) . ',
\'exclude_from_search\' => ' . $this->get_value( 'exclude_from_search' ) . ',
);
register_post_status( \'' . $this->get_value( 'post_status' ) . '\', $args );
}
add_action( \'init\', \'' . $this->get_value( 'function_name' ) . '\', 5 );';
}
}
@@ -0,0 +1,896 @@
<?php
/**
* Generate a snippet to register a new post type.
*
* @package WPCode
*/
/**
* The Post Type generator.
*/
class WPCode_Generator_Post_Type extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'post-type';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'content',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Post Type', 'insert-headers-and-footers' );
$this->description = __( 'Use this tool to generate a custom post type for your website.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Generate custom post types for your website using a snippet.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You can add custom post types for specific items that are not blog posts, for example, if your site is about music you can have post types for artists, albums or songs.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'custom_post_type',
'default' => 'custom_post_type' . time(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'post_type' => array(
'label' => __( 'Post Type', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Post Type Key', 'insert-headers-and-footers' ),
'description' => __( 'Name of post type used in the code, lowercase maximum 20 characters.', 'insert-headers-and-footers' ),
'id' => 'post_type',
'placeholder' => 'post_type',
'default' => 'post_type',
),
array(
'type' => 'text',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A short description of the post type.', 'insert-headers-and-footers' ),
'id' => 'description',
'placeholder' => 'Post type description',
'default' => 'Post type description',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Name', 'insert-headers-and-footers' ),
'description' => __( 'The singular post type name (e.g. Artist, Album, Song).', 'insert-headers-and-footers' ),
'id' => 'label',
'placeholder' => 'Post Type',
'default' => 'Post Type',
),
array(
'type' => 'text',
'label' => __( 'Name (Plural)', 'insert-headers-and-footers' ),
'description' => __( 'The post type plural name (e.g. Artists, Albums, Songs).', 'insert-headers-and-footers' ),
'id' => 'label_count',
'placeholder' => 'Post Types',
'default' => 'Post Types',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Link To Taxonomies', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of Taxonomies (e.g. post_tag, category)', 'insert-headers-and-footers' ),
'id' => 'taxonomies',
'placeholder' => 'category,post_tag',
'default' => '',
),
array(
'type' => 'select',
'label' => __( 'Hierarchical', 'insert-headers-and-footers' ),
'description' => __( 'Hierarchical post types can have parents/children.', 'insert-headers-and-footers' ),
'id' => 'hierarchical',
'default' => 'false',
'options' => array(
'true' => __( 'Yes, like pages', 'insert-headers-and-footers' ),
'false' => __( 'No, like posts', 'insert-headers-and-footers' ),
),
),
),
),
),
'labels' => array(
'label' => __( 'Labels', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Menu Name', 'insert-headers-and-footers' ),
'id' => 'label_menu_name',
'placeholder' => 'Post Types',
'default' => 'Post Types',
),
array(
'type' => 'text',
'label' => __( 'Admin Bar Name', 'insert-headers-and-footers' ),
'id' => 'label_admin_bar_name',
'placeholder' => 'Post Type',
'default' => 'Post Type',
),
array(
'type' => 'text',
'label' => __( 'Archives', 'insert-headers-and-footers' ),
'id' => 'label_archives',
'placeholder' => 'Item Archives',
'default' => 'Item Archives',
),
array(
'type' => 'text',
'label' => __( 'Attributes', 'insert-headers-and-footers' ),
'id' => 'label_attributes',
'placeholder' => 'Item Attributes',
'default' => 'Item Attributes',
),
array(
'type' => 'text',
'label' => __( 'Parent Item', 'insert-headers-and-footers' ),
'id' => 'label_parent_item',
'placeholder' => 'Parent Item:',
'default' => 'Parent Item:',
),
array(
'type' => 'text',
'label' => __( 'All Items', 'insert-headers-and-footers' ),
'id' => 'label_all_items',
'placeholder' => 'All Items',
'default' => 'All Items',
),
array(
'type' => 'text',
'label' => __( 'Add New Item', 'insert-headers-and-footers' ),
'id' => 'label_add_new_item',
'placeholder' => 'Add New Item',
'default' => 'Add New Item',
),
array(
'type' => 'text',
'label' => __( 'Add New', 'insert-headers-and-footers' ),
'id' => 'label_add_new',
'placeholder' => 'Add New',
'default' => 'Add New',
),
array(
'type' => 'text',
'label' => __( 'New Item', 'insert-headers-and-footers' ),
'id' => 'label_new_item',
'placeholder' => 'New Item',
'default' => 'New Item',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Edit Item', 'insert-headers-and-footers' ),
'id' => 'label_edit_item',
'placeholder' => 'Edit Item',
'default' => 'Edit Item',
),
array(
'type' => 'text',
'label' => __( 'Update Item', 'insert-headers-and-footers' ),
'id' => 'label_update_item',
'placeholder' => 'Update Item',
'default' => 'Update Item',
),
array(
'type' => 'text',
'label' => __( 'View Item', 'insert-headers-and-footers' ),
'id' => 'label_view_item',
'placeholder' => 'View Item',
'default' => 'View Item',
),
array(
'type' => 'text',
'label' => __( 'View Items', 'insert-headers-and-footers' ),
'id' => 'label_view_items',
'placeholder' => 'View Items',
'default' => 'View Items',
),
array(
'type' => 'text',
'label' => __( 'Search Item', 'insert-headers-and-footers' ),
'id' => 'label_search_item',
'placeholder' => 'Search Item',
'default' => 'Search Item',
),
array(
'type' => 'text',
'label' => __( 'Not Found', 'insert-headers-and-footers' ),
'id' => 'label_not_found',
'placeholder' => 'Not Found',
'default' => 'Not Found',
),
array(
'type' => 'text',
'label' => __( 'Not Found in Trash', 'insert-headers-and-footers' ),
'id' => 'label_not_found_in_trash',
'placeholder' => 'Not Found in Trash',
'default' => 'Not Found in Trash',
),
array(
'type' => 'text',
'label' => __( 'Featured Image', 'insert-headers-and-footers' ),
'id' => 'label_featured_image',
'placeholder' => 'Featured Image',
'default' => 'Featured Image',
),
array(
'type' => 'text',
'label' => __( 'Set featured image', 'insert-headers-and-footers' ),
'id' => 'label_set_featured_image',
'placeholder' => 'Set featured image',
'default' => 'Set featured image',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Remove featured image', 'insert-headers-and-footers' ),
'id' => 'label_remove_featured_image',
'placeholder' => 'Remove featured image',
'default' => 'Remove featured image',
),
array(
'type' => 'text',
'label' => __( 'Use as featured image', 'insert-headers-and-footers' ),
'id' => 'label_use_as_featured_image',
'placeholder' => 'Use as featured image',
'default' => 'Use as featured image',
),
array(
'type' => 'text',
'label' => __( 'Insert into item', 'insert-headers-and-footers' ),
'id' => 'label_label_insert_into_item',
'placeholder' => 'Insert into item',
'default' => 'Insert into item',
),
array(
'type' => 'text',
'label' => __( 'Uploaded to this item', 'insert-headers-and-footers' ),
'id' => 'label_uploaded_to_this_item',
'placeholder' => 'Uploaded to this item',
'default' => 'Uploaded to this item',
),
array(
'type' => 'text',
'label' => __( 'Items list', 'insert-headers-and-footers' ),
'id' => 'label_items_list',
'placeholder' => 'Items list',
'default' => 'Items list',
),
array(
'type' => 'text',
'label' => __( 'Items list navigation', 'insert-headers-and-footers' ),
'id' => 'label_items_list_navigation',
'placeholder' => 'Items list navigation',
'default' => 'Items list navigation',
),
array(
'type' => 'text',
'label' => __( 'Filter items list', 'insert-headers-and-footers' ),
'id' => 'label_filter_items_list',
'placeholder' => 'Filter items list',
'default' => 'Filter items list',
),
),
),
),
'options' => array(
'label' => __( 'Options', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'checkbox_list',
'label' => __( 'Supports', 'insert-headers-and-footers' ),
'description' => __( 'Select which features this post type should support', 'insert-headers-and-footers' ),
'id' => 'supports',
'default' => array( 'title', 'editor' ),
'options' => array(
'title' => __( 'Title', 'insert-headers-and-footers' ),
'editor' => __( 'Content Editor', 'insert-headers-and-footers' ),
'author' => __( 'Author', 'insert-headers-and-footers' ),
'thumbnail' => __( 'Featured image', 'insert-headers-and-footers' ),
'excerpt' => __( 'Excerpt', 'insert-headers-and-footers' ),
'trackbacks' => __( 'Trackbacks', 'insert-headers-and-footers' ),
'custom-fields' => __( 'Custom Fields', 'insert-headers-and-footers' ),
'comments' => __( 'Comments', 'insert-headers-and-footers' ),
'revisions' => __( 'Revisions', 'insert-headers-and-footers' ),
'page-attributes' => __( 'Page Attributes', 'insert-headers-and-footers' ),
'post-formats' => __( 'Post Formats', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Exclude From Search', 'insert-headers-and-footers' ),
'description' => __( 'Exclude the posts of this post type from search results?', 'insert-headers-and-footers' ),
'id' => 'exclude_from_search',
'default' => 'false',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No - default', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Enable Export', 'insert-headers-and-footers' ),
'description' => __( 'Allow exporting posts of this post type in Tools > Export.', 'insert-headers-and-footers' ),
'id' => 'can_export',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Enable Archives', 'insert-headers-and-footers' ),
'description' => __( 'Enables archives for this post type, the post type key is used as default.', 'insert-headers-and-footers' ),
'id' => 'has_archive',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'custom' => __( 'Yes - using custom slug', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Custom Archive Slug', 'insert-headers-and-footers' ),
'description' => __( 'Custom archive slug (if selected above).', 'insert-headers-and-footers' ),
'id' => 'custom_archive_slug',
'placeholder' => '',
'default' => '',
),
),
),
),
'visibility' => array(
'label' => __( 'Visibility', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Public', 'insert-headers-and-footers' ),
// Translators: Placeholders add a link to the wp.org documentation page.
'description' => sprintf( __( 'Should this post type be %1$svisible to authors%2$s?', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#public" target="_blank">', '</a>' ),
'id' => 'public',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Show UI', 'insert-headers-and-footers' ),
'description' => __( 'Should this post type be visible in the Admin?', 'insert-headers-and-footers' ),
'id' => 'show_ui',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Show in Menu?', 'insert-headers-and-footers' ),
'description' => __( 'Should this post type be visible in the admin menu?', 'insert-headers-and-footers' ),
'id' => 'show_in_menu',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Menu position', 'insert-headers-and-footers' ),
'description' => __( 'Choose the admin menu position.', 'insert-headers-and-footers' ),
'id' => 'menu_position',
'default' => '5',
'options' => array(
'5' => __( 'Below Posts (5)', 'insert-headers-and-footers' ),
'10' => __( 'Below Media (10)', 'insert-headers-and-footers' ),
'20' => __( 'Below Pages (20)', 'insert-headers-and-footers' ),
'30' => __( 'Below Comments (30)', 'insert-headers-and-footers' ),
'60' => __( 'Below First Separator (60)', 'insert-headers-and-footers' ),
'65' => __( 'Below Plugins (65)', 'insert-headers-and-footers' ),
'70' => __( 'Below Users (70)', 'insert-headers-and-footers' ),
'75' => __( 'Below Tools (75)', 'insert-headers-and-footers' ),
'80' => __( 'Below Settings (80)', 'insert-headers-and-footers' ),
'100' => __( 'Below Second Separator (100)', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Menu Icon', 'insert-headers-and-footers' ),
// Translators: Placeholder adds a link to the dashicons page.
'description' => sprintf( __( 'Icon used next to the post type label in the admin menu. Use either a %1$sdashicon%2$s name or a full URL to an image file.', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/resource/dashicons/" target="_blank">', '</a>' ),
'id' => 'menu_icon',
'placeholder' => '',
'default' => '',
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Show in Admin Bar?', 'insert-headers-and-footers' ),
'description' => __( 'Should this post type be visible in the admin bar?', 'insert-headers-and-footers' ),
'id' => 'show_in_admin_bar',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Show in Navigation Menus?', 'insert-headers-and-footers' ),
'description' => __( 'Should this post type be available for use in menus (Appearance > Menus)?', 'insert-headers-and-footers' ),
'id' => 'show_in_nav_menus',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
),
),
'query' => array(
'label' => __( 'Query', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Publicly Queryable', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'Enable frontend requests using the query variable. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#publicly_queryable" target="_blank">', '</a>' ),
'id' => 'publicly_queryable',
'default' => 'true',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Query variable', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'Key used for querying posts in the frontend. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#query_var" target="_blank">', '</a>' ),
'id' => 'query_var',
'default' => 'true',
'options' => array(
'true' => __( 'Default (post type key)', 'insert-headers-and-footers' ),
'custom' => __( 'Custom variable', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Custom Query Variable', 'insert-headers-and-footers' ),
// Translators: Placeholder adds a link to the dashicons page.
'description' => sprintf( __( 'The custom query variable to use for this post type. %1$sSee documentation%2$s.', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#query_var" target="_blank">', '</a>' ),
'id' => 'query_var',
'placeholder' => '',
'default' => '',
),
),
),
),
'permalinks' => array(
'label' => __( 'Permalinks', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Rewrite Permalinks', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'Use the default permalink structure, disable permalinks for this post type or use custom options. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#rewrite" target="_blank">', '</a>' ),
'id' => 'rewrite',
'default' => 'true',
'options' => array(
'true' => __( 'Default (post type key)', 'insert-headers-and-footers' ),
'false' => __( 'Disable permalink rewrites', 'insert-headers-and-footers' ),
'custom' => __( 'Custom permalink structure', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'URL Slug', 'insert-headers-and-footers' ),
'description' => __( 'The slug used for this post types base. (for example: artist in www.example.com/artist/ )', 'insert-headers-and-footers' ),
'id' => 'rewrite_slug',
'placeholder' => '',
'default' => '',
),
array(
'type' => 'select',
'label' => __( 'Use URL Slug?', 'insert-headers-and-footers' ),
'description' => __( 'Use the post type name as URL slug base?', 'insert-headers-and-footers' ),
'id' => 'with_front',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Use pagination?', 'insert-headers-and-footers' ),
'description' => __( 'Allow the post type to have pagination?', 'insert-headers-and-footers' ),
'id' => 'pages',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Use feeds?', 'insert-headers-and-footers' ),
'description' => __( 'Allow the post type to have feeds?', 'insert-headers-and-footers' ),
'id' => 'feeds',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
),
),
'capabilities' => array(
'label' => __( 'Capabilities', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Capabilities', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'User capabilities in relation to this post type. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#capability_type" target="_blank">', '</a>' ),
'id' => 'capabilities',
'default' => 'true',
'options' => array(
'true' => __( 'Base capabilities - default', 'insert-headers-and-footers' ),
'custom' => __( 'Custom Capabilities', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Base Capablities Type', 'insert-headers-and-footers' ),
'description' => __( 'Use base capabilities from a core post type.', 'insert-headers-and-footers' ),
'id' => 'capability_type',
'default' => 'post',
'options' => array(
'post' => __( 'Posts', 'insert-headers-and-footers' ),
'page' => __( 'Pages', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'description',
'label' => __( 'Custom Capabilities', 'insert-headers-and-footers' ),
'content' => __( 'Use the fields below to use custom capabilities for this post type.', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Read Post', 'insert-headers-and-footers' ),
'id' => 'read_post',
'default' => 'read_post',
'placeholder' => 'read_post',
),
array(
'type' => 'text',
'label' => __( 'Read Private Posts', 'insert-headers-and-footers' ),
'id' => 'read_private_posts',
'default' => 'read_private_posts',
'placeholder' => 'read_private_posts',
),
array(
'type' => 'text',
'label' => __( 'Publish Posts', 'insert-headers-and-footers' ),
'id' => 'publish_posts',
'default' => 'publish_posts',
'placeholder' => 'publish_posts',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Delete Posts', 'insert-headers-and-footers' ),
'id' => 'delete_post',
'default' => 'delete_post',
'placeholder' => 'delete_post',
),
array(
'type' => 'text',
'label' => __( 'Edit Post', 'insert-headers-and-footers' ),
'id' => 'edit_post',
'default' => 'edit_post',
'placeholder' => 'edit_post',
),
array(
'type' => 'text',
'label' => __( 'Edit Posts', 'insert-headers-and-footers' ),
'id' => 'edit_posts',
'default' => 'edit_posts',
'placeholder' => 'edit_posts',
),
array(
'type' => 'text',
'label' => __( 'Edit Others Posts', 'insert-headers-and-footers' ),
'id' => 'edit_others_posts',
'default' => 'edit_others_posts',
'placeholder' => 'edit_others_posts',
),
),
),
),
'rest_api' => array(
'label' => __( 'Rest API', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Show in Rest API?', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'Add the post type to the WordPress wp-json API. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#show_in_rest" target="_blank">', '</a>' ),
'id' => 'show_in_rest',
'default' => 'false',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No - default', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Rest Base', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'The base slug that this post type will use in the REST API. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#rest_base" target="_blank">', '</a>' ),
'id' => 'rest_base',
'default' => '',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Rest Controller Class', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'The name of a custom Rest Controller class instead of WP_REST_Posts_Controller. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_post_type/#rest_controller_class" target="_blank">', '</a>' ),
'id' => 'rest_controller_class',
'default' => '',
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$has_archive = $this->get_value( 'has_archive' );
if ( 'custom' === $has_archive ) {
$has_archive = "'{$this->get_value( 'custom_archive_slug' )}'";
}
$rewrite = $this->get_value( 'rewrite' );
$rewrite_options = '';
if ( 'true' === $rewrite ) {
$rewrite = '';
} elseif ( 'custom' === $rewrite ) {
$rewrite = "\t\t'rewrite' => \$rewrite_options,\n";
$rewrite_options = "
\$rewrite_options = array(
'slug' => '{$this->get_value('rewrite_slug')}',
'with_front' => {$this->get_value( 'with_front')},
'pages' => {$this->get_value( 'pages')},
'feeds' => {$this->get_value( 'feeds')},
);
";
} else {
$rewrite = "\t\t'rewrite' => $rewrite,\n";
}
$custom_capabilities = '';
$capabilities = $this->get_value( 'capabilities' );
if ( 'custom' === $capabilities ) {
$custom_capabilities = "
\$capabilities = array(
'read_post' => '{$this->get_value( 'read_post')}',
'read_private_posts' => '{$this->get_value( 'read_private_posts')}',
'publish_posts' => '{$this->get_value( 'publish_posts')}',
'delete_post' => '{$this->get_value( 'delete_post')}',
'edit_post' => '{$this->get_value( 'edit_post')}',
'edit_posts' => '{$this->get_value( 'edit_posts')}',
'edit_others_posts' => '{$this->get_value( 'edit_others_posts')}',
);
";
$capabilities = "'capabilities' => \$capabilities,\n";
} else {
$capabilities = "'capability_type' => '{$this->get_value('capability_type')}',\n";
}
return '// Register Custom Post Type
function ' . $this->get_value('function_name') . '() {
$labels = array(
\'name\' => _x( \'' . $this->get_value('label_count') . '\', \'Post Type General Name\', \'' . $this->get_value('text_domain') . '\' ),
\'singular_name\' => _x( \'' . $this->get_value('label') . '\', \'Post Type Singular Name\', \'' . $this->get_value('text_domain') . '\' ),
\'menu_name\' => __( \'' . $this->get_value('label_menu_name') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'name_admin_bar\' => __( \'' . $this->get_value('label_admin_bar_name') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'archives\' => __( \'' . $this->get_value('label_archives') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'attributes\' => __( \'' . $this->get_value('label_attributes') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'parent_item_colon\' => __( \'' . $this->get_value('label_parent_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'all_items\' => __( \'' . $this->get_value('label_all_items') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'add_new_item\' => __( \'' . $this->get_value('label_add_new_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'add_new\' => __( \'' . $this->get_value('label_add_new') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'new_item\' => __( \'' . $this->get_value('label_new_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'edit_item\' => __( \'' . $this->get_value('label_edit_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'update_item\' => __( \'' . $this->get_value('label_update_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'view_item\' => __( \'' . $this->get_value('label_view_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'view_items\' => __( \'' . $this->get_value('label_view_items') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'search_items\' => __( \'' . $this->get_value('label_search_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'not_found\' => __( \'' . $this->get_value('label_not_found') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'not_found_in_trash\' => __( \'' . $this->get_value('label_not_found_in_trash') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'featured_image\' => __( \'' . $this->get_value('label_featured_image') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'set_featured_image\' => __( \'' . $this->get_value('label_set_featured_image') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'remove_featured_image\' => __( \'' . $this->get_value('label_remove_featured_image') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'use_featured_image\' => __( \'' . $this->get_value('label_use_as_featured_image') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'insert_into_item\' => __( \'' . $this->get_value('label_label_insert_into_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'uploaded_to_this_item\' => __( \'' . $this->get_value('label_uploaded_to_this_item') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'items_list\' => __( \'' . $this->get_value('label_items_list') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'items_list_navigation\' => __( \'' . $this->get_value('label_items_list_navigation') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'filter_items_list\' => __( \'' . $this->get_value('label_filter_items_list') . '\', \'' . $this->get_value('text_domain') . '\' ),
);
' . $custom_capabilities . '
' . $rewrite_options . '
$args = array(
\'label\' => __( \'' . $this->get_value('label') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'description\' => __( \'' . $this->get_value('description') . '\', \'' . $this->get_value('text_domain') . '\' ),
\'labels\' => $labels,
\'supports\' => ' . $this->get_array_value('supports') . ',
\'taxonomies\' => ' . $this->get_value_comma_separated('taxonomies') . ',
\'hierarchical\' => ' . $this->get_value('hierarchical') . ',
\'public\' => ' . $this->get_value('public') . ',
\'show_ui\' => ' . $this->get_value('show_ui') . ',
\'show_in_menu\' => ' . $this->get_value('show_in_menu') . ',
\'menu_position\' => ' . $this->get_value('menu_position') . ',
\'show_in_admin_bar\' => ' . $this->get_value('show_in_admin_bar') . ',
\'show_in_nav_menus\' => ' . $this->get_value('show_in_nav_menus') . ',
\'can_export\' => ' . $this->get_value('can_export') . ',
\'has_archive\' => ' . $has_archive . ',
\'exclude_from_search\' => ' . $this->get_value('exclude_from_search') . ',
\'publicly_queryable\' => ' . $this->get_value('publicly_queryable') . ',
' . $capabilities . $rewrite . $this->get_optional_value('menu_icon', true) . $this->get_optional_value('show_in_rest') . $this->get_optional_value('rest_base', true) . $this->get_optional_value('rest_controller_class', true) . chr(9) . ');
register_post_type( \'' . $this->get_value('post_type') . '\', $args );
}
add_action( \'init\', \'' . $this->get_value('function_name') . '\', 0 );';
}
}
@@ -0,0 +1,743 @@
<?php
/**
* Generate a snippet using WP_Query
*
* @package WPCode
*/
/**
* WPCode_Generator_Query class.
*/
class WPCode_Generator_Query extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'query';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'query',
);
/**
* This snippet should not be auto-inserted by default.
*
* @var bool
*/
public $auto_insert = false;
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'WP_Query', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet using WP_Query to load posts from your website.', 'insert-headers-and-footers' );
}
/**
* Get a list of available post types for autocomplete.
*
* @return array
*/
public function get_autocomplete_post_types() {
return array_keys( get_post_types() );
}
/**
* Get a list of available post statuses for autocomplete.
*
* @return array
*/
public function get_autocomplete_post_statuses() {
return array_keys( get_post_statuses() );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => sprintf(
// Translators: Placeholders add links to the wordpress.org references.
__( 'This generator makes it easy for you to create custom queries using %1$sWP_Query%2$s which you can then extend to display posts or similar.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/classes/wp_query/" target="_blank">',
'</a>'
),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You can use this generator to get quickly started with a query for all the posts of an author and display them using the shortcode functionality of WPCode or automatically displaying the posts using the auto-insert option.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Query variable name', 'insert-headers-and-footers' ),
'description' => __( 'If you want to use something more specific. The leading $ will be automatically added.', 'insert-headers-and-footers' ),
'id' => 'var_name',
'placeholder' => '$query',
'default' => 'query',
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Include loop', 'insert-headers-and-footers' ),
'description' => __( 'Select yes if you want to include an empty loop of the results that you can fill in for output.', 'insert-headers-and-footers' ),
'id' => 'loop',
'default' => 'true',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
),
),
'post' => array(
'label' => __( 'IDs & Parents', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Post ID(s)', 'insert-headers-and-footers' ),
'description' => __( 'Query a specific post ID or comma-separated list of ids. Cannot be combined with "Post ID not in" below.', 'insert-headers-and-footers' ),
'id' => 'post__in',
'default' => '',
'comma-separated' => true,
),
array(
'type' => 'text',
'label' => __( 'Post ID not in', 'insert-headers-and-footers' ),
'description' => __( 'Post ids to exclude from this query. Cannot be combined with "Post ID(s)" above.', 'insert-headers-and-footers' ),
'id' => 'post__not_in',
'default' => '',
'comma-separated' => true,
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Post parent ID(s)', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of post parent ids if the post type is hierarchical (like pages).', 'insert-headers-and-footers' ),
'id' => 'post_parent__in',
'default' => '',
'comma-separated' => true,
),
array(
'type' => 'text',
'label' => __( 'Post parent not in', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of post parent ids to exclude.', 'insert-headers-and-footers' ),
'id' => 'post_parent__not_in',
'default' => '',
'comma-separated' => true,
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Post slugs', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of post slugs to query by.', 'insert-headers-and-footers' ),
'id' => 'post_name__in',
'default' => '',
'comma-separated' => true,
),
),
),
),
'status' => array(
'label' => __( 'Type & Status', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Post type', 'insert-headers-and-footers' ),
'description' => __( 'Post type to query by, start typing to get suggestions.', 'insert-headers-and-footers' ),
'id' => 'post_type',
'default' => 'post',
'autocomplete' => $this->get_autocomplete_post_types(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Post status', 'insert-headers-and-footers' ),
'description' => __( 'Post status to query by.', 'insert-headers-and-footers' ),
'id' => 'post_status',
'default' => 'publish',
'autocomplete' => $this->get_autocomplete_post_statuses(),
),
),
),
),
'author' => array(
'label' => __( 'Author', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Author ID(s)', 'insert-headers-and-footers' ),
'description' => __( 'Author ID or comma-separated list of ids.', 'insert-headers-and-footers' ),
'id' => 'author',
'default' => '',
),
array(
'type' => 'text',
'label' => __( 'Author not in', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of author ids to exclude from the query.', 'insert-headers-and-footers' ),
'id' => 'author__not_in',
'default' => '',
'comma-separated' => true,
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Author name', 'insert-headers-and-footers' ),
'description' => __( 'Use the "user_nicename" parameter to query by author.', 'insert-headers-and-footers' ),
'id' => 'author_name',
'default' => '',
),
),
),
),
'search' => array(
'label' => __( 'Search', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Search term', 'insert-headers-and-footers' ),
'description' => __( 'Search for posts by this search term.', 'insert-headers-and-footers' ),
'id' => 's',
'default' => '',
),
),
),
),
'order' => array(
'label' => __( 'Order', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Results Order', 'insert-headers-and-footers' ),
'id' => 'order',
'default' => 'DESC',
'options' => array(
'DESC' => __( 'Descending order (3, 2, 1; c, b, a)', 'insert-headers-and-footers' ),
'ASC' => __( 'Ascending order (1, 2, 3; a, b, c)', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Order by', 'insert-headers-and-footers' ),
'id' => 'orderby',
'default' => 'date',
'options' => array(
'none' => __( 'No order (none)', 'insert-headers-and-footers' ),
'ID' => __( 'ID', 'insert-headers-and-footers' ),
'author' => __( 'Author', 'insert-headers-and-footers' ),
'title' => __( 'Title', 'insert-headers-and-footers' ),
'name' => __( 'Slug (name)', 'insert-headers-and-footers' ),
'type' => __( 'Post type (type)', 'insert-headers-and-footers' ),
'date' => __( 'Date (default)', 'insert-headers-and-footers' ),
'modified' => __( 'Modified date', 'insert-headers-and-footers' ),
'parent' => __( 'Parent id', 'insert-headers-and-footers' ),
'rand' => __( 'Random', 'insert-headers-and-footers' ),
'comment_count' => __( 'Comment count', 'insert-headers-and-footers' ),
'relevance' => __( 'Relevance (for search)', 'insert-headers-and-footers' ),
'menu_order' => __( 'Page Order (menu_order)', 'insert-headers-and-footers' ),
//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
'meta_value' => __( 'Meta value', 'insert-headers-and-footers' ),
'meta_value_num' => __( 'Numerical meta value (meta_value_num)', 'insert-headers-and-footers' ),
'post__in' => __( 'Order of ids in post__in', 'insert-headers-and-footers' ),
'post_name__in' => __( 'Order of names in post_name__in', 'insert-headers-and-footers' ),
'post_parent__in' => __( 'Order of ids in post_parent__in', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Meta Key', 'insert-headers-and-footers' ),
'description' => __( 'Meta key to use if you choose to order by meta value.', 'insert-headers-and-footers' ),
'id' => 'meta_key',
'default' => '',
),
),
// Column 3.
array(),
),
),
'pagination' => array(
'label' => __( 'Pagination', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Use Pagination', 'insert-headers-and-footers' ),
'id' => 'nopaging',
'default' => 'false',
'description' => __( 'Choose no to display all posts (not recommended).', 'insert-headers-and-footers' ),
'options' => array(
'true' => __( 'No', 'insert-headers-and-footers' ),
'false' => __( 'Yes (default)', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Page number', 'insert-headers-and-footers' ),
'description' => __( 'Which page to show.', 'insert-headers-and-footers' ),
'id' => 'paged',
'default' => '',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Posts per page', 'insert-headers-and-footers' ),
'description' => __( 'How many posts should be displayed per page.', 'insert-headers-and-footers' ),
'id' => 'posts_per_page',
'default' => '',
),
array(
'type' => 'text',
'label' => __( 'Offset', 'insert-headers-and-footers' ),
'description' => __( 'Number of posts to skip.', 'insert-headers-and-footers' ),
'id' => 'offset',
'default' => '',
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Ignore sticky posts', 'insert-headers-and-footers' ),
'id' => 'ignore_sticky_posts',
'default' => 'false',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No (default)', 'insert-headers-and-footers' ),
),
),
),
),
),
'taxonomy' => array(
'label' => __( 'Taxonomy', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Taxonomy', 'insert-headers-and-footers' ),
'description' => __( 'Taxonomy slug that you want to query by.', 'insert-headers-and-footers' ),
'id' => 'taxonomy',
'name' => 'taxonomy[]',
'default' => '',
'repeater' => 'tax_query',
),
array(
'type' => 'select',
'label' => __( 'Field', 'insert-headers-and-footers' ),
'description' => __( 'Select taxonomy term by.', 'insert-headers-and-footers' ),
'id' => 'field',
'name' => 'field[]',
'repeater' => 'tax_query',
'default' => 'term_id',
'options' => array(
'term_id' => __( 'Term ID (default)', 'insert-headers-and-footers' ),
'name' => __( 'Term Name', 'insert-headers-and-footers' ),
'slug' => __( 'Term Slug', 'insert-headers-and-footers' ),
'term_taxonomy_id' => __( 'Term Taxonomy ID', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Terms', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of terms to query by.', 'insert-headers-and-footers' ),
'id' => 'terms',
'name' => 'terms[]',
'default' => '',
'repeater' => 'tax_query',
'comma-separated' => true,
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Include Children', 'insert-headers-and-footers' ),
'id' => 'include_children',
'name' => 'include_children[]',
'default' => 'true',
'description' => __( 'Whether or not to include children for hierarchical taxonomies.', 'insert-headers-and-footers' ),
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
'repeater' => 'tax_query',
),
array(
'type' => 'select',
'label' => __( 'Operator', 'insert-headers-and-footers' ),
'id' => 'operator',
'name' => 'operator[]',
'default' => 'IN',
'description' => __( 'Operator to test relation by.', 'insert-headers-and-footers' ),
'options' => array(
'IN' => 'IN',
'NOT IN' => 'NOT IN',
'AND' => 'AND',
'EXISTS' => 'EXISTS',
'NOT EXISTS' => 'NOT EXISTS',
),
'repeater' => 'tax_query',
),
array(
'type' => 'spacer',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add another taxonomy', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add Taxonomy" button below to query multiple taxonomies.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add Taxonomy', 'insert-headers-and-footers' ),
'id' => 'tax_query', // Repeater to repeat when clicked.
),
array(
'type' => 'select',
'label' => __( 'Tax Relation', 'insert-headers-and-footers' ),
'id' => 'relation',
'default' => 'AND',
'options' => array(
'AND' => __( 'AND (default)', 'insert-headers-and-footers' ),
'OR' => __( 'OR', 'insert-headers-and-footers' ),
),
),
),
),
),
'meta' => array(
'label' => __( 'Custom Fields', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Meta Key', 'insert-headers-and-footers' ),
'description' => __( 'The key of the custom field.', 'insert-headers-and-footers' ),
'id' => 'key',
'name' => 'key[]',
'default' => '',
'repeater' => 'meta_query',
),
array(
'type' => 'text',
'label' => __( 'Meta Value', 'insert-headers-and-footers' ),
'description' => __( 'Value to query the meta by.', 'insert-headers-and-footers' ),
'id' => 'value',
'name' => 'value[]',
'default' => '',
'repeater' => 'meta_query',
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Compare', 'insert-headers-and-footers' ),
'description' => __( 'How to compare the value for querying by meta.', 'insert-headers-and-footers' ),
'id' => 'compare',
'name' => 'compare[]',
'repeater' => 'meta_query',
'default' => '=',
'options' => array(
'=' => '=',
'!=' => '!=',
'>' => '>',
'>=' => '>=',
'<' => '<',
'<=' => '<=',
'LIKE' => 'LIKE',
'NOT LIKE' => 'NOT LIKE',
'IN' => 'IN',
'NOT IN' => 'NOT IN',
'BETWEEN' => 'BETWEEN',
'NOT BETWEEN' => 'NOT BETWEEN',
'EXISTS' => 'EXISTS',
'NOT EXISTS' => 'NOT EXISTS',
'REGEXP' => 'REGEXP',
'NOT REGEXP' => 'NOT REGEXP',
'RLIKE' => 'RLIKE',
),
),
array(
'type' => 'select',
'label' => __( 'Type', 'insert-headers-and-footers' ),
'description' => __( 'Type of custom field.', 'insert-headers-and-footers' ),
'id' => 'meta_type',
'name' => 'meta_type[]',
'repeater' => 'meta_query',
'default' => 'CHAR',
'options' => array(
'NUMERIC' => 'NUMERIC',
'BINARY' => 'BINARY',
'CHAR' => 'CHAR',
'DATE' => 'DATE',
'DATETIME' => 'DATETIME',
'DECIMAL' => 'DECIMAL',
'SIGNED' => 'SIGNED',
'TIME' => 'TIME',
'UNSIGNED' => 'UNSIGNED',
),
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add another meta query', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add Meta" button below to use multiple meta queries.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add Meta', 'insert-headers-and-footers' ),
'id' => 'meta_query', // Repeater to repeat when clicked.
),
array(
'type' => 'select',
'label' => __( 'Relation', 'insert-headers-and-footers' ),
'id' => 'meta_relation',
'default' => 'AND',
'options' => array(
'AND' => __( 'AND (default)', 'insert-headers-and-footers' ),
'OR' => __( 'OR', 'insert-headers-and-footers' ),
),
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$query_variable = '$' . str_replace( '$', '', $this->get_value( 'var_name' ) );
$loop_code = '';
if ( 'true' === $this->get_value( 'loop' ) ) {
$loop_code = "
if ( {$query_variable}->have_posts() ) {
while ( {$query_variable}->have_posts() ) {
{$query_variable}->the_post();
// Add you post code here.
}
} else {
// Display a no posts found message here.
}
// Reset post data.
wp_reset_postdata();
";
}
$optional_values = array(
'post__in' => false,
'post__not_in' => false, // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
'post_parent__in' => false,
'post_parent__not_in' => false,
'post_name__in' => true,
'post_type' => true,
'post_status' => true,
'author' => true,
'author__not_in' => false,
'author_name' => true,
's' => true,
'order' => true,
'orderby' => true,
//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'meta_key' => true,
'nopaging' => false,
'paged' => false,
'posts_per_page' => false,
'offset' => false,
'ignore_sticky_posts' => false,
);
$args = '';
foreach ( $optional_values as $optional_value => $quotes ) {
$args .= $this->get_optional_value( $optional_value, $quotes );
}
$tax_query = '';
$taxonomies = $this->get_value( 'taxonomy' );
$fields = $this->get_value( 'field' );
$terms = $this->get_value( 'terms' );
$include_children = $this->get_value( 'include_children' );
$operator = $this->get_value( 'operator' );
if ( ! empty( $taxonomies ) ) {
$tax_query_arrays = array();
foreach ( $taxonomies as $key => $taxonomy ) {
if ( empty( $taxonomy ) ) {
continue;
}
$params = array(
$this->get_optional_value_code( $fields[ $key ], $this->get_default_value( 'field' ), 'field', true ),
$this->get_optional_value_code( $terms[ $key ], $this->get_default_value( 'terms' ), 'terms', true, true ),
$this->get_optional_value_code( $include_children[ $key ], $this->get_default_value( 'include_children' ), 'include_children' ),
$this->get_optional_value_code( $operator[ $key ], $this->get_default_value( 'operator' ), 'operator', true ),
);
$params = array_filter( $params );
$params = str_replace( "\n", '', $params );
$params = implode( "\n\t\t", $params );
if ( ! empty( $params ) ) {
$params = "\n\t\t" . $params;
}
$tax_query_arrays[] = "\n\t\t\tarray(
'taxonomy' => '$taxonomy',$params
),";
}
if ( ! empty( $tax_query_arrays ) ) {
$tax_query = "\t\t'tax_query' => array(";
if ( count( $tax_query_arrays ) > 1 ) {
$optional_relation = $this->get_optional_value( 'relation', true );
if ( ! empty( $optional_relation ) ) {
$tax_query .= "\n\t" . str_replace( "\n", '', $optional_relation );
}
}
$tax_query .= implode( '', $tax_query_arrays );
$tax_query .= '
),';
}
}
$meta_query = '';
$meta_keys = $this->get_value( 'key' );
$meta_values = $this->get_value( 'value' );
$meta_compares = $this->get_value( 'compare' );
$meta_types = $this->get_value( 'meta_type' );
if ( ! empty( $meta_keys ) ) {
$meta_query_arrays = array();
foreach ( $meta_keys as $key => $meta_key ) {
if ( empty( $meta_key ) ) {
continue;
}
$params = array(
$this->get_optional_value_code( $meta_values[ $key ], $this->get_default_value( 'value' ), 'value', true ),
$this->get_optional_value_code( $meta_compares[ $key ], $this->get_default_value( 'compare' ), 'compare', true ),
$this->get_optional_value_code( $meta_types[ $key ], $this->get_default_value( 'meta_type' ), 'type', true ),
);
$params = array_filter( $params );
$params = str_replace( "\n", '', $params );
$params = implode( "\n\t\t", $params );
if ( ! empty( $params ) ) {
$params = "\n\t\t" . $params;
}
$meta_query_arrays[] = "\n\t\t\tarray(
'key' => '$meta_key',$params
),";
}
if ( ! empty( $meta_query_arrays ) ) {
$meta_query = "\n\t\t'meta_query' => array(";
if ( count( $meta_query_arrays ) > 1 ) {
$optional_relation = $this->get_optional_value( 'meta_relation', true, 'relation' );
if ( ! empty( $optional_relation ) ) {
$meta_query .= "\n\t" . str_replace( "\n", '', $optional_relation );
}
}
$meta_query .= implode( '', $meta_query_arrays );
$meta_query .= '
),';
}
}
$args = "\n" . $args;
return '// Query Posts.
// Query arguments.
$query_args = array(' . $args . $tax_query . $meta_query . '
);
// Run the query.
' . $query_variable . ' = new WP_Query( $query_args );
' . $loop_code . '
';
}
}
@@ -0,0 +1,288 @@
<?php
/**
* Generate a snippet for Article schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Article class.
*/
class WPCode_Generator_Schema_Article extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-article';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Article Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for articles, blog posts, and news articles.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Article schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'article' => array(
'label' => __( 'Article Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic article information.
array(
array(
'type' => 'text',
'label' => __( 'Article Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the article.', 'insert-headers-and-footers' ),
'id' => 'article_title',
'default' => '',
'placeholder' => __( 'My Article Title', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Article Description', 'insert-headers-and-footers' ),
'description' => __( 'A brief description or summary of the article.', 'insert-headers-and-footers' ),
'id' => 'article_description',
'default' => '',
'placeholder' => __( 'Description of the article...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
),
array(
array(
'type' => 'select',
'label' => __( 'Article Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of article.', 'insert-headers-and-footers' ),
'id' => 'article_type',
'default' => 'Article',
'options' => array(
'Article' => __( 'Article', 'insert-headers-and-footers' ),
'BlogPosting' => __( 'Blog Post', 'insert-headers-and-footers' ),
'NewsArticle' => __( 'News Article', 'insert-headers-and-footers' ),
'TechArticle' => __( 'Tech Article', 'insert-headers-and-footers' ),
'ScholarlyArticle' => __( 'Scholarly Article', 'insert-headers-and-footers' ),
'SocialMediaPosting' => __( 'Social Media Post', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Article URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the article.', 'insert-headers-and-footers' ),
'id' => 'article_url',
'default' => '',
'placeholder' => 'https://example.com/article',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
// Column 2 - Dates and images.
array(
array(
'type' => 'date',
'label' => __( 'Published Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the article was published.', 'insert-headers-and-footers' ),
'id' => 'article_published_date',
'default' => '',
'placeholder' => '2025-01-01',
),
array(
'type' => 'date',
'label' => __( 'Modified Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the article was last modified.', 'insert-headers-and-footers' ),
'id' => 'article_modified_date',
'default' => '',
'placeholder' => '2025-01-02',
),
array(
'type' => 'text',
'label' => __( 'Featured Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of the article\'s featured image.', 'insert-headers-and-footers' ),
'id' => 'article_image',
'default' => '',
'placeholder' => 'https://example.com/image.jpg',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
),
),
'author' => array(
'label' => __( 'Author', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Author details.
array(
array(
'type' => 'text',
'label' => __( 'Author Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the article author.', 'insert-headers-and-footers' ),
'id' => 'author_name',
'default' => '',
'placeholder' => __( 'John Doe', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Author URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the author\'s profile or website.', 'insert-headers-and-footers' ),
'id' => 'author_url',
'default' => '',
'placeholder' => 'https://example.com/author',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
),
),
'publisher' => array(
'label' => __( 'Publisher', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Publisher details.
array(
array(
'type' => 'text',
'label' => __( 'Publisher Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the publisher.', 'insert-headers-and-footers' ),
'id' => 'publisher_name',
'default' => '',
'placeholder' => __( 'Publisher Name', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'first_name' ),
),
array(
'type' => 'text',
'label' => __( 'Publisher Logo', 'insert-headers-and-footers' ),
'description' => __( 'URL of the publisher\'s logo.', 'insert-headers-and-footers' ),
'id' => 'publisher_logo',
'default' => '',
'placeholder' => 'https://example.com/logo.png',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => $this->get_value( 'article_type' ),
'headline' => $this->get_value( 'article_title' ),
'description' => $this->get_value( 'article_description' ),
);
// Add URL if set.
$url = $this->get_value( 'article_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add dates.
$published_date = $this->get_value( 'article_published_date' );
if ( ! empty( $published_date ) ) {
$schema['datePublished'] = $published_date;
}
$modified_date = $this->get_value( 'article_modified_date' );
if ( ! empty( $modified_date ) ) {
$schema['dateModified'] = $modified_date;
}
// Add image if set.
$image = $this->get_value( 'article_image' );
if ( ! empty( $image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image,
);
}
// Add author details.
$author_name = $this->get_value( 'author_name' );
if ( ! empty( $author_name ) ) {
$schema['author'] = array(
'@type' => 'Person',
'name' => $author_name,
);
$author_url = $this->get_value( 'author_url' );
if ( ! empty( $author_url ) ) {
$schema['author']['url'] = $author_url;
}
}
// Add publisher details.
$publisher_name = $this->get_value( 'publisher_name' );
if ( ! empty( $publisher_name ) ) {
$schema['publisher'] = array(
'@type' => 'Organization',
'name' => $publisher_name,
);
$publisher_logo = $this->get_value( 'publisher_logo' );
if ( ! empty( $publisher_logo ) ) {
$schema['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => $publisher_logo,
);
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,109 @@
<?php
/**
* Base class for schema markup generators with smart tags support.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Base class.
*/
abstract class WPCode_Generator_Schema_Base extends WPCode_Generator_Type {
/**
* Initialize smart tags.
*
* @var WPCode_Smart_Tags_Pro
*/
protected $smart_tags;
/**
* Location where the snippet will run after being saved.
*
* @var string
*/
public $location = 'site_wide_header';
/**
* Constructor.
*/
public function __construct() {
$this->smart_tags = clone wpcode()->smart_tags;
if ( $this->smart_tags instanceof WPCode_Smart_Tags_Lite ) {
$this->smart_tags->utm_medium = 'generator';
$this->smart_tags->utm_content = $this->name;
}
parent::__construct();
}
/**
* Get all available smart tags.
*
* @return array
*/
public function get_smart_tags() {
return $this->smart_tags->get_tags();
}
/**
* Render a field with smart tags support.
*
* @param array $field The field config.
*
* @return void
*/
public function render_field( $field ) {
// Check if the field type is set.
if ( ! isset( $field['type'] ) ) {
return;
}
$type = $field['type'];
// Check if we have a method of rendering the field.
if ( ! method_exists( $this, 'render_field_' . $type ) ) {
return;
}
$this->add_field_wrap( $field );
// Add smart tags above the field if enabled for this field and pro is installed.
if ( ! empty( $field['smart_tags'] ) && in_array( $type, array( 'text', 'textarea', 'html' ), true ) ) {
$this->render_smart_tags_picker( $field['id'], $field );
}
call_user_func_array( array( $this, 'render_field_' . $type ), array( $field ) );
$this->add_field_wrap( $field, true );
}
/**
* Render smart tags picker above an input field.
*
* @param string $target_id The ID of the input field.
* @param array $field The field configuration.
*
* @return void
*/
protected function render_smart_tags_picker( $target_id, $field ) {
$predefined_tags = ! empty( $field['predefined_tags'] ) ? $field['predefined_tags'] : array();
$this->smart_tags->smart_tags_picker( $target_id, $predefined_tags );
}
/**
* Override the get_snippet_code method to process smart tags.
*
* @return string
*/
public function get_snippet_code() {
return $this->generate_snippet_code();
}
/**
* Generate the snippet code without processing smart tags.
* This should be implemented by child classes.
*
* @return string
*/
abstract protected function generate_snippet_code();
}
@@ -0,0 +1,317 @@
<?php
/**
* Generate a snippet for Book schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Book class.
*/
class WPCode_Generator_Schema_Book extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-book';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Book Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for books, including novels, textbooks, and publications.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Book schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'book' => array(
'label' => __( 'Book Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic book information.
array(
array(
'type' => 'text',
'label' => __( 'Book Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the book.', 'insert-headers-and-footers' ),
'id' => 'book_title',
'default' => '',
'placeholder' => __( 'My Book Title', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Book Description', 'insert-headers-and-footers' ),
'description' => __( 'A brief description or summary of the book.', 'insert-headers-and-footers' ),
'id' => 'book_description',
'default' => '',
'placeholder' => __( 'Description of the book...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'date',
'label' => __( 'Date Published', 'insert-headers-and-footers' ),
'description' => __( 'The date when the book was published.', 'insert-headers-and-footers' ),
'id' => 'book_date_published',
'default' => '',
'placeholder' => '2024-03-20',
),
),
array(
array(
'type' => 'text',
'label' => __( 'ISBN', 'insert-headers-and-footers' ),
'description' => __( 'The ISBN of the book.', 'insert-headers-and-footers' ),
'id' => 'book_isbn',
'default' => '',
'smart_tags' => true,
'placeholder' => '978-3-16-148410-0',
),
array(
'type' => 'text',
'label' => __( 'Book URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL where the book can be purchased or viewed.', 'insert-headers-and-footers' ),
'id' => 'book_url',
'default' => '',
'placeholder' => 'https://example.com/book',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
array(
'type' => 'text',
'label' => __( 'Book Edition', 'insert-headers-and-footers' ),
'description' => __( 'The edition of the book.', 'insert-headers-and-footers' ),
'id' => 'book_edition',
'default' => '',
'smart_tags' => true,
'placeholder' => '1st Edition',
),
),
// Column 2 - Additional details.
array(
array(
'type' => 'text',
'label' => __( 'Number of Pages', 'insert-headers-and-footers' ),
'description' => __( 'The number of pages in the book.', 'insert-headers-and-footers' ),
'id' => 'book_number_of_pages',
'default' => '',
'smart_tags' => true,
'placeholder' => '300',
),
array(
'type' => 'text',
'label' => __( 'Book Format', 'insert-headers-and-footers' ),
'description' => __( 'The format of the book (e.g., Hardcover, Paperback, EBook).', 'insert-headers-and-footers' ),
'id' => 'book_format',
'smart_tags' => true,
'default' => '',
'placeholder' => 'Hardcover',
),
array(
'type' => 'text',
'label' => __( 'Book Cover Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of the book\'s cover image.', 'insert-headers-and-footers' ),
'id' => 'book_image',
'default' => '',
'placeholder' => 'https://example.com/book-cover.jpg',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
),
),
'author' => array(
'label' => __( 'Author', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Author details.
array(
array(
'type' => 'text',
'label' => __( 'Author Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the book author.', 'insert-headers-and-footers' ),
'id' => 'author_name',
'default' => '',
'placeholder' => __( 'John Doe', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Author URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the author\'s profile or website.', 'insert-headers-and-footers' ),
'id' => 'author_url',
'default' => '',
'placeholder' => 'https://example.com/author',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
),
),
'publisher' => array(
'label' => __( 'Publisher', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Publisher details.
array(
array(
'type' => 'text',
'label' => __( 'Publisher Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the publisher.', 'insert-headers-and-footers' ),
'id' => 'publisher_name',
'default' => '',
'placeholder' => __( 'Publisher Name', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Publisher Logo', 'insert-headers-and-footers' ),
'description' => __( 'URL of the publisher\'s logo.', 'insert-headers-and-footers' ),
'id' => 'publisher_logo',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/logo.png',
'is_image_url' => true,
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Book',
'name' => $this->get_value( 'book_title' ),
'description' => $this->get_value( 'book_description' ),
);
// Add date published if set.
$date_published = $this->get_value( 'book_date_published' );
if ( ! empty( $date_published ) ) {
$schema['datePublished'] = $date_published;
}
// Add ISBN if set.
$isbn = $this->get_value( 'book_isbn' );
if ( ! empty( $isbn ) ) {
$schema['isbn'] = $isbn;
}
// Add URL if set.
$url = $this->get_value( 'book_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add book details.
$edition = $this->get_value( 'book_edition' );
if ( ! empty( $edition ) ) {
$schema['bookEdition'] = $edition;
}
$number_of_pages = $this->get_value( 'book_number_of_pages' );
if ( ! empty( $number_of_pages ) ) {
$schema['numberOfPages'] = $number_of_pages;
}
$format = $this->get_value( 'book_format' );
if ( ! empty( $format ) ) {
$schema['bookFormat'] = $format;
}
// Add image if set.
$image = $this->get_value( 'book_image' );
if ( ! empty( $image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image,
);
}
// Add author details.
$author_name = $this->get_value( 'author_name' );
if ( ! empty( $author_name ) ) {
$schema['author'] = array(
'@type' => 'Person',
'name' => $author_name,
);
$author_url = $this->get_value( 'author_url' );
if ( ! empty( $author_url ) ) {
$schema['author']['url'] = $author_url;
}
}
// Add publisher details.
$publisher_name = $this->get_value( 'publisher_name' );
if ( ! empty( $publisher_name ) ) {
$schema['publisher'] = array(
'@type' => 'Organization',
'name' => $publisher_name,
);
$publisher_logo = $this->get_value( 'publisher_logo' );
if ( ! empty( $publisher_logo ) ) {
$schema['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => $publisher_logo,
);
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,317 @@
<?php
/**
* Generate a snippet for Car schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Car class.
*/
class WPCode_Generator_Schema_Car extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-car';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Car Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for cars and vehicles to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Car schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'vehicle' => array(
'label' => __( 'Vehicle Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic vehicle information.
array(
array(
'type' => 'text',
'label' => __( 'Vehicle Name', 'insert-headers-and-footers' ),
'description' => __( 'The name or model of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'vehicle_name',
'default' => '',
'placeholder' => __( 'Toyota Camry', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Vehicle Description', 'insert-headers-and-footers' ),
'description' => __( 'A brief description of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'vehicle_description',
'default' => '',
'placeholder' => __( 'Description of the vehicle...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Vehicle URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL where the vehicle can be viewed or purchased.', 'insert-headers-and-footers' ),
'id' => 'vehicle_url',
'default' => '',
'placeholder' => 'https://example.com/vehicle',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Brand', 'insert-headers-and-footers' ),
'description' => __( 'The brand or manufacturer of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'vehicle_brand',
'default' => '',
'smart_tags' => true,
'placeholder' => 'Toyota',
),
array(
'type' => 'text',
'label' => __( 'Vehicle Identification Number (VIN)', 'insert-headers-and-footers' ),
'description' => __( 'The VIN of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'vehicle_vin',
'default' => '',
'smart_tags' => true,
'placeholder' => '1HGCM82633A123456',
),
array(
'type' => 'text',
'label' => __( 'Model Year', 'insert-headers-and-footers' ),
'description' => __( 'The model year of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'vehicle_model_year',
'default' => '',
'smart_tags' => true,
'placeholder' => '2023',
),
),
// Column 2 - Additional details.
array(
array(
'type' => 'text',
'label' => __( 'Fuel Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of fuel used by the vehicle.', 'insert-headers-and-footers' ),
'id' => 'vehicle_fuel_type',
'default' => '',
'smart_tags' => true,
'placeholder' => 'Gasoline',
),
array(
'type' => 'text',
'label' => __( 'Vehicle Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of the vehicle\'s image.', 'insert-headers-and-footers' ),
'id' => 'vehicle_image',
'default' => '',
'placeholder' => 'https://example.com/vehicle-image.jpg',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
),
),
'seller' => array(
'label' => __( 'Seller', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Seller details.
array(
array(
'type' => 'text',
'label' => __( 'Seller Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the seller or dealership.', 'insert-headers-and-footers' ),
'id' => 'seller_name',
'default' => '',
'placeholder' => __( 'ABC Motors', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'first_name' ),
),
array(
'type' => 'text',
'label' => __( 'Seller URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the seller\'s website.', 'insert-headers-and-footers' ),
'id' => 'seller_url',
'default' => '',
'placeholder' => 'https://example.com/dealership',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
),
),
'offer' => array(
'label' => __( 'Offer', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Offer details.
array(
array(
'type' => 'text',
'label' => __( 'Price', 'insert-headers-and-footers' ),
'description' => __( 'The price of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'offer_price',
'default' => '',
'smart_tags' => true,
'placeholder' => '25000',
),
array(
'type' => 'text',
'label' => __( 'Price Currency', 'insert-headers-and-footers' ),
'description' => __( 'The currency of the price (e.g., USD, EUR).', 'insert-headers-and-footers' ),
'id' => 'offer_price_currency',
'default' => 'USD',
'smart_tags' => true,
'placeholder' => 'USD',
),
array(
'type' => 'select',
'label' => __( 'Availability', 'insert-headers-and-footers' ),
'description' => __( 'The availability status of the vehicle.', 'insert-headers-and-footers' ),
'id' => 'offer_availability',
'default' => 'InStock',
'options' => array(
'InStock' => __( 'In Stock', 'insert-headers-and-footers' ),
'OutOfStock' => __( 'Out of Stock', 'insert-headers-and-footers' ),
'PreOrder' => __( 'Pre-Order', 'insert-headers-and-footers' ),
'Discontinued' => __( 'Discontinued', 'insert-headers-and-footers' ),
),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Vehicle',
'name' => $this->get_value( 'vehicle_name' ),
'description' => $this->get_value( 'vehicle_description' ),
);
// Add URL if set.
$url = $this->get_value( 'vehicle_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add VIN if set.
$vin = $this->get_value( 'vehicle_vin' );
if ( ! empty( $vin ) ) {
$schema['vehicleIdentificationNumber'] = $vin;
}
// Add brand if set.
$brand = $this->get_value( 'vehicle_brand' );
if ( ! empty( $brand ) ) {
$schema['brand'] = array(
'@type' => 'Brand',
'name' => $brand,
);
}
// Add model year if set.
$model_year = $this->get_value( 'vehicle_model_year' );
if ( ! empty( $model_year ) ) {
$schema['modelDate'] = $model_year;
}
// Add fuel type if set.
$fuel_type = $this->get_value( 'vehicle_fuel_type' );
if ( ! empty( $fuel_type ) ) {
$schema['fuelType'] = $fuel_type;
}
// Add image if set.
$image = $this->get_value( 'vehicle_image' );
if ( ! empty( $image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image,
);
}
// Add seller details if set.
$seller_name = $this->get_value( 'seller_name' );
if ( ! empty( $seller_name ) ) {
$schema['seller'] = array(
'@type' => 'Organization',
'name' => $seller_name,
);
$seller_url = $this->get_value( 'seller_url' );
if ( ! empty( $seller_url ) ) {
$schema['seller']['url'] = $seller_url;
}
}
// Add offer details if set.
$price = $this->get_value( 'offer_price' );
if ( ! empty( $price ) ) {
$schema['offers'] = array(
'@type' => 'Offer',
'price' => $price,
'priceCurrency' => $this->get_value( 'offer_price_currency' ),
'availability' => $this->get_value( 'offer_availability' ),
);
// Add seller to offer if available.
if ( ! empty( $seller_name ) ) {
$schema['offers']['seller'] = $schema['seller'];
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,352 @@
<?php
/**
* Generate a snippet for Course schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Course class.
*/
class WPCode_Generator_Schema_Course extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-course';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Course Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for courses to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Course schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'course' => array(
'label' => __( 'Course Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic course information.
array(
array(
'type' => 'text',
'label' => __( 'Course Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the course.', 'insert-headers-and-footers' ),
'id' => 'course_name',
'default' => '',
'placeholder' => __( 'Introduction to Web Development', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Course Description', 'insert-headers-and-footers' ),
'description' => __( 'A brief description of the course.', 'insert-headers-and-footers' ),
'id' => 'course_description',
'default' => '',
'placeholder' => __( 'Description of the course...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Course URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL where the course can be accessed.', 'insert-headers-and-footers' ),
'id' => 'course_url',
'default' => '',
'placeholder' => 'https://example.com/course',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Provider Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the course provider or institution.', 'insert-headers-and-footers' ),
'id' => 'provider_name',
'default' => '',
'placeholder' => 'University of Example',
'smart_tags' => true,
'predefined_tags' => array( 'site_name' ),
),
array(
'type' => 'text',
'label' => __( 'Provider URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the course provider\'s website.', 'insert-headers-and-footers' ),
'id' => 'provider_url',
'default' => '',
'placeholder' => 'https://example.com',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
// Column 2 - Additional details.
array(
array(
'type' => 'text',
'label' => __( 'Course Code', 'insert-headers-and-footers' ),
'description' => __( 'The course code or identifier.', 'insert-headers-and-footers' ),
'id' => 'course_code',
'default' => '',
'smart_tags' => true,
'placeholder' => 'CS101',
),
array(
'type' => 'text',
'label' => __( 'Course Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of the course image.', 'insert-headers-and-footers' ),
'id' => 'course_image',
'default' => '',
'placeholder' => 'https://example.com/course-image.jpg',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
),
),
'instructor' => array(
'label' => __( 'Instructor', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Instructor details.
array(
array(
'type' => 'text',
'label' => __( 'Instructor Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the course instructor.', 'insert-headers-and-footers' ),
'id' => 'instructor_name',
'default' => '',
'placeholder' => __( 'John Doe', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Instructor URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the instructor\'s profile or website.', 'insert-headers-and-footers' ),
'id' => 'instructor_url',
'default' => '',
'placeholder' => 'https://example.com/instructor',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
),
),
'pricing' => array(
'label' => __( 'Pricing & Availability', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Pricing details.
array(
array(
'type' => 'select',
'label' => __( 'Course Type', 'insert-headers-and-footers' ),
'description' => __( 'Whether this is a free or paid course.', 'insert-headers-and-footers' ),
'id' => 'course_type',
'default' => 'paid',
'options' => array(
'paid' => __( 'Paid Course', 'insert-headers-and-footers' ),
'free' => __( 'Free Course', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Price', 'insert-headers-and-footers' ),
'description' => __( 'The price of the course (leave empty for free courses).', 'insert-headers-and-footers' ),
'id' => 'course_price',
'smart_tags' => true,
'default' => '',
'placeholder' => '99.99',
),
array(
'type' => 'text',
'label' => __( 'Currency', 'insert-headers-and-footers' ),
'description' => __( 'The currency code (e.g., USD, EUR).', 'insert-headers-and-footers' ),
'id' => 'course_currency',
'smart_tags' => true,
'default' => 'USD',
'placeholder' => 'USD',
),
),
// Column 2 - Additional pricing details.
array(
array(
'type' => 'date',
'label' => __( 'Valid From', 'insert-headers-and-footers' ),
'description' => __( 'The date when the course becomes available (YYYY-MM-DD).', 'insert-headers-and-footers' ),
'id' => 'valid_from',
'default' => '',
'placeholder' => '2024-01-01',
),
array(
'type' => 'date',
'label' => __( 'Valid Until', 'insert-headers-and-footers' ),
'description' => __( 'The date when the course offer expires (YYYY-MM-DD).', 'insert-headers-and-footers' ),
'id' => 'valid_until',
'default' => '',
'placeholder' => '2024-12-31',
),
array(
'type' => 'select',
'label' => __( 'Availability', 'insert-headers-and-footers' ),
'description' => __( 'The availability status of the course.', 'insert-headers-and-footers' ),
'id' => 'availability',
'default' => 'InStock',
'options' => array(
'InStock' => __( 'In Stock', 'insert-headers-and-footers' ),
'OutOfStock' => __( 'Out of Stock', 'insert-headers-and-footers' ),
'PreOrder' => __( 'Pre-order', 'insert-headers-and-footers' ),
'Discontinued' => __( 'Discontinued', 'insert-headers-and-footers' ),
),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Course',
'name' => $this->get_value( 'course_name' ),
'description' => $this->get_value( 'course_description' ),
);
// Add URL if set.
$url = $this->get_value( 'course_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add course code if set.
$code = $this->get_value( 'course_code' );
if ( ! empty( $code ) ) {
$schema['courseCode'] = $code;
}
// Add provider details if set.
$provider_name = $this->get_value( 'provider_name' );
if ( ! empty( $provider_name ) ) {
$schema['provider'] = array(
'@type' => 'Organization',
'name' => $provider_name,
);
$provider_url = $this->get_value( 'provider_url' );
if ( ! empty( $provider_url ) ) {
$schema['provider']['url'] = $provider_url;
}
}
// Add image if set.
$image = $this->get_value( 'course_image' );
if ( ! empty( $image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image,
);
}
// Add instructor details if set.
$instructor_name = $this->get_value( 'instructor_name' );
if ( ! empty( $instructor_name ) ) {
$schema['instructor'] = array(
'@type' => 'Person',
'name' => $instructor_name,
);
$instructor_url = $this->get_value( 'instructor_url' );
if ( ! empty( $instructor_url ) ) {
$schema['instructor']['url'] = $instructor_url;
}
}
// Add pricing and availability information.
$course_type = $this->get_value( 'course_type' );
$schema['isAccessibleForFree'] = ( 'free' === $course_type );
if ( 'paid' === $course_type ) {
$price = $this->get_value( 'course_price' );
$currency = $this->get_value( 'course_currency' );
if ( ! empty( $price ) ) {
$schema['offers'] = array(
'@type' => 'Offer',
'price' => $price,
'priceCurrency' => $currency,
'availability' => 'https://schema.org/' . $this->get_value( 'availability' ),
);
// Add valid from date if set.
$valid_from = $this->get_value( 'valid_from' );
if ( ! empty( $valid_from ) ) {
$schema['offers']['validFrom'] = $valid_from;
}
// Add valid until date if set.
$valid_until = $this->get_value( 'valid_until' );
if ( ! empty( $valid_until ) ) {
$schema['offers']['validThrough'] = $valid_until;
}
// Add URL to the offer if course URL is set.
if ( ! empty( $url ) ) {
$schema['offers']['url'] = $url;
}
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,256 @@
<?php
/**
* Generate a snippet for Dataset schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Dataset class.
*/
class WPCode_Generator_Schema_Dataset extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-dataset';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Dataset Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for datasets to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Dataset schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'dataset' => array(
'label' => __( 'Dataset Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic dataset information.
array(
array(
'type' => 'text',
'label' => __( 'Dataset Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the dataset.', 'insert-headers-and-footers' ),
'id' => 'dataset_name',
'default' => '',
'placeholder' => __( 'Global Climate Data 2023', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Dataset Description', 'insert-headers-and-footers' ),
'description' => __( 'A brief description of the dataset.', 'insert-headers-and-footers' ),
'id' => 'dataset_description',
'default' => '',
'placeholder' => __( 'Description of the dataset...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Dataset URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL where the dataset can be accessed.', 'insert-headers-and-footers' ),
'id' => 'dataset_url',
'default' => '',
'placeholder' => 'https://example.com/dataset',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Publisher Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the dataset publisher.', 'insert-headers-and-footers' ),
'id' => 'publisher_name',
'default' => '',
'placeholder' => 'Data Organization',
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Publisher URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the publisher\'s website.', 'insert-headers-and-footers' ),
'id' => 'publisher_url',
'default' => '',
'placeholder' => 'https://example.com',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
// Column 2 - Additional details.
array(
array(
'type' => 'text',
'label' => __( 'Version', 'insert-headers-and-footers' ),
'description' => __( 'The version of the dataset.', 'insert-headers-and-footers' ),
'id' => 'version',
'default' => '',
'smart_tags' => true,
'placeholder' => '1.0.0',
),
array(
'type' => 'text',
'label' => __( 'License', 'insert-headers-and-footers' ),
'description' => __( 'The license under which the dataset is distributed.', 'insert-headers-and-footers' ),
'id' => 'license',
'default' => '',
'smart_tags' => true,
'placeholder' => 'https://creativecommons.org/licenses/by/4.0/',
),
),
),
),
'distribution' => array(
'label' => __( 'Distribution', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Distribution details.
array(
array(
'type' => 'text',
'label' => __( 'Distribution URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL where the dataset can be downloaded.', 'insert-headers-and-footers' ),
'id' => 'distribution_url',
'default' => '',
'placeholder' => 'https://example.com/dataset/download',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
array(
'type' => 'text',
'label' => __( 'File Format', 'insert-headers-and-footers' ),
'description' => __( 'The format of the dataset file (e.g., CSV, JSON, XML).', 'insert-headers-and-footers' ),
'id' => 'file_format',
'default' => '',
'smart_tags' => true,
'placeholder' => 'CSV',
),
array(
'type' => 'text',
'label' => __( 'File Size', 'insert-headers-and-footers' ),
'description' => __( 'The size of the dataset file.', 'insert-headers-and-footers' ),
'id' => 'file_size',
'default' => '',
'smart_tags' => true,
'placeholder' => '10MB',
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Dataset',
'name' => $this->get_value( 'dataset_name' ),
'description' => $this->get_value( 'dataset_description' ),
);
// Add URL if set.
$url = $this->get_value( 'dataset_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add version if set.
$version = $this->get_value( 'version' );
if ( ! empty( $version ) ) {
$schema['version'] = $version;
}
// Add publisher details if set.
$publisher_name = $this->get_value( 'publisher_name' );
if ( ! empty( $publisher_name ) ) {
$schema['publisher'] = array(
'@type' => 'Organization',
'name' => $publisher_name,
);
$publisher_url = $this->get_value( 'publisher_url' );
if ( ! empty( $publisher_url ) ) {
$schema['publisher']['url'] = $publisher_url;
}
}
// Add license if set.
$license = $this->get_value( 'license' );
if ( ! empty( $license ) ) {
$schema['license'] = $license;
}
// Add distribution details if set.
$distribution_url = $this->get_value( 'distribution_url' );
if ( ! empty( $distribution_url ) ) {
$schema['distribution'] = array(
'@type' => 'DataDownload',
'url' => $distribution_url,
);
$file_format = $this->get_value( 'file_format' );
if ( ! empty( $file_format ) ) {
$schema['distribution']['encodingFormat'] = $file_format;
}
$file_size = $this->get_value( 'file_size' );
if ( ! empty( $file_size ) ) {
$schema['distribution']['contentSize'] = $file_size;
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,469 @@
<?php
/**
* Generate a snippet for Event schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Event class.
*/
class WPCode_Generator_Schema_Event extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-event';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Default schema type to use.
*
* @var string
*/
private $schema_type = 'Event';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Event Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for conferences, concerts, exhibitions, and other events.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Event schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'event' => array(
'label' => __( 'Event Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic event information.
array(
array(
'type' => 'text',
'label' => __( 'Event Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the event.', 'insert-headers-and-footers' ),
'id' => 'event_name',
'default' => '',
'placeholder' => __( 'My Awesome Event', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Event Description', 'insert-headers-and-footers' ),
'description' => __( 'A description of the event.', 'insert-headers-and-footers' ),
'id' => 'event_description',
'default' => '',
'placeholder' => __( 'Description of the event...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Event Image URL', 'insert-headers-and-footers' ),
'description' => __( 'URL of an image representing the event.', 'insert-headers-and-footers' ),
'id' => 'event_image',
'default' => '',
'placeholder' => 'https://example.com/event-image.jpg',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
// Column 2 - Dates and status.
array(
array(
'type' => 'date_and_time',
'label' => __( 'Start Date & Time', 'insert-headers-and-footers' ),
'description' => __( 'The start date and time (ISO 8601 format).', 'insert-headers-and-footers' ),
'id' => 'event_start_date',
'default' => '',
'placeholder' => '2025-04-15T09:00',
),
array(
'type' => 'date_and_time',
'label' => __( 'End Date & Time', 'insert-headers-and-footers' ),
'description' => __( 'The end date and time (ISO 8601 format).', 'insert-headers-and-footers' ),
'id' => 'event_end_date',
'default' => '',
'placeholder' => '2025-04-15T10:00',
),
array(
'type' => 'select',
'label' => __( 'Event Status', 'insert-headers-and-footers' ),
'description' => __( 'The current status of the event.', 'insert-headers-and-footers' ),
'id' => 'event_status',
'default' => 'https://schema.org/EventScheduled',
'options' => array(
'https://schema.org/EventScheduled' => __( 'Scheduled', 'insert-headers-and-footers' ),
'https://schema.org/EventCancelled' => __( 'Cancelled', 'insert-headers-and-footers' ),
'https://schema.org/EventPostponed' => __( 'Postponed', 'insert-headers-and-footers' ),
'https://schema.org/EventRescheduled' => __( 'Rescheduled', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Attendance Mode', 'insert-headers-and-footers' ),
'description' => __( 'Whether the event is online, offline, or mixed.', 'insert-headers-and-footers' ),
'id' => 'event_attendance_mode',
'default' => 'https://schema.org/OfflineEventAttendanceMode',
'options' => array(
'https://schema.org/OfflineEventAttendanceMode' => __( 'Offline', 'insert-headers-and-footers' ),
'https://schema.org/OnlineEventAttendanceMode' => __( 'Online', 'insert-headers-and-footers' ),
'https://schema.org/MixedEventAttendanceMode' => __( 'Mixed (Online & Offline)', 'insert-headers-and-footers' ),
),
),
),
),
),
'location' => array(
'label' => __( 'Location', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Place information.
array(
array(
'type' => 'text',
'label' => __( 'Venue Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the venue where the event takes place.', 'insert-headers-and-footers' ),
'id' => 'location_name',
'default' => '',
'placeholder' => __( 'Event Center', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'custom_field' ),
),
),
// Column 2 - Address information.
array(
array(
'type' => 'text',
'label' => __( 'Street Address', 'insert-headers-and-footers' ),
'description' => __( 'The street address of the venue.', 'insert-headers-and-footers' ),
'id' => 'location_street',
'default' => '',
'placeholder' => __( '123 Main St', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'City', 'insert-headers-and-footers' ),
'description' => __( 'The city of the venue.', 'insert-headers-and-footers' ),
'id' => 'location_city',
'default' => '',
'placeholder' => __( 'New York', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Postal Code', 'insert-headers-and-footers' ),
'description' => __( 'The postal code of the venue.', 'insert-headers-and-footers' ),
'id' => 'location_postal',
'default' => '',
'placeholder' => __( '10001', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Country Code', 'insert-headers-and-footers' ),
'description' => __( 'The country code of the venue (e.g., US, UK, CA).', 'insert-headers-and-footers' ),
'id' => 'location_country',
'default' => '',
'placeholder' => __( 'US', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
),
),
),
'performer' => array(
'label' => __( 'Performer', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Performer Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of performer at the event.', 'insert-headers-and-footers' ),
'id' => 'performer_type',
'default' => 'PerformingGroup',
'options' => array(
'none' => __( 'No Performer', 'insert-headers-and-footers' ),
'Person' => __( 'Person', 'insert-headers-and-footers' ),
'PerformingGroup' => __( 'Performing Group', 'insert-headers-and-footers' ),
'MusicGroup' => __( 'Music Group', 'insert-headers-and-footers' ),
'DanceGroup' => __( 'Dance Group', 'insert-headers-and-footers' ),
'TheaterGroup' => __( 'Theater Group', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Performer Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the performer or group.', 'insert-headers-and-footers' ),
'id' => 'performer_name',
'default' => '',
'placeholder' => __( 'The Performers', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
),
),
),
'offers' => array(
'label' => __( 'Offers', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Offer details.
array(
array(
'type' => 'text',
'label' => __( 'Offer Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the offer (e.g., General Admission).', 'insert-headers-and-footers' ),
'id' => 'offer_name',
'name' => 'offer_name[]',
'repeater' => 'offer_items',
'default' => '',
'placeholder' => __( 'General Admission', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Price', 'insert-headers-and-footers' ),
'description' => __( 'The price of the ticket.', 'insert-headers-and-footers' ),
'id' => 'offer_price',
'name' => 'offer_price[]',
'repeater' => 'offer_items',
'default' => '',
'placeholder' => __( '25.00', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Currency', 'insert-headers-and-footers' ),
'description' => __( 'The currency code (e.g., USD, EUR, GBP).', 'insert-headers-and-footers' ),
'id' => 'offer_currency',
'name' => 'offer_currency[]',
'repeater' => 'offer_items',
'default' => 'USD',
'placeholder' => __( 'USD', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
),
// Column 2 - Additional offer details.
array(
array(
'type' => 'date',
'label' => __( 'Valid From', 'insert-headers-and-footers' ),
'description' => __( 'The date when the ticket goes on sale (YYYY-MM-DD).', 'insert-headers-and-footers' ),
'id' => 'offer_valid_from',
'name' => 'offer_valid_from[]',
'repeater' => 'offer_items',
'default' => '',
'placeholder' => __( '2025-01-01', 'insert-headers-and-footers' ),
'smart_tags' => false,
),
array(
'type' => 'text',
'label' => __( 'Ticket URL', 'insert-headers-and-footers' ),
'description' => __( 'URL where tickets can be purchased.', 'insert-headers-and-footers' ),
'id' => 'offer_url',
'name' => 'offer_url[]',
'repeater' => 'offer_items',
'default' => '',
'placeholder' => 'https://example.com/tickets',
'smart_tags' => true,
),
array(
'type' => 'select',
'label' => __( 'Availability', 'insert-headers-and-footers' ),
'description' => __( 'The availability status of tickets.', 'insert-headers-and-footers' ),
'id' => 'offer_availability',
'name' => 'offer_availability[]',
'repeater' => 'offer_items',
'default' => 'https://schema.org/InStock',
'options' => array(
'https://schema.org/InStock' => __( 'In Stock', 'insert-headers-and-footers' ),
'https://schema.org/SoldOut' => __( 'Sold Out', 'insert-headers-and-footers' ),
'https://schema.org/PreOrder' => __( 'Pre-Order', 'insert-headers-and-footers' ),
'https://schema.org/OutOfStock' => __( 'Out of Stock', 'insert-headers-and-footers' ),
'https://schema.org/Discontinued' => __( 'Discontinued', 'insert-headers-and-footers' ),
),
),
),
// Column 3 - Repeater button.
array(
array(
'type' => 'repeater_button',
'id' => 'offer_items',
'button_text' => __( 'Add Another Offer', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Event',
'name' => $this->get_value( 'event_name' ),
'description' => $this->get_value( 'event_description' ),
);
$image = $this->get_value( 'event_image' );
if ( ! empty( $image ) ) {
$schema['image'] = $image;
}
$start_date = $this->get_value( 'event_start_date' );
if ( ! empty( $start_date ) ) {
$schema['startDate'] = $start_date;
}
$end_date = $this->get_value( 'event_end_date' );
if ( ! empty( $end_date ) ) {
$schema['endDate'] = $end_date;
}
$schema['eventStatus'] = $this->get_value( 'event_status' );
$schema['eventAttendanceMode'] = $this->get_value( 'event_attendance_mode' );
$location_name = $this->get_value( 'location_name' );
if ( ! empty( $location_name ) ) {
$schema['location'] = array(
'@type' => 'Place',
'name' => $location_name,
);
$street = $this->get_value( 'location_street' );
if ( ! empty( $street ) ) {
$schema['location']['address'] = array(
'@type' => 'PostalAddress',
'streetAddress' => $street,
);
$city = $this->get_value( 'location_city' );
if ( ! empty( $city ) ) {
$schema['location']['address']['addressLocality'] = $city;
}
$postal = $this->get_value( 'location_postal' );
if ( ! empty( $postal ) ) {
$schema['location']['address']['postalCode'] = $postal;
}
$country = $this->get_value( 'location_country' );
if ( ! empty( $country ) ) {
$schema['location']['address']['addressCountry'] = $country;
}
}
}
$performer_type = $this->get_value( 'performer_type' );
$performer_name = $this->get_value( 'performer_name' );
if ( 'none' !== $performer_type && ! empty( $performer_name ) ) {
$schema['performer'] = array(
'@type' => $performer_type,
'name' => $performer_name,
);
}
// Get the offer items.
$offer_names = $this->get_value( 'offer_name' );
$offer_prices = $this->get_value( 'offer_price' );
$offer_currencies = $this->get_value( 'offer_currency' );
$offer_valid_from = $this->get_value( 'offer_valid_from' );
$offer_urls = $this->get_value( 'offer_url' );
$offer_availability = $this->get_value( 'offer_availability' );
// If we have offer names, add them to the schema.
if ( ! empty( $offer_names ) ) {
// Convert to arrays if single values.
if ( ! is_array( $offer_names ) ) {
$offer_names = array( $offer_names );
$offer_prices = array( $offer_prices );
$offer_currencies = array( $offer_currencies );
$offer_valid_from = array( $offer_valid_from );
$offer_urls = array( $offer_urls );
$offer_availability = array( $offer_availability );
}
$schema['offers'] = array();
// Add each offer to the schema.
foreach ( $offer_names as $index => $offer_name ) {
if ( ! empty( $offer_name ) ) {
$offer = array(
'@type' => 'Offer',
'name' => $offer_name,
);
if ( ! empty( $offer_prices[ $index ] ) ) {
$offer['price'] = $offer_prices[ $index ];
$offer['priceCurrency'] = $offer_currencies[ $index ] ?? 'USD';
}
if ( ! empty( $offer_valid_from[ $index ] ) ) {
$offer['validFrom'] = $offer_valid_from[ $index ];
}
if ( ! empty( $offer_urls[ $index ] ) ) {
$offer['url'] = $offer_urls[ $index ];
}
if ( ! empty( $offer_availability[ $index ] ) ) {
$offer['availability'] = $offer_availability[ $index ];
}
$schema['offers'][] = $offer;
}
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,231 @@
<?php
/**
* Generate a snippet for Fact Check schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Fact_Check class.
*/
class WPCode_Generator_Schema_Fact_Check extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-fact-check';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Fact Check Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for fact-checking content to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Fact Check schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'fact_check' => array(
'label' => __( 'Fact Check Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Fact Check information.
array(
array(
'type' => 'text',
'label' => __( 'Claim Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the claim being fact-checked.', 'insert-headers-and-footers' ),
'id' => 'claim_title',
'default' => '',
'placeholder' => __( 'Enter the claim title...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Claim Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the claim being fact-checked.', 'insert-headers-and-footers' ),
'id' => 'claim_description',
'default' => '',
'placeholder' => __( 'Describe the claim in detail...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Fact Check URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the fact check page.', 'insert-headers-and-footers' ),
'id' => 'fact_check_url',
'default' => '',
'placeholder' => 'https://example.com/fact-check',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'select',
'label' => __( 'Fact Check Rating', 'insert-headers-and-footers' ),
'description' => __( 'The rating of the fact check.', 'insert-headers-and-footers' ),
'id' => 'fact_check_rating',
'default' => 'true',
'options' => array(
'true' => __( 'True', 'insert-headers-and-footers' ),
'false' => __( 'False', 'insert-headers-and-footers' ),
'partially_true' => __( 'Partially True', 'insert-headers-and-footers' ),
'partially_false' => __( 'Partially False', 'insert-headers-and-footers' ),
'mostly_true' => __( 'Mostly True', 'insert-headers-and-footers' ),
'mostly_false' => __( 'Mostly False', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'text',
'label' => __( 'Author Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the fact checker.', 'insert-headers-and-footers' ),
'id' => 'author_name',
'default' => '',
'placeholder' => __( 'Enter the fact checker name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Author URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the fact checker.', 'insert-headers-and-footers' ),
'id' => 'author_url',
'default' => '',
'placeholder' => 'https://example.com/author',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
array(
array(
'type' => 'date',
'label' => __( 'Date Published', 'insert-headers-and-footers' ),
'description' => __( 'The date when the fact check was published.', 'insert-headers-and-footers' ),
'id' => 'date_published',
'default' => '',
),
array(
'type' => 'date',
'label' => __( 'Date Modified', 'insert-headers-and-footers' ),
'description' => __( 'The date when the fact check was last modified.', 'insert-headers-and-footers' ),
'id' => 'date_modified',
'default' => '',
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'ClaimReview',
'claimReviewed' => array(
'@type' => 'Claim',
),
);
// Add claim title.
$claim_title = $this->get_value( 'claim_title' );
if ( ! empty( $claim_title ) ) {
$schema['claimReviewed']['name'] = $claim_title;
}
// Add claim description.
$claim_description = $this->get_value( 'claim_description' );
if ( ! empty( $claim_description ) ) {
$schema['claimReviewed']['description'] = $claim_description;
}
// Add URL.
$url = $this->get_value( 'fact_check_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add fact check rating.
$rating = $this->get_value( 'fact_check_rating' );
if ( ! empty( $rating ) ) {
$schema['reviewRating'] = array(
'@type' => 'Rating',
'ratingValue' => $rating,
);
}
// Add author information.
$author_name = $this->get_value( 'author_name' );
$author_url = $this->get_value( 'author_url' );
if ( ! empty( $author_name ) ) {
$schema['author'] = array(
'@type' => 'Person',
'name' => $author_name,
);
if ( ! empty( $author_url ) ) {
$schema['author']['url'] = $author_url;
}
}
// Add dates.
$date_published = $this->get_value( 'date_published' );
if ( ! empty( $date_published ) ) {
$schema['datePublished'] = $date_published;
}
$date_modified = $this->get_value( 'date_modified' );
if ( ! empty( $date_modified ) ) {
$schema['dateModified'] = $date_modified;
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,154 @@
<?php
/**
* Generate a snippet for FAQ schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_FAQ class.
*/
class WPCode_Generator_Schema_FAQ extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-faq';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'FAQ Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for Frequently Asked Questions to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates FAQ schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'faq' => array(
'label' => __( 'FAQ Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - FAQ items.
array(
array(
'type' => 'text',
'label' => __( 'Question', 'insert-headers-and-footers' ),
'description' => __( 'The question text.', 'insert-headers-and-footers' ),
'id' => 'question',
'name' => 'question[]',
'repeater' => 'faq_items',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'What is your question?', 'insert-headers-and-footers' ),
),
array(
'type' => 'textarea',
'label' => __( 'Answer', 'insert-headers-and-footers' ),
'description' => __( 'The answer to the question.', 'insert-headers-and-footers' ),
'id' => 'answer',
'name' => 'answer[]',
'repeater' => 'faq_items',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Enter your answer here...', 'insert-headers-and-footers' ),
),
),
// Column 2 - Repeater button.
array(
array(
'type' => 'repeater_button',
'id' => 'faq_items',
'button_text' => __( 'Add Another FAQ Item', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => array(),
);
// Get the FAQ items.
$questions = $this->get_value( 'question' );
$answers = $this->get_value( 'answer' );
// If we have questions and answers, add them to the schema.
if ( ! empty( $questions ) && ! empty( $answers ) ) {
// Convert to arrays if single values.
if ( ! is_array( $questions ) ) {
$questions = array( $questions );
}
if ( ! is_array( $answers ) ) {
$answers = array( $answers );
}
// Add each question/answer pair to the schema.
foreach ( $questions as $index => $question ) {
if ( ! empty( $question ) && ! empty( $answers[ $index ] ) ) {
$schema['mainEntity'][] = array(
'@type' => 'Question',
'name' => $question,
'acceptedAnswer' => array(
'@type' => 'Answer',
'text' => $answers[ $index ],
),
);
}
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,239 @@
<?php
/**
* Generate a snippet for How To schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_How_To class.
*/
class WPCode_Generator_Schema_How_To extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-how-to';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'How-To Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for step-by-step instructions and tutorials.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates How-To schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the how-to guide.', 'insert-headers-and-footers' ),
'id' => 'title',
'default' => '',
'predefined_tags' => array( 'title' ),
'smart_tags' => true,
),
array(
'type' => 'textarea',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the how-to guide.', 'insert-headers-and-footers' ),
'id' => 'description',
'default' => '',
'predefined_tags' => array( 'excerpt' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Total Time', 'insert-headers-and-footers' ),
'description' => __( 'The total time required to complete the task (e.g., "PT30M" for 30 minutes).', 'insert-headers-and-footers' ),
'id' => 'total_time',
'smart_tags' => true,
'default' => '',
),
),
),
),
'steps' => array(
'label' => __( 'Steps', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Step fields.
array(
array(
'type' => 'text',
'label' => __( 'Step Name', 'insert-headers-and-footers' ),
'description' => __( 'The name/title of this step.', 'insert-headers-and-footers' ),
'id' => 'step_name',
'name' => 'step_name[]',
'repeater' => 'steps',
'default' => '',
'predefined_tags' => array( 'title' ),
'smart_tags' => true,
),
array(
'type' => 'textarea',
'label' => __( 'Step Text', 'insert-headers-and-footers' ),
'description' => __( 'The detailed instructions for this step.', 'insert-headers-and-footers' ),
'id' => 'step_text',
'name' => 'step_text[]',
'repeater' => 'steps',
'default' => '',
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Step URL', 'insert-headers-and-footers' ),
'description' => __( 'Optional URL for this step (e.g., to a detailed tutorial).', 'insert-headers-and-footers' ),
'id' => 'step_url',
'name' => 'step_url[]',
'repeater' => 'steps',
'default' => '',
'predefined_tags' => array( 'permalink' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Step Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of an image for this step.', 'insert-headers-and-footers' ),
'id' => 'step_image',
'name' => 'step_image[]',
'repeater' => 'steps',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'default' => '',
'is_image_url' => true,
),
),
// Column 2 - Repeater button.
array(
array(
'type' => 'repeater_button',
'id' => 'steps',
'button_text' => __( 'Add Another Step', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'HowTo',
'name' => $this->get_value( 'title' ),
'description' => $this->get_value( 'description' ),
);
// Add total time if provided.
$total_time = $this->get_value( 'total_time' );
if ( ! empty( $total_time ) ) {
$schema['totalTime'] = $total_time;
}
// Get the steps.
$step_names = $this->get_value( 'step_name' );
$step_texts = $this->get_value( 'step_text' );
$step_urls = $this->get_value( 'step_url' );
$step_images = $this->get_value( 'step_image' );
// If we have steps, add them to the schema.
if ( ! empty( $step_names ) && ! empty( $step_texts ) ) {
// Convert to arrays if single values.
if ( ! is_array( $step_names ) ) {
$step_names = array( $step_names );
}
if ( ! is_array( $step_texts ) ) {
$step_texts = array( $step_texts );
}
if ( ! is_array( $step_urls ) ) {
$step_urls = array( $step_urls );
}
if ( ! is_array( $step_images ) ) {
$step_images = array( $step_images );
}
$schema['step'] = array();
// Add each step to the schema.
foreach ( $step_names as $index => $step_name ) {
if ( ! empty( $step_name ) && isset( $step_texts[ $index ] ) && ! empty( $step_texts[ $index ] ) ) {
$step = array(
'@type' => 'HowToStep',
'name' => $step_name,
'text' => $step_texts[ $index ],
);
// Add URL if provided.
if ( ! empty( $step_urls[ $index ] ) ) {
$step['url'] = $step_urls[ $index ];
}
// Add image if provided.
if ( ! empty( $step_images[ $index ] ) ) {
$step['image'] = array(
'@type' => 'ImageObject',
'url' => $step_images[ $index ],
);
}
$schema['step'][] = $step;
}
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,395 @@
<?php
/**
* Generate a snippet for Job Posting schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Job_Posting class.
*/
class WPCode_Generator_Schema_Job_Posting extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-job-posting';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Job Posting Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for job listings and employment opportunities.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Job Posting schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'job' => array(
'label' => __( 'Job Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic job information.
array(
array(
'type' => 'text',
'label' => __( 'Job Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the job posting.', 'insert-headers-and-footers' ),
'id' => 'job_title',
'default' => '',
'placeholder' => __( 'Software Engineer', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Job Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the job.', 'insert-headers-and-footers' ),
'id' => 'job_description',
'default' => '',
'placeholder' => __( 'Description of the job...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Industry', 'insert-headers-and-footers' ),
'description' => __( 'The industry of the job (e.g., IT, Healthcare, Education).', 'insert-headers-and-footers' ),
'id' => 'job_industry',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Information Technology', 'insert-headers-and-footers' ),
),
array(
'type' => 'select',
'label' => __( 'Employment Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of employment.', 'insert-headers-and-footers' ),
'id' => 'job_employment_type',
'default' => 'FULL_TIME',
'options' => array(
'FULL_TIME' => __( 'Full Time', 'insert-headers-and-footers' ),
'PART_TIME' => __( 'Part Time', 'insert-headers-and-footers' ),
'CONTRACT' => __( 'Contract', 'insert-headers-and-footers' ),
'TEMPORARY' => __( 'Temporary', 'insert-headers-and-footers' ),
'INTERN' => __( 'Intern', 'insert-headers-and-footers' ),
'VOLUNTEER' => __( 'Volunteer', 'insert-headers-and-footers' ),
'PER_DIEM' => __( 'Per Diem', 'insert-headers-and-footers' ),
'OTHER' => __( 'Other', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Job Location Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of work location.', 'insert-headers-and-footers' ),
'id' => 'job_location_type',
'default' => 'TELECOMMUTE',
'options' => array(
'TELECOMMUTE' => __( 'Remote', 'insert-headers-and-footers' ),
'ONSITE' => __( 'On-site', 'insert-headers-and-footers' ),
'HYBRID' => __( 'Hybrid', 'insert-headers-and-footers' ),
),
),
),
// Column 2 - Dates and requirements.
array(
array(
'type' => 'text',
'label' => __( 'Work Hours', 'insert-headers-and-footers' ),
'description' => __( 'The number of hours per week.', 'insert-headers-and-footers' ),
'id' => 'job_work_hours',
'default' => '',
'placeholder' => '40',
'smart_tags' => true,
),
array(
'type' => 'date',
'label' => __( 'Date Posted', 'insert-headers-and-footers' ),
'description' => __( 'The date when the job was posted.', 'insert-headers-and-footers' ),
'id' => 'job_date_posted',
'default' => '',
'placeholder' => '2025-01-01',
),
array(
'type' => 'date',
'label' => __( 'Valid Through', 'insert-headers-and-footers' ),
'description' => __( 'The date when the job posting expires.', 'insert-headers-and-footers' ),
'id' => 'job_valid_through',
'default' => '',
'placeholder' => '2025-12-31',
),
),
),
),
'organization' => array(
'label' => __( 'Organization', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Organization details.
array(
array(
'type' => 'text',
'label' => __( 'Organization Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the hiring organization.', 'insert-headers-and-footers' ),
'id' => 'org_name',
'default' => '',
'placeholder' => __( 'Company Name', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array(),
),
array(
'type' => 'text',
'label' => __( 'Organization Website', 'insert-headers-and-footers' ),
'description' => __( 'The website URL of the organization.', 'insert-headers-and-footers' ),
'id' => 'org_website',
'default' => '',
'smart_tags' => true,
'placeholder' => 'https://example.com',
),
array(
'type' => 'text',
'label' => __( 'Organization Logo', 'insert-headers-and-footers' ),
'description' => __( 'URL of the organization logo.', 'insert-headers-and-footers' ),
'id' => 'org_logo',
'default' => '',
'placeholder' => 'https://example.com/logo.png',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
),
),
),
'location' => array(
'label' => __( 'Location', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Location details.
array(
array(
'type' => 'text',
'label' => __( 'Street Address', 'insert-headers-and-footers' ),
'description' => __( 'The street address of the job location.', 'insert-headers-and-footers' ),
'id' => 'location_street',
'default' => '',
'placeholder' => __( '123 Main St', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'City', 'insert-headers-and-footers' ),
'description' => __( 'The city of the job location.', 'insert-headers-and-footers' ),
'id' => 'location_city',
'default' => '',
'placeholder' => __( 'New York', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Postal Code', 'insert-headers-and-footers' ),
'description' => __( 'The postal code of the job location.', 'insert-headers-and-footers' ),
'id' => 'location_postal',
'default' => '',
'placeholder' => __( '10001', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Country Code', 'insert-headers-and-footers' ),
'description' => __( 'The country code of the job location (e.g., US, UK, CA).', 'insert-headers-and-footers' ),
'id' => 'location_country',
'default' => '',
'placeholder' => __( 'US', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
),
),
),
'salary' => array(
'label' => __( 'Salary', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Salary details.
array(
array(
'type' => 'text',
'label' => __( 'Base Salary', 'insert-headers-and-footers' ),
'description' => __( 'The base salary amount.', 'insert-headers-and-footers' ),
'id' => 'salary_base',
'default' => '',
'placeholder' => '50000',
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Currency', 'insert-headers-and-footers' ),
'description' => __( 'The currency code (e.g., USD, EUR, GBP).', 'insert-headers-and-footers' ),
'id' => 'salary_currency',
'default' => 'USD',
'placeholder' => __( 'USD', 'insert-headers-and-footers' ),
'smart_tags' => true,
),
array(
'type' => 'select',
'label' => __( 'Salary Unit', 'insert-headers-and-footers' ),
'description' => __( 'The unit of time for the salary.', 'insert-headers-and-footers' ),
'id' => 'salary_unit',
'default' => 'YEAR',
'options' => array(
'HOUR' => __( 'Per Hour', 'insert-headers-and-footers' ),
'DAY' => __( 'Per Day', 'insert-headers-and-footers' ),
'WEEK' => __( 'Per Week', 'insert-headers-and-footers' ),
'MONTH' => __( 'Per Month', 'insert-headers-and-footers' ),
'YEAR' => __( 'Per Year', 'insert-headers-and-footers' ),
),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'JobPosting',
'title' => $this->get_value( 'job_title' ),
'description' => $this->get_value( 'job_description' ),
);
// Add industry if set.
$industry = $this->get_value( 'job_industry' );
if ( ! empty( $industry ) ) {
$schema['industry'] = $industry;
}
// Add employment type.
$schema['employmentType'] = $this->get_value( 'job_employment_type' );
// Add work hours if set.
$work_hours = $this->get_value( 'job_work_hours' );
if ( ! empty( $work_hours ) ) {
$schema['workHours'] = $work_hours;
}
// Add dates.
$date_posted = $this->get_value( 'job_date_posted' );
if ( ! empty( $date_posted ) ) {
$schema['datePosted'] = $date_posted;
}
$valid_through = $this->get_value( 'job_valid_through' );
if ( ! empty( $valid_through ) ) {
$schema['validThrough'] = $valid_through;
}
// Add job location type.
$schema['jobLocationType'] = $this->get_value( 'job_location_type' );
// Add organization details.
$org_name = $this->get_value( 'org_name' );
if ( ! empty( $org_name ) ) {
$schema['hiringOrganization'] = array(
'@type' => 'Organization',
'name' => $org_name,
);
$org_website = $this->get_value( 'org_website' );
if ( ! empty( $org_website ) ) {
$schema['hiringOrganization']['sameAs'] = $org_website;
}
$org_logo = $this->get_value( 'org_logo' );
if ( ! empty( $org_logo ) ) {
$schema['hiringOrganization']['logo'] = $org_logo;
}
}
// Add location details.
$street = $this->get_value( 'location_street' );
if ( ! empty( $street ) ) {
$schema['jobLocation'] = array(
'@type' => 'Place',
'address' => array(
'@type' => 'PostalAddress',
'streetAddress' => $street,
),
);
$city = $this->get_value( 'location_city' );
if ( ! empty( $city ) ) {
$schema['jobLocation']['address']['addressLocality'] = $city;
}
$postal = $this->get_value( 'location_postal' );
if ( ! empty( $postal ) ) {
$schema['jobLocation']['address']['postalCode'] = $postal;
}
$country = $this->get_value( 'location_country' );
if ( ! empty( $country ) ) {
$schema['jobLocation']['address']['addressCountry'] = $country;
}
}
// Add salary details.
$base_salary = $this->get_value( 'salary_base' );
if ( ! empty( $base_salary ) ) {
$schema['baseSalary'] = array(
'@type' => 'MonetaryAmount',
'currency' => $this->get_value( 'salary_currency' ),
'value' => array(
'@type' => 'QuantitativeValue',
'value' => $base_salary,
'unitText' => $this->get_value( 'salary_unit' ),
),
);
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,259 @@
<?php
/**
* Generate a snippet for Movie schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Movie class.
*/
class WPCode_Generator_Schema_Movie extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-movie';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Movie Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for movies to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Movie schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'movie' => array(
'label' => __( 'Movie Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Movie information.
array(
array(
'type' => 'text',
'label' => __( 'Movie Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the movie.', 'insert-headers-and-footers' ),
'id' => 'movie_title',
'default' => '',
'placeholder' => __( 'Enter the movie title...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the movie.', 'insert-headers-and-footers' ),
'id' => 'description',
'default' => '',
'placeholder' => __( 'Describe the movie...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Movie URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the movie page.', 'insert-headers-and-footers' ),
'id' => 'movie_url',
'default' => '',
'placeholder' => 'https://example.com/movie',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Thumbnail URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the movie poster or image.', 'insert-headers-and-footers' ),
'id' => 'image_url',
'default' => '',
'placeholder' => 'https://example.com/movie-poster.jpg',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
array(
'type' => 'date',
'label' => __( 'Release Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the movie was released.', 'insert-headers-and-footers' ),
'id' => 'release_date',
'default' => '',
'placeholder' => '2024-01-01',
),
array(
'type' => 'text',
'label' => __( 'Duration', 'insert-headers-and-footers' ),
'description' => __( 'The duration of the movie in minutes.', 'insert-headers-and-footers' ),
'id' => 'duration',
'smart_tags' => true,
'default' => '',
'placeholder' => '120',
),
),
array(
array(
'type' => 'text',
'label' => __( 'Director', 'insert-headers-and-footers' ),
'description' => __( 'The name of the movie director.', 'insert-headers-and-footers' ),
'id' => 'director',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter director name...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Genre', 'insert-headers-and-footers' ),
'description' => __( 'The genre of the movie (e.g., Action, Comedy, Drama).', 'insert-headers-and-footers' ),
'id' => 'genre',
'default' => '',
'smart_tags' => true,
'placeholder' => 'Action, Adventure',
),
array(
'type' => 'text',
'label' => __( 'Rating', 'insert-headers-and-footers' ),
'description' => __( 'The rating of the movie (e.g., PG-13, R).', 'insert-headers-and-footers' ),
'id' => 'rating',
'default' => '',
'placeholder' => 'PG-13',
'smart_tags' => true,
),
array(
'type' => 'text',
'label' => __( 'Production Company', 'insert-headers-and-footers' ),
'description' => __( 'The name of the production company.', 'insert-headers-and-footers' ),
'id' => 'production_company',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter production company name...', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Movie',
);
// Add basic information.
$movie_title = $this->get_value( 'movie_title' );
if ( ! empty( $movie_title ) ) {
$schema['name'] = $movie_title;
}
$description = $this->get_value( 'description' );
if ( ! empty( $description ) ) {
$schema['description'] = $description;
}
$url = $this->get_value( 'movie_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add image.
$image_url = $this->get_value( 'image_url' );
if ( ! empty( $image_url ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image_url,
);
}
// Add release date.
$release_date = $this->get_value( 'release_date' );
if ( ! empty( $release_date ) ) {
$schema['datePublished'] = $release_date;
}
// Add duration.
$duration = $this->get_value( 'duration' );
if ( ! empty( $duration ) ) {
$schema['duration'] = 'PT' . intval( $duration ) . 'M';
}
// Add director.
$director = $this->get_value( 'director' );
if ( ! empty( $director ) ) {
$schema['director'] = array(
'@type' => 'Person',
'name' => $director,
);
}
// Add genre.
$genre = $this->get_value( 'genre' );
if ( ! empty( $genre ) ) {
$schema['genre'] = array_map( 'trim', explode( ',', $genre ) );
}
// Add rating.
$rating = $this->get_value( 'rating' );
if ( ! empty( $rating ) ) {
$schema['contentRating'] = $rating;
}
// Add production company.
$production_company = $this->get_value( 'production_company' );
if ( ! empty( $production_company ) ) {
$schema['productionCompany'] = array(
'@type' => 'Organization',
'name' => $production_company,
);
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,262 @@
<?php
/**
* Generate a snippet for Music schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Music class.
*/
class WPCode_Generator_Schema_Music extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-music';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Music Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for music content to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Music schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'music' => array(
'label' => __( 'Music Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Music information.
array(
array(
'type' => 'text',
'label' => __( 'Music Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the music track or album.', 'insert-headers-and-footers' ),
'id' => 'music_title',
'default' => '',
'placeholder' => __( 'Enter the music title...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the music.', 'insert-headers-and-footers' ),
'id' => 'description',
'default' => '',
'placeholder' => __( 'Describe the music...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Music URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the music page.', 'insert-headers-and-footers' ),
'id' => 'music_url',
'default' => '',
'placeholder' => 'https://example.com/music',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Image Cover URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the music cover art or image.', 'insert-headers-and-footers' ),
'id' => 'image_url',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/album-cover.jpg',
'is_image_url' => true,
),
array(
'type' => 'date',
'label' => __( 'Release Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the music was released.', 'insert-headers-and-footers' ),
'id' => 'release_date',
'default' => '',
'placeholder' => '2024-01-01',
),
array(
'type' => 'text',
'label' => __( 'Duration', 'insert-headers-and-footers' ),
'description' => __( 'The duration of the music in seconds.', 'insert-headers-and-footers' ),
'id' => 'duration',
'default' => '',
'smart_tags' => true,
'placeholder' => '180',
),
array(
'type' => 'text',
'label' => __( 'Artist', 'insert-headers-and-footers' ),
'description' => __( 'The name of the music artist.', 'insert-headers-and-footers' ),
'id' => 'artist',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Enter artist name...', 'insert-headers-and-footers' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Genre', 'insert-headers-and-footers' ),
'description' => __( 'The genre of the music (e.g., Rock, Pop, Jazz).', 'insert-headers-and-footers' ),
'id' => 'genre',
'default' => '',
'smart_tags' => true,
'placeholder' => 'Rock, Pop',
),
array(
'type' => 'text',
'label' => __( 'Album', 'insert-headers-and-footers' ),
'description' => __( 'The name of the album (if applicable).', 'insert-headers-and-footers' ),
'id' => 'album',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter album name...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Record Label', 'insert-headers-and-footers' ),
'description' => __( 'The name of the record label.', 'insert-headers-and-footers' ),
'id' => 'record_label',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter record label name...', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'MusicRecording',
);
// Add basic information.
$music_title = $this->get_value( 'music_title' );
if ( ! empty( $music_title ) ) {
$schema['name'] = $music_title;
}
$description = $this->get_value( 'description' );
if ( ! empty( $description ) ) {
$schema['description'] = $description;
}
$url = $this->get_value( 'music_url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add image.
$image_url = $this->get_value( 'image_url' );
if ( ! empty( $image_url ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image_url,
);
}
// Add release date.
$release_date = $this->get_value( 'release_date' );
if ( ! empty( $release_date ) ) {
$schema['datePublished'] = $release_date;
}
// Add duration.
$duration = $this->get_value( 'duration' );
if ( ! empty( $duration ) ) {
$schema['duration'] = 'PT' . intval( $duration ) . 'S';
}
// Add artist.
$artist = $this->get_value( 'artist' );
if ( ! empty( $artist ) ) {
$schema['byArtist'] = array(
'@type' => 'MusicGroup',
'name' => $artist,
);
}
// Add genre.
$genre = $this->get_value( 'genre' );
if ( ! empty( $genre ) ) {
$schema['genre'] = array_map( 'trim', explode( ',', $genre ) );
}
// Add album.
$album = $this->get_value( 'album' );
if ( ! empty( $album ) ) {
$schema['inAlbum'] = array(
'@type' => 'MusicAlbum',
'name' => $album,
);
}
// Add record label.
$record_label = $this->get_value( 'record_label' );
if ( ! empty( $record_label ) ) {
$schema['recordLabel'] = array(
'@type' => 'Organization',
'name' => $record_label,
);
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,242 @@
<?php
/**
* Generate a snippet for Person schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Person class.
*/
class WPCode_Generator_Schema_Person extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-person';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Person Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for people to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Person schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'person' => array(
'label' => __( 'Person Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Person information.
array(
array(
'type' => 'text',
'label' => __( 'Name', 'insert-headers-and-footers' ),
'description' => __( 'The full name of the person.', 'insert-headers-and-footers' ),
'id' => 'name',
'default' => '',
'placeholder' => __( 'Enter the person\'s name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the person.', 'insert-headers-and-footers' ),
'id' => 'description',
'default' => '',
'placeholder' => __( 'Describe the person...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the person\'s page.', 'insert-headers-and-footers' ),
'id' => 'url',
'default' => '',
'placeholder' => 'https://example.com/person',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Image URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the person\'s photo.', 'insert-headers-and-footers' ),
'id' => 'image_url',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/photo.jpg',
'is_image_url' => true,
),
array(
'type' => 'text',
'label' => __( 'Job Title', 'insert-headers-and-footers' ),
'description' => __( 'The person\'s job title or role.', 'insert-headers-and-footers' ),
'id' => 'job_title',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter job title...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Works For', 'insert-headers-and-footers' ),
'description' => __( 'The organization the person works for.', 'insert-headers-and-footers' ),
'id' => 'works_for',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter organization name...', 'insert-headers-and-footers' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Email', 'insert-headers-and-footers' ),
'description' => __( 'The person\'s email address.', 'insert-headers-and-footers' ),
'id' => 'email',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'email' ),
'placeholder' => 'person@example.com',
),
array(
'type' => 'text',
'label' => __( 'Telephone', 'insert-headers-and-footers' ),
'description' => __( 'The person\'s telephone number.', 'insert-headers-and-footers' ),
'id' => 'telephone',
'default' => '',
'smart_tags' => true,
'placeholder' => '+1-234-567-8900',
),
array(
'type' => 'textarea',
'label' => __( 'Same As', 'insert-headers-and-footers' ),
'description' => __( 'URLs of the person\'s social media profiles (comma-separated).', 'insert-headers-and-footers' ),
'id' => 'same_as',
'default' => '',
'smart_tags' => true,
'placeholder' => 'https://twitter.com/username, https://linkedin.com/in/username',
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Person',
);
// Add basic information.
$name = $this->get_value( 'name' );
if ( ! empty( $name ) ) {
$schema['name'] = $name;
}
$description = $this->get_value( 'description' );
if ( ! empty( $description ) ) {
$schema['description'] = $description;
}
$url = $this->get_value( 'url' );
if ( ! empty( $url ) ) {
$schema['url'] = $url;
}
// Add image.
$image_url = $this->get_value( 'image_url' );
if ( ! empty( $image_url ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image_url,
);
}
// Add job title.
$job_title = $this->get_value( 'job_title' );
if ( ! empty( $job_title ) ) {
$schema['jobTitle'] = $job_title;
}
// Add works for.
$works_for = $this->get_value( 'works_for' );
if ( ! empty( $works_for ) ) {
$schema['worksFor'] = array(
'@type' => 'Organization',
'name' => $works_for,
);
}
// Add contact information.
$email = $this->get_value( 'email' );
if ( ! empty( $email ) ) {
$schema['email'] = $email;
}
$telephone = $this->get_value( 'telephone' );
if ( ! empty( $telephone ) ) {
$schema['telephone'] = $telephone;
}
// Add social media profiles.
$same_as = $this->get_value( 'same_as' );
if ( ! empty( $same_as ) ) {
$schema['sameAs'] = array_map( 'trim', explode( ',', $same_as ) );
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,288 @@
<?php
/**
* Generate a snippet for Product Review schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Product_Review class.
*/
class WPCode_Generator_Schema_Product_Review extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-product-review';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Product Review Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for product reviews to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Product Review schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'review' => array(
'label' => __( 'Review Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Review information.
array(
array(
'type' => 'text',
'label' => __( 'Review Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the review.', 'insert-headers-and-footers' ),
'id' => 'review_title',
'default' => '',
'placeholder' => __( 'Enter the review title...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Review Description', 'insert-headers-and-footers' ),
'description' => __( 'The detailed review content.', 'insert-headers-and-footers' ),
'id' => 'review_description',
'default' => '',
'placeholder' => __( 'Write your review...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'custom_field' ),
),
array(
'type' => 'text',
'label' => __( 'Review URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the review page.', 'insert-headers-and-footers' ),
'id' => 'review_url',
'default' => '',
'placeholder' => 'https://example.com/review',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'date',
'label' => __( 'Review Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the review was published.', 'insert-headers-and-footers' ),
'id' => 'review_date',
'default' => '',
'placeholder' => '2024-01-01',
),
array(
'type' => 'text',
'label' => __( 'Review Rating', 'insert-headers-and-footers' ),
'description' => __( 'The rating given in the review (1-5).', 'insert-headers-and-footers' ),
'id' => 'review_rating',
'smart_tags' => true,
'default' => '',
'placeholder' => '4.5',
),
array(
'type' => 'text',
'label' => __( 'Reviewer Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the reviewer.', 'insert-headers-and-footers' ),
'id' => 'reviewer_name',
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
'default' => '',
'placeholder' => __( 'Enter reviewer name...', 'insert-headers-and-footers' ),
),
),
),
),
'product' => array(
'label' => __( 'Product Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Product information.
array(
array(
'type' => 'text',
'label' => __( 'Product Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the product being reviewed.', 'insert-headers-and-footers' ),
'id' => 'product_name',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
'placeholder' => __( 'Enter product name...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Product URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the product page.', 'insert-headers-and-footers' ),
'id' => 'product_url',
'default' => '',
'placeholder' => 'https://example.com/product',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
array(
'type' => 'text',
'label' => __( 'Product Image', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the product image.', 'insert-headers-and-footers' ),
'id' => 'product_image',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/product-image.jpg',
'is_image_url' => true,
),
),
array(
array(
'type' => 'text',
'label' => __( 'Product Brand', 'insert-headers-and-footers' ),
'description' => __( 'The brand or manufacturer of the product.', 'insert-headers-and-footers' ),
'id' => 'product_brand',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Enter brand name...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Product SKU', 'insert-headers-and-footers' ),
'description' => __( 'The SKU or model number of the product.', 'insert-headers-and-footers' ),
'id' => 'product_sku',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Enter SKU...', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Review',
);
// Add review information.
$review_title = $this->get_value( 'review_title' );
if ( ! empty( $review_title ) ) {
$schema['name'] = $review_title;
}
$review_description = $this->get_value( 'review_description' );
if ( ! empty( $review_description ) ) {
$schema['reviewBody'] = $review_description;
}
$review_url = $this->get_value( 'review_url' );
if ( ! empty( $review_url ) ) {
$schema['url'] = $review_url;
}
$review_date = $this->get_value( 'review_date' );
if ( ! empty( $review_date ) ) {
$schema['datePublished'] = $review_date;
}
// Add review rating.
$review_rating = $this->get_value( 'review_rating' );
if ( ! empty( $review_rating ) ) {
$schema['reviewRating'] = array(
'@type' => 'Rating',
'ratingValue' => floatval( $review_rating ),
'bestRating' => '5',
'worstRating' => '1',
);
}
// Add reviewer information.
$reviewer_name = $this->get_value( 'reviewer_name' );
if ( ! empty( $reviewer_name ) ) {
$schema['author'] = array(
'@type' => 'Person',
'name' => $reviewer_name,
);
}
// Add product information.
$product_name = $this->get_value( 'product_name' );
if ( ! empty( $product_name ) ) {
$schema['itemReviewed'] = array(
'@type' => 'Product',
'name' => $product_name,
);
$product_url = $this->get_value( 'product_url' );
if ( ! empty( $product_url ) ) {
$schema['itemReviewed']['url'] = $product_url;
}
$product_image = $this->get_value( 'product_image' );
if ( ! empty( $product_image ) ) {
$schema['itemReviewed']['image'] = array(
'@type' => 'ImageObject',
'url' => $product_image,
);
}
$product_brand = $this->get_value( 'product_brand' );
if ( ! empty( $product_brand ) ) {
$schema['itemReviewed']['brand'] = array(
'@type' => 'Brand',
'name' => $product_brand,
);
}
$product_sku = $this->get_value( 'product_sku' );
if ( ! empty( $product_sku ) ) {
$schema['itemReviewed']['sku'] = $product_sku;
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,341 @@
<?php
/**
* Generate a snippet for Product schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Product class.
*/
class WPCode_Generator_Schema_Product extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-product';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Product Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for products to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Product schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'product' => array(
'label' => __( 'Product Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Product information.
array(
array(
'type' => 'text',
'label' => __( 'Product Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the product.', 'insert-headers-and-footers' ),
'id' => 'product_name',
'default' => '',
'placeholder' => __( 'Enter product name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Product Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the product.', 'insert-headers-and-footers' ),
'id' => 'product_description',
'default' => '',
'placeholder' => __( 'Describe the product...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Product URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the product page.', 'insert-headers-and-footers' ),
'id' => 'product_url',
'default' => '',
'placeholder' => 'https://example.com/product',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Product Image', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the product image.', 'insert-headers-and-footers' ),
'id' => 'product_image',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/product-image.jpg',
'is_image_url' => true,
),
array(
'type' => 'text',
'label' => __( 'Product Brand', 'insert-headers-and-footers' ),
'description' => __( 'The brand or manufacturer of the product.', 'insert-headers-and-footers' ),
'id' => 'product_brand',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter brand name...', 'insert-headers-and-footers' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Product SKU', 'insert-headers-and-footers' ),
'description' => __( 'The SKU or model number of the product.', 'insert-headers-and-footers' ),
'id' => 'product_sku',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter SKU...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Product GTIN', 'insert-headers-and-footers' ),
'description' => __( 'The GTIN (UPC, EAN, ISBN) of the product.', 'insert-headers-and-footers' ),
'id' => 'product_gtin',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter GTIN...', 'insert-headers-and-footers' ),
),
),
),
),
'offer' => array(
'label' => __( 'Offer Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Offer information.
array(
array(
'type' => 'text',
'label' => __( 'Offer Name', 'insert-headers-and-footers' ),
'description' => __( 'A name to identify this offer (e.g., Regular Price, Sale Price, Bundle Offer).', 'insert-headers-and-footers' ),
'id' => 'offer_name',
'name' => 'offer_name[]',
'repeater' => 'offer_items',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Regular Price', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Price', 'insert-headers-and-footers' ),
'description' => __( 'The price of the product.', 'insert-headers-and-footers' ),
'id' => 'product_price',
'name' => 'product_price[]',
'repeater' => 'offer_items',
'default' => '',
'smart_tags' => true,
'placeholder' => '99.99',
),
array(
'type' => 'text',
'label' => __( 'Currency', 'insert-headers-and-footers' ),
'description' => __( 'The currency of the price (e.g., USD, EUR).', 'insert-headers-and-footers' ),
'id' => 'product_currency',
'name' => 'product_currency[]',
'repeater' => 'offer_items',
'default' => 'USD',
'smart_tags' => true,
'placeholder' => 'USD',
),
array(
'type' => 'select',
'label' => __( 'Availability', 'insert-headers-and-footers' ),
'description' => __( 'The availability status of the product.', 'insert-headers-and-footers' ),
'id' => 'product_availability',
'name' => 'product_availability[]',
'repeater' => 'offer_items',
'default' => 'InStock',
'options' => array(
'InStock' => __( 'In Stock', 'insert-headers-and-footers' ),
'OutOfStock' => __( 'Out of Stock', 'insert-headers-and-footers' ),
'PreOrder' => __( 'Pre-order', 'insert-headers-and-footers' ),
'Discontinued' => __( 'Discontinued', 'insert-headers-and-footers' ),
'LimitedAvailability' => __( 'Limited Availability', 'insert-headers-and-footers' ),
'OnlineOnly' => __( 'Online Only', 'insert-headers-and-footers' ),
'PreSale' => __( 'Pre-sale', 'insert-headers-and-footers' ),
'SoldOut' => __( 'Sold Out', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'date',
'label' => __( 'Price Valid Until', 'insert-headers-and-footers' ),
'description' => __( 'The date until which the price is valid.', 'insert-headers-and-footers' ),
'id' => 'price_valid_until',
'name' => 'price_valid_until[]',
'repeater' => 'offer_items',
'default' => '',
'placeholder' => '2024-12-31',
),
),
// Column 3 - Repeater button.
array(
array(
'type' => 'repeater_button',
'id' => 'offer_items',
'button_text' => __( 'Add Another Offer', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Product',
);
// Add basic product information.
$product_name = $this->get_value( 'product_name' );
if ( ! empty( $product_name ) ) {
$schema['name'] = $product_name;
}
$product_description = $this->get_value( 'product_description' );
if ( ! empty( $product_description ) ) {
$schema['description'] = $product_description;
}
$product_url = $this->get_value( 'product_url' );
if ( ! empty( $product_url ) ) {
$schema['url'] = $product_url;
}
// Add image.
$product_image = $this->get_value( 'product_image' );
if ( ! empty( $product_image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $product_image,
);
}
// Add brand.
$product_brand = $this->get_value( 'product_brand' );
if ( ! empty( $product_brand ) ) {
$schema['brand'] = array(
'@type' => 'Brand',
'name' => $product_brand,
);
}
// Add identifiers.
$product_sku = $this->get_value( 'product_sku' );
if ( ! empty( $product_sku ) ) {
$schema['sku'] = $product_sku;
}
$product_gtin = $this->get_value( 'product_gtin' );
if ( ! empty( $product_gtin ) ) {
$schema['gtin'] = $product_gtin;
}
$product_mpn = $this->get_value( 'product_mpn' );
if ( ! empty( $product_mpn ) ) {
$schema['mpn'] = $product_mpn;
}
// Get the offer items.
$offer_names = $this->get_value( 'offer_name' );
$product_prices = $this->get_value( 'product_price' );
$product_currencies = $this->get_value( 'product_currency' );
$product_availability = $this->get_value( 'product_availability' );
$price_valid_until = $this->get_value( 'price_valid_until' );
// If we have prices, add them to the schema.
if ( ! empty( $product_prices ) ) {
// Convert to arrays if single values.
if ( ! is_array( $product_prices ) ) {
$offer_names = array( $offer_names );
$product_prices = array( $product_prices );
$product_currencies = array( $product_currencies );
$product_availability = array( $product_availability );
$price_valid_until = array( $price_valid_until );
}
$schema['offers'] = array();
// Add each offer to the schema.
foreach ( $product_prices as $index => $price ) {
if ( ! empty( $price ) ) {
$offer = array(
'@type' => 'Offer',
'price' => floatval( $price ),
'priceCurrency' => $product_currencies[ $index ] ?? 'USD',
);
// Add offer name if provided
if ( ! empty( $offer_names[ $index ] ) ) {
$offer['name'] = $offer_names[ $index ];
}
if ( ! empty( $product_availability[ $index ] ) ) {
$offer['availability'] = 'https://schema.org/' . $product_availability[ $index ];
}
if ( ! empty( $price_valid_until[ $index ] ) ) {
$offer['priceValidUntil'] = $price_valid_until[ $index ];
}
$schema['offers'][] = $offer;
}
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,377 @@
<?php
/**
* Generate a snippet for Recipe schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Recipe class.
*/
class WPCode_Generator_Schema_Recipe extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-recipe';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Recipe Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for cooking recipes and food preparation instructions.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Recipe schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Recipe Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the recipe.', 'insert-headers-and-footers' ),
'id' => 'name',
'default' => '',
'predefined_tags' => array( 'title' ),
'smart_tags' => true,
'placeholder' => __( 'Classic Chocolate Chip Cookies', 'insert-headers-and-footers' ),
),
array(
'type' => 'textarea',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the recipe.', 'insert-headers-and-footers' ),
'id' => 'description',
'default' => '',
'predefined_tags' => array( 'excerpt' ),
'smart_tags' => true,
'placeholder' => __( 'A delicious and easy-to-make chocolate chip cookie recipe that will become your family favorite.', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Recipe Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of the recipe image.', 'insert-headers-and-footers' ),
'id' => 'image',
'placeholder' => 'https://example.com/recipe-image.jpg',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'is_image_url' => true,
),
array(
'type' => 'text',
'label' => __( 'Author Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the recipe author.', 'insert-headers-and-footers' ),
'id' => 'author_name',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
'placeholder' => __( 'John Smith', 'insert-headers-and-footers' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Recipe Category', 'insert-headers-and-footers' ),
'description' => __( 'The category of the recipe (salad, dessert).', 'insert-headers-and-footers' ),
'id' => 'recipe_category',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Dessert, Main Course, Appetizer', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Calories', 'insert-headers-and-footers' ),
'description' => __( 'The calorie content of the recipe.', 'insert-headers-and-footers' ),
'id' => 'calories',
'default' => '',
'smart_tags' => true,
'placeholder' => __( '350 calories', 'insert-headers-and-footers' ),
),
array(
'type' => 'textarea',
'label' => __( 'Ingredients', 'insert-headers-and-footers' ),
'description' => __( 'List all ingredients, separated by commas.', 'insert-headers-and-footers' ),
'id' => 'ingredients',
'default' => '',
'smart_tags' => true,
'placeholder' => __( '2 cups all-purpose flour, 1 cup butter, 2 eggs, 1 cup sugar', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Recipe Cuisine', 'insert-headers-and-footers' ),
'description' => __( 'The cuisine type (Italian, Mexican).', 'insert-headers-and-footers' ),
'id' => 'recipe_cuisine',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Italian, Mexican, Asian', 'insert-headers-and-footers' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Prep Time', 'insert-headers-and-footers' ),
'description' => __( 'Preparation time in ISO 8601 format (PT30M for 30 minutes).', 'insert-headers-and-footers' ),
'id' => 'prep_time',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'PT30M (30 minutes)', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Cook Time', 'insert-headers-and-footers' ),
'description' => __( 'Cooking time in ISO 8601 format (PT1H for 1 hour).', 'insert-headers-and-footers' ),
'id' => 'cook_time',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'PT1H (1 hour)', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Total Time', 'insert-headers-and-footers' ),
'description' => __( 'Total time in ISO 8601 format.', 'insert-headers-and-footers' ),
'id' => 'total_time',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'PT1H30M (1 hour 30 minutes)', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Recipe Yield', 'insert-headers-and-footers' ),
'description' => __( 'Number of servings or yield amount.', 'insert-headers-and-footers' ),
'id' => 'recipe_yield',
'smart_tags' => true,
'default' => '',
'placeholder' => __( '4 servings', 'insert-headers-and-footers' ),
),
),
),
),
'instructions' => array(
'label' => __( 'Instructions', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Instructions.
array(
array(
'type' => 'text',
'label' => __( 'Step Name', 'insert-headers-and-footers' ),
'description' => __( 'The name/title of this step.', 'insert-headers-and-footers' ),
'id' => 'instruction_name',
'name' => 'instruction_name[]',
'repeater' => 'instructions',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Preheat the oven', 'insert-headers-and-footers' ),
),
array(
'type' => 'textarea',
'label' => __( 'Step Text', 'insert-headers-and-footers' ),
'description' => __( 'The detailed instructions for this step.', 'insert-headers-and-footers' ),
'id' => 'instruction_text',
'name' => 'instruction_text[]',
'repeater' => 'instructions',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Preheat the oven to 350°F (175°C). Line a baking sheet with parchment paper.', 'insert-headers-and-footers' ),
'rows' => 4,
),
array(
'type' => 'text',
'label' => __( 'Step Image', 'insert-headers-and-footers' ),
'description' => __( 'URL of an image for this step.', 'insert-headers-and-footers' ),
'id' => 'instruction_image',
'name' => 'instruction_image[]',
'repeater' => 'instructions',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/step-image.jpg',
'default' => '',
'is_image_url' => true,
),
),
// Column 2 - Repeater button.
array(
array(
'type' => 'repeater_button',
'id' => 'instructions',
'button_text' => __( 'Add Another Step', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Recipe',
'name' => $this->get_value( 'name' ),
'description' => $this->get_value( 'description' ),
);
// Add author if provided.
$author_name = $this->get_value( 'author_name' );
if ( ! empty( $author_name ) ) {
$schema['author'] = array(
'@type' => 'Person',
'name' => $author_name,
);
}
// Add image if provided.
$image = $this->get_value( 'image' );
if ( ! empty( $image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $image,
);
}
// Add recipe category if provided.
$recipe_category = $this->get_value( 'recipe_category' );
if ( ! empty( $recipe_category ) ) {
$schema['recipeCategory'] = $recipe_category;
}
// Add recipe cuisine if provided.
$recipe_cuisine = $this->get_value( 'recipe_cuisine' );
if ( ! empty( $recipe_cuisine ) ) {
$schema['recipeCuisine'] = $recipe_cuisine;
}
// Add times if provided.
$prep_time = $this->get_value( 'prep_time' );
if ( ! empty( $prep_time ) ) {
$schema['prepTime'] = $prep_time;
}
$cook_time = $this->get_value( 'cook_time' );
if ( ! empty( $cook_time ) ) {
$schema['cookTime'] = $cook_time;
}
$total_time = $this->get_value( 'total_time' );
if ( ! empty( $total_time ) ) {
$schema['totalTime'] = $total_time;
}
// Add recipe yield if provided.
$recipe_yield = $this->get_value( 'recipe_yield' );
if ( ! empty( $recipe_yield ) ) {
$schema['recipeYield'] = $recipe_yield;
}
// Add nutrition if calories provided.
$calories = $this->get_value( 'calories' );
if ( ! empty( $calories ) ) {
$schema['nutrition'] = array(
'@type' => 'NutritionInformation',
'calories' => $calories,
);
}
// Get the ingredients.
$ingredients = $this->get_value( 'ingredients' );
if ( ! empty( $ingredients ) ) {
// Split by comma and trim each ingredient.
$ingredients_array = array_map( 'trim', explode( ',', $ingredients ) );
// Filter out empty values.
$ingredients_array = array_filter( $ingredients_array );
if ( ! empty( $ingredients_array ) ) {
$schema['recipeIngredient'] = array_values( $ingredients_array );
}
}
// Get the instructions.
$instruction_names = $this->get_value( 'instruction_name' );
$instruction_texts = $this->get_value( 'instruction_text' );
$instruction_images = $this->get_value( 'instruction_image' );
// If we have instructions, add them to the schema.
if ( ! empty( $instruction_names ) && ! empty( $instruction_texts ) ) {
// Convert to arrays if single values.
if ( ! is_array( $instruction_names ) ) {
$instruction_names = array( $instruction_names );
}
if ( ! is_array( $instruction_texts ) ) {
$instruction_texts = array( $instruction_texts );
}
if ( ! is_array( $instruction_images ) ) {
$instruction_images = array( $instruction_images );
}
$schema['recipeInstructions'] = array();
// Add each instruction to the schema.
foreach ( $instruction_names as $index => $instruction_name ) {
if ( ! empty( $instruction_name ) && ! empty( $instruction_texts[ $index ] ) ) {
$instruction = array(
'@type' => 'HowToStep',
'name' => $instruction_name,
'text' => $instruction_texts[ $index ],
);
// Add image if provided.
if ( ! empty( $instruction_images[ $index ] ) ) {
$instruction['image'] = $instruction_images[ $index ];
}
$schema['recipeInstructions'][] = $instruction;
}
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,333 @@
<?php
/**
* Generate a snippet for Service schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Service class.
*/
class WPCode_Generator_Schema_Service extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-service';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Service Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for services to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Service schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'service' => array(
'label' => __( 'Service Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Service information.
array(
array(
'type' => 'text',
'label' => __( 'Service Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the service.', 'insert-headers-and-footers' ),
'id' => 'service_name',
'default' => '',
'placeholder' => __( 'Enter service name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Service Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the service.', 'insert-headers-and-footers' ),
'id' => 'service_description',
'default' => '',
'placeholder' => __( 'Describe the service...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Service URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the service page.', 'insert-headers-and-footers' ),
'id' => 'service_url',
'default' => '',
'placeholder' => 'https://example.com/service',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
array(
'type' => 'text',
'label' => __( 'Service Image', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the service image.', 'insert-headers-and-footers' ),
'id' => 'service_image',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/service-image.jpg',
'is_image_url' => true,
),
),
array(
array(
'type' => 'text',
'label' => __( 'Service Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of service (e.g., ProfessionalService, FinancialService).', 'insert-headers-and-footers' ),
'id' => 'service_type',
'smart_tags' => true,
'default' => 'ProfessionalService',
'placeholder' => 'ProfessionalService',
),
array(
'type' => 'text',
'label' => __( 'Area Served', 'insert-headers-and-footers' ),
'description' => __( 'The geographic area where the service is available.', 'insert-headers-and-footers' ),
'id' => 'area_served',
'smart_tags' => true,
'default' => '',
'placeholder' => __( 'Enter area served...', 'insert-headers-and-footers' ),
),
),
),
),
'provider' => array(
'label' => __( 'Service Provider', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Provider information.
array(
array(
'type' => 'text',
'label' => __( 'Provider Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the service provider.', 'insert-headers-and-footers' ),
'id' => 'provider_name',
'default' => '',
'placeholder' => __( 'Enter provider name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'user_name' ),
),
array(
'type' => 'text',
'label' => __( 'Provider URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the service provider.', 'insert-headers-and-footers' ),
'id' => 'provider_url',
'default' => '',
'placeholder' => 'https://example.com',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Provider Logo', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the provider logo.', 'insert-headers-and-footers' ),
'id' => 'provider_logo',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/logo.png',
'is_image_url' => true,
),
array(
'type' => 'text',
'label' => __( 'Provider Type', 'insert-headers-and-footers' ),
'description' => __( 'The type of provider (e.g., Organization, Person).', 'insert-headers-and-footers' ),
'id' => 'provider_type',
'default' => 'Organization',
'smart_tags' => true,
'placeholder' => 'Organization',
),
),
),
),
'contact' => array(
'label' => __( 'Contact Information', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Contact details.
array(
array(
'type' => 'text',
'label' => __( 'Email', 'insert-headers-and-footers' ),
'description' => __( 'The contact email address.', 'insert-headers-and-footers' ),
'id' => 'contact_email',
'smart_tags' => true,
'predefined_tags' => array( 'email' ),
'default' => '',
'placeholder' => 'contact@example.com',
),
array(
'type' => 'text',
'label' => __( 'Telephone', 'insert-headers-and-footers' ),
'description' => __( 'The contact phone number.', 'insert-headers-and-footers' ),
'id' => 'contact_telephone',
'default' => '',
'smart_tags' => true,
'placeholder' => '+1-555-555-5555',
),
array(
'type' => 'text',
'label' => __( 'Address', 'insert-headers-and-footers' ),
'description' => __( 'The physical address.', 'insert-headers-and-footers' ),
'id' => 'contact_address',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter address...', 'insert-headers-and-footers' ),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$service_type = $this->get_value( 'service_type' );
$schema = array(
'@context' => 'https://schema.org',
'@type' => $service_type ? $service_type : 'Service',
);
// Add basic service information.
$service_name = $this->get_value( 'service_name' );
if ( ! empty( $service_name ) ) {
$schema['name'] = $service_name;
}
$service_description = $this->get_value( 'service_description' );
if ( ! empty( $service_description ) ) {
$schema['description'] = $service_description;
}
$service_url = $this->get_value( 'service_url' );
if ( ! empty( $service_url ) ) {
$schema['url'] = $service_url;
}
// Add image.
$service_image = $this->get_value( 'service_image' );
if ( ! empty( $service_image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $service_image,
);
}
// Add area served.
$area_served = $this->get_value( 'area_served' );
if ( ! empty( $area_served ) ) {
$schema['areaServed'] = array(
'@type' => 'City',
'name' => $area_served,
);
}
// Add provider information.
$provider_name = $this->get_value( 'provider_name' );
$provider_url = $this->get_value( 'provider_url' );
$provider_logo = $this->get_value( 'provider_logo' );
$provider_value = $this->get_value( 'provider_type' );
$provider_type = ! empty( $provider_value ) ? $provider_value : 'Organization';
if ( ! empty( $provider_name ) || ! empty( $provider_url ) || ! empty( $provider_logo ) ) {
$schema['provider'] = array(
'@type' => $provider_type,
);
if ( ! empty( $provider_name ) ) {
$schema['provider']['name'] = $provider_name;
}
if ( ! empty( $provider_url ) ) {
$schema['provider']['url'] = $provider_url;
}
if ( ! empty( $provider_logo ) ) {
$schema['provider']['logo'] = array(
'@type' => 'ImageObject',
'url' => $provider_logo,
);
}
}
// Add contact information.
$contact_email = $this->get_value( 'contact_email' );
$contact_telephone = $this->get_value( 'contact_telephone' );
$contact_address = $this->get_value( 'contact_address' );
if ( ! empty( $contact_email ) || ! empty( $contact_telephone ) || ! empty( $contact_address ) ) {
$schema['contactPoint'] = array(
'@type' => 'ContactPoint',
);
if ( ! empty( $contact_email ) ) {
$schema['contactPoint']['email'] = $contact_email;
}
if ( ! empty( $contact_telephone ) ) {
$schema['contactPoint']['telephone'] = $contact_telephone;
}
if ( ! empty( $contact_address ) ) {
$schema['contactPoint']['address'] = array(
'@type' => 'PostalAddress',
'streetAddress' => $contact_address,
);
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,344 @@
<?php
/**
* Generate a snippet for Software schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Software class.
*/
class WPCode_Generator_Schema_Software extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-software';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Software Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for software applications to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Software schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'software' => array(
'label' => __( 'Software Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Software information.
array(
array(
'type' => 'text',
'label' => __( 'Software Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the software application.', 'insert-headers-and-footers' ),
'id' => 'software_name',
'default' => '',
'placeholder' => __( 'Enter software name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Software Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the software.', 'insert-headers-and-footers' ),
'id' => 'software_description',
'default' => '',
'placeholder' => __( 'Describe the software...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Software URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the software page.', 'insert-headers-and-footers' ),
'id' => 'software_url',
'default' => '',
'placeholder' => 'https://example.com/software',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Software Image', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the software screenshot or logo.', 'insert-headers-and-footers' ),
'id' => 'software_image',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/software-image.jpg',
'is_image_url' => true,
),
array(
'type' => 'text',
'label' => __( 'Application Category', 'insert-headers-and-footers' ),
'description' => __( 'The category of the software (e.g., BusinessApplication, GameApplication).', 'insert-headers-and-footers' ),
'id' => 'application_category',
'default' => 'BusinessApplication',
'smart_tags' => true,
'placeholder' => 'BusinessApplication',
),
array(
'type' => 'text',
'label' => __( 'Operating System', 'insert-headers-and-footers' ),
'description' => __( 'The operating system(s) supported (e.g., Windows, macOS, Linux).', 'insert-headers-and-footers' ),
'id' => 'operating_system',
'default' => '',
'smart_tags' => true,
'placeholder' => __( 'Enter operating system...', 'insert-headers-and-footers' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Version', 'insert-headers-and-footers' ),
'description' => __( 'The version number of the software.', 'insert-headers-and-footers' ),
'id' => 'software_version',
'default' => '',
'smart_tags' => true,
'placeholder' => '1.0.0',
),
array(
'type' => 'date',
'label' => __( 'Release Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the software was released.', 'insert-headers-and-footers' ),
'id' => 'release_date',
'default' => '',
'placeholder' => '2024-01-01',
),
),
),
),
'publisher' => array(
'label' => __( 'Publisher Information', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Publisher details.
array(
array(
'type' => 'text',
'label' => __( 'Publisher Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the software publisher.', 'insert-headers-and-footers' ),
'id' => 'publisher_name',
'default' => '',
'placeholder' => __( 'Enter publisher name...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
),
array(
'type' => 'text',
'label' => __( 'Publisher URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the publisher website.', 'insert-headers-and-footers' ),
'id' => 'publisher_url',
'default' => '',
'placeholder' => 'https://example.com',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
),
array(
'type' => 'text',
'label' => __( 'Publisher Logo', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the publisher logo.', 'insert-headers-and-footers' ),
'id' => 'publisher_logo',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'placeholder' => 'https://example.com/logo.png',
'is_image_url' => true,
),
),
),
),
'offers' => array(
'label' => __( 'Offers', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Offer details.
array(
array(
'type' => 'text',
'label' => __( 'Price', 'insert-headers-and-footers' ),
'description' => __( 'The price of the software.', 'insert-headers-and-footers' ),
'id' => 'software_price',
'default' => '',
'smart_tags' => true,
'placeholder' => '99.99',
),
array(
'type' => 'text',
'label' => __( 'Currency', 'insert-headers-and-footers' ),
'description' => __( 'The currency of the price (e.g., USD, EUR).', 'insert-headers-and-footers' ),
'id' => 'software_currency',
'smart_tags' => true,
'default' => 'USD',
'placeholder' => 'USD',
),
array(
'type' => 'select',
'label' => __( 'Availability', 'insert-headers-and-footers' ),
'description' => __( 'The availability status of the software.', 'insert-headers-and-footers' ),
'id' => 'software_availability',
'default' => 'In Stock',
'placeholder' => 'In Stock',
'options' => array(
'InStock' => __( 'In Stock', 'insert-headers-and-footers' ),
'OutOfStock' => __( 'Out of Stock', 'insert-headers-and-footers' ),
'SoldOut' => __( 'Sold Out', 'insert-headers-and-footers' ),
),
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'SoftwareApplication',
);
// Add basic software information.
$software_name = $this->get_value( 'software_name' );
if ( ! empty( $software_name ) ) {
$schema['name'] = $software_name;
}
$software_description = $this->get_value( 'software_description' );
if ( ! empty( $software_description ) ) {
$schema['description'] = $software_description;
}
$software_url = $this->get_value( 'software_url' );
if ( ! empty( $software_url ) ) {
$schema['url'] = $software_url;
}
// Add image.
$software_image = $this->get_value( 'software_image' );
if ( ! empty( $software_image ) ) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => $software_image,
);
}
// Add application category.
$application_category = $this->get_value( 'application_category' );
if ( ! empty( $application_category ) ) {
$schema['applicationCategory'] = $application_category;
}
// Add operating system.
$operating_system = $this->get_value( 'operating_system' );
if ( ! empty( $operating_system ) ) {
$schema['operatingSystem'] = $operating_system;
}
// Add version.
$software_version = $this->get_value( 'software_version' );
if ( ! empty( $software_version ) ) {
$schema['softwareVersion'] = $software_version;
}
// Add release date.
$release_date = $this->get_value( 'release_date' );
if ( ! empty( $release_date ) ) {
$schema['releaseDate'] = $release_date;
}
// Add publisher information.
$publisher_name = $this->get_value( 'publisher_name' );
$publisher_url = $this->get_value( 'publisher_url' );
$publisher_logo = $this->get_value( 'publisher_logo' );
if ( ! empty( $publisher_name ) || ! empty( $publisher_url ) || ! empty( $publisher_logo ) ) {
$schema['publisher'] = array(
'@type' => 'Organization',
);
if ( ! empty( $publisher_name ) ) {
$schema['publisher']['name'] = $publisher_name;
}
if ( ! empty( $publisher_url ) ) {
$schema['publisher']['url'] = $publisher_url;
}
if ( ! empty( $publisher_logo ) ) {
$schema['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => $publisher_logo,
);
}
}
// Add offer information.
$software_price = $this->get_value( 'software_price' );
$software_currency = $this->get_value( 'software_currency' );
$software_availability = $this->get_value( 'software_availability' );
if ( ! empty( $software_price ) ) {
$schema['offers'] = array(
'@type' => 'Offer',
'price' => floatval( $software_price ),
'priceCurrency' => $software_currency ? $software_currency : 'USD',
);
if ( ! empty( $software_availability ) ) {
$schema['offers']['availability'] = 'https://schema.org/' . $software_availability;
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,251 @@
<?php
/**
* Generate a snippet for Video schema markup.
*
* @package WPCode
*/
/**
* WPCode_Generator_Schema_Video class.
*/
class WPCode_Generator_Schema_Video extends WPCode_Generator_Schema_Base {
/**
* The generator slug.
*
* @var string
*/
public $name = 'schema-video';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'schema',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'html';
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Video Schema', 'insert-headers-and-footers' );
$this->description = __( 'Generate schema markup for videos to enhance search results.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'This generator creates Video schema.org markup for improved SEO and rich search results.', 'insert-headers-and-footers' ),
),
),
),
),
'video' => array(
'label' => __( 'Video Details', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Basic Video information.
array(
array(
'type' => 'text',
'label' => __( 'Video Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the video.', 'insert-headers-and-footers' ),
'id' => 'video_title',
'default' => '',
'placeholder' => __( 'Enter video title...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'title' ),
),
array(
'type' => 'textarea',
'label' => __( 'Video Description', 'insert-headers-and-footers' ),
'description' => __( 'A detailed description of the video.', 'insert-headers-and-footers' ),
'id' => 'video_description',
'default' => '',
'placeholder' => __( 'Describe the video...', 'insert-headers-and-footers' ),
'smart_tags' => true,
'predefined_tags' => array( 'excerpt' ),
),
array(
'type' => 'text',
'label' => __( 'Video URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the video page.', 'insert-headers-and-footers' ),
'id' => 'video_url',
'default' => '',
'placeholder' => 'https://example.com/video',
'smart_tags' => true,
'predefined_tags' => array( 'permalink' ),
),
),
array(
array(
'type' => 'text',
'label' => __( 'Video Embed URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the embedded video (e.g., YouTube embed URL).', 'insert-headers-and-footers' ),
'id' => 'video_embed_url',
'smart_tags' => true,
'default' => '',
'placeholder' => 'https://www.youtube.com/embed/VIDEO_ID',
),
array(
'type' => 'text',
'label' => __( 'Video Thumbnail', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the video thumbnail image.', 'insert-headers-and-footers' ),
'id' => 'video_thumbnail',
'smart_tags' => true,
'predefined_tags' => array( 'featured_image' ),
'default' => '',
'placeholder' => 'https://example.com/video-thumbnail.jpg',
'is_image_url' => true,
),
),
array(
array(
'type' => 'text',
'label' => __( 'Video Duration', 'insert-headers-and-footers' ),
'description' => __( 'The duration of the video in ISO 8601 format (e.g., PT1H30M for 1 hour 30 minutes).', 'insert-headers-and-footers' ),
'id' => 'video_duration',
'smart_tags' => true,
'default' => '',
'placeholder' => 'PT1H30M',
),
array(
'type' => 'date',
'label' => __( 'Upload Date', 'insert-headers-and-footers' ),
'description' => __( 'The date when the video was uploaded.', 'insert-headers-and-footers' ),
'id' => 'upload_date',
'default' => '',
'placeholder' => '2024-01-01',
),
),
),
),
'creator' => array(
'label' => __( 'Creator Information', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1 - Creator details.
array(
array(
'type' => 'text',
'label' => __( 'Creator Name', 'insert-headers-and-footers' ),
'description' => __( 'The name of the video creator.', 'insert-headers-and-footers' ),
'id' => 'creator_name',
'default' => '',
'smart_tags' => true,
'predefined_tags' => array( 'author_name' ),
'placeholder' => __( 'Enter creator name...', 'insert-headers-and-footers' ),
),
array(
'type' => 'text',
'label' => __( 'Creator URL', 'insert-headers-and-footers' ),
'description' => __( 'The URL of the creator website or profile.', 'insert-headers-and-footers' ),
'id' => 'creator_url',
'smart_tags' => true,
'predefined_tags' => array( 'author_url' ),
'default' => '',
'placeholder' => 'https://example.com/creator',
),
),
),
),
);
}
/**
* Generate the snippet code without processing smart tags.
*
* @return string
*/
protected function generate_snippet_code() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'VideoObject',
);
// Add basic video information.
$video_title = $this->get_value( 'video_title' );
if ( ! empty( $video_title ) ) {
$schema['name'] = $video_title;
}
$video_description = $this->get_value( 'video_description' );
if ( ! empty( $video_description ) ) {
$schema['description'] = $video_description;
}
$video_url = $this->get_value( 'video_url' );
if ( ! empty( $video_url ) ) {
$schema['url'] = $video_url;
}
// Add thumbnail.
$video_thumbnail = $this->get_value( 'video_thumbnail' );
if ( ! empty( $video_thumbnail ) ) {
$schema['thumbnailUrl'] = $video_thumbnail;
}
// Add duration.
$video_duration = $this->get_value( 'video_duration' );
if ( ! empty( $video_duration ) ) {
$schema['duration'] = $video_duration;
}
// Add upload date.
$upload_date = $this->get_value( 'upload_date' );
if ( ! empty( $upload_date ) ) {
$schema['uploadDate'] = $upload_date;
}
// Add embed URL.
$video_embed_url = $this->get_value( 'video_embed_url' );
if ( ! empty( $video_embed_url ) ) {
$schema['embedUrl'] = $video_embed_url;
}
// Add creator information.
$creator_name = $this->get_value( 'creator_name' );
$creator_url = $this->get_value( 'creator_url' );
if ( ! empty( $creator_name ) || ! empty( $creator_url ) ) {
$schema['creator'] = array(
'@type' => 'Person',
);
if ( ! empty( $creator_name ) ) {
$schema['creator']['name'] = $creator_name;
}
if ( ! empty( $creator_url ) ) {
$schema['creator']['url'] = $creator_url;
}
}
// Encode the schema to JSON with pretty print.
$json = wp_json_encode( $schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
// Return the properly formatted schema JSON-LD with script tags.
return '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>';
}
}
@@ -0,0 +1,296 @@
<?php
/**
* Generate a snippet to enqueue scripts.
*
* @package WPCode
*/
/**
* WPCode_Generator_Script class.
*/
class WPCode_Generator_Script extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'enqueue_script';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'core',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Register Scripts', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet to load JavaScript scripts using wp_register_script.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Using this generator you can create a WordPress function to register and enqueue scripts.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => sprintf(
// Translators: the placeholders add a link to getboostrap.com.
__( 'You can use this to load external scripts or even scripts from a theme or plugin. For example, you could load %1$sbootstrap%2$s from a cdn.', 'insert-headers-and-footers' ),
'<a href="https://getbootstrap.com/" target="_blank">',
'</a>'
),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'add_custom_script',
'default' => 'add_custom_script' . time(),
// This makes it unique for people who don't want to customize.
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Action (hook)', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: placeholders add links to documentation on wordpress.org.
__( 'Hook used to add the scripts: %1$sfrontend%2$s, %3$sadmin%4$s, %5$slogin%6$s or %7$sembed%8$s.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/" target="_blank">',
'</a>',
'<a href="https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/" target="_blank">',
'</a>',
'<a href="https://developer.wordpress.org/reference/hooks/login_enqueue_scripts/" target="_blank">',
'</a>',
'<a href="https://developer.wordpress.org/reference/hooks/enqueue_embed_scripts/" target="_blank">',
'</a>'
),
'id' => 'hook',
'default' => 'wp_enqueue_scripts',
'options' => array(
// Translators: placeholder adds the hook name.
'wp_enqueue_scripts' => sprintf( __( 'Frontend (%s)', 'insert-headers-and-footers' ), 'wp_enqueue_scripts' ),
// Translators: placeholder adds the hook name.
'admin_enqueue_scripts' => sprintf( __( 'Admin (%s)', 'insert-headers-and-footers' ), 'admin_enqueue_scripts' ),
// Translators: placeholder adds the hook name.
'login_enqueue_scripts' => sprintf( __( 'Login (%s)', 'insert-headers-and-footers' ), 'login_enqueue_scripts' ),
// Translators: placeholder adds the hook name.
'enqueue_embed_scripts' => sprintf( __( 'Embed (%s)', 'insert-headers-and-footers' ), 'enqueue_embed_scripts' ),
),
),
),
),
),
'scripts' => array(
'label' => __( 'Scripts', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Script name', 'insert-headers-and-footers' ),
'description' => __( 'This will be used as an identifier in the code, should be lowercase with no spaces.', 'insert-headers-and-footers' ),
'id' => 'script_name',
'name' => 'script_name[]',
'default' => '',
'placeholder' => '',
'repeater' => 'script',
),
array(
'type' => 'text',
'label' => __( 'Script URL', 'insert-headers-and-footers' ),
'description' => __( 'The full URL for the script e.g. https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js.', 'insert-headers-and-footers' ),
'id' => 'script_url',
'name' => 'script_url[]',
'default' => '',
'placeholder' => '',
'repeater' => 'script',
),
array(
'type' => 'text',
'label' => __( 'Dependencies', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of scripts required for this script to load, e.g. jquery', 'insert-headers-and-footers' ),
'id' => 'script_dependencies',
'name' => 'script_dependencies[]',
'default' => '',
'placeholder' => '',
'repeater' => 'script',
),
array(
'type' => 'text',
'label' => __( 'Script Version', 'insert-headers-and-footers' ),
'description' => __( 'The script version.', 'insert-headers-and-footers' ),
'id' => 'script_version',
'name' => 'script_version[]',
'default' => '1.0.0',
'placeholder' => '',
'repeater' => 'script',
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Header or Footer?', 'insert-headers-and-footers' ),
'description' => __( 'Load the script in the page head or in the footer.', 'insert-headers-and-footers' ),
'id' => 'script_location',
'name' => 'script_location[]',
'default' => 'true',
'options' => array(
'true' => __( 'Footer', 'insert-headers-and-footers' ),
'false' => __( 'Header', 'insert-headers-and-footers' ),
),
'repeater' => 'script',
),
array(
'type' => 'select',
'label' => __( 'Deregister script?', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: Placeholders for wp.org docs link.
__( 'Should the script be %1$sderegistered%2$s first? (for example, if you are replacing an existing script).', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/wp_deregister_script/" target="_blank">',
'</a>'
),
'id' => 'script_deregister',
'name' => 'script_deregister[]',
'default' => 'false',
'options' => array(
'false' => __( 'No', 'insert-headers-and-footers' ),
'true' => __( 'Yes', 'insert-headers-and-footers' ),
),
'repeater' => 'script',
),
array(
'type' => 'select',
'label' => __( 'Enqueue script?', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: Placeholders for wp.org docs link.
__( 'Should the script be %1$senqueued%2$s or just registered? (select "No" only if you intend enqueueing it later.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/wp_enqueue_script/" target="_blank">',
'</a>'
),
'id' => 'script_enqueue',
'name' => 'script_enqueue[]',
'default' => 'true',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
'repeater' => 'script',
),
array(
'type' => 'spacer',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add more scripts', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add script" button below to add multiple scripts in this snippet.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add script', 'insert-headers-and-footers' ),
'id' => 'script', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$scripts = $this->get_value( 'script_name' );
$scripts_urls = $this->get_value( 'script_url' );
$scripts_deps = $this->get_value( 'script_dependencies' );
$scripts_versions = $this->get_value( 'script_version' );
$scripts_locations = $this->get_value( 'script_location' );
$scripts_deregister = $this->get_value( 'script_deregister' );
$scripts_enqueue = $this->get_value( 'script_enqueue' );
$code = '';
if ( ! empty( $scripts ) ) {
foreach ( $scripts as $key => $script_name ) {
if ( empty( $script_name ) ) {
continue;
}
$script_name = sanitize_title( $script_name );
$dependencies = explode( ',', $scripts_deps[ $key ] );
$deregister = 'true' === $scripts_deregister[ $key ] ? "wp_deregister_script( '$script_name' );" : '';
$enqueue = 'true' === $scripts_enqueue[ $key ] ? "wp_enqueue_script( '$script_name' );" : '';
$code .= "
$deregister
wp_register_script( '$script_name', '$scripts_urls[$key]', {$this->array_to_code_string($dependencies)}, '$scripts_versions[$key]', $scripts_locations[$key] );
$enqueue
";
}
}
return '// Add custom scripts
function ' . $this->get_value( 'function_name' ) . '() {
' . $code . '
}
add_action( \'' . $this->get_value( 'hook' ) . '\', \'' . $this->get_value( 'function_name' ) . '\' );';
}
}
@@ -0,0 +1,262 @@
<?php
/**
* Generate a snippet for a sidebar.
*
* @package WPCode
*/
/**
* WPCode_Generator_Sidebar class.
*/
class WPCode_Generator_Sidebar extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'sidebar';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'design',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Sidebar', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet to register a sidebar for your widgets.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => sprintf(
// Translators: Placeholders add links to the wordpress.org references.
__( 'This generator makes it easy to add sidebars to your website using the "register_sidebar" function.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/register_sidebar/" target="_blank">',
'</a>'
),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'You can add multiple widget areas for your footer or post-type specific sidebars.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'register_custom_sidebars',
'default' => 'register_custom_sidebars' . time(),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'schedule' => array(
'label' => __( 'Sidebars', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Sidebar Id', 'insert-headers-and-footers' ),
'description' => __( 'This is the sidebar unique id, used in the code, lowercase with no spaces.', 'insert-headers-and-footers' ),
'id' => 'sidebar_id',
'name' => 'sidebar_id[]',
'repeater' => 'sidebars',
),
array(
'type' => 'text',
'label' => __( 'Name', 'insert-headers-and-footers' ),
'description' => __( 'Add a descriptive label for this sidebar to be used in the admin.', 'insert-headers-and-footers' ),
'id' => 'sidebar_name',
'name' => 'sidebar_name[]',
'repeater' => 'sidebars',
),
array(
'type' => 'text',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'A short description for the the admin area.', 'insert-headers-and-footers' ),
'id' => 'sidebar_description',
'name' => 'sidebar_description[]',
'repeater' => 'sidebars',
),
array(
'type' => 'text',
'label' => __( 'CSS Class', 'insert-headers-and-footers' ),
'description' => __( 'Use an unique CSS class name for better control over this sidebar\'s styles in the admin.', 'insert-headers-and-footers' ),
'id' => 'sidebar_css_class',
'name' => 'sidebar_css_class[]',
'repeater' => 'sidebars',
),
),
// Column 2.
array(
array(
'type' => 'html',
'label' => __( 'Before Title', 'insert-headers-and-footers' ),
'description' => __( 'HTML code to add before each widget title.', 'insert-headers-and-footers' ),
'id' => 'before_title',
'name' => 'before_title[]',
'repeater' => 'sidebars',
'default' => '<h2 class="widgettitle">',
),
array(
'type' => 'html',
'label' => __( 'After Title', 'insert-headers-and-footers' ),
'description' => __( 'HTML code to add after each widget title.', 'insert-headers-and-footers' ),
'id' => 'after_title',
'name' => 'after_title[]',
'repeater' => 'sidebars',
'default' => '</h2>',
),
array(
'type' => 'html',
'label' => __( 'Before Widget', 'insert-headers-and-footers' ),
'description' => __( 'HTML code to add before each widget.', 'insert-headers-and-footers' ),
'id' => 'before_widget',
'name' => 'before_widget[]',
'repeater' => 'sidebars',
'default' => '<li id="%1$s" class="widget %2$s">',
),
array(
'type' => 'html',
'label' => __( 'After Widget', 'insert-headers-and-footers' ),
'description' => __( 'HTML code to add after each widget.', 'insert-headers-and-footers' ),
'id' => 'after_widget',
'name' => 'after_widget[]',
'repeater' => 'sidebars',
'default' => '</li>',
),
array(
'type' => 'spacer',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add another sidebar', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add Sidebar" button below to add as many sidebars as you need.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add Sidebar', 'insert-headers-and-footers' ),
'id' => 'sidebars', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$sidebar_id = $this->get_value( 'sidebar_id' );
$sidebar_code = '';
$values = array(
'name' => 'sidebar_name',
'description' => 'sidebar_description',
'class' => 'sidebar_css_class',
'before_title' => 'before_title',
'after_title' => 'after_title',
'before_widget' => 'before_widget',
'after_widget' => 'after_widget',
);
if ( ! empty( $sidebar_id ) ) {
foreach ( $sidebar_id as $key => $id ) {
if ( empty( $id ) ) {
continue;
}
$id = sanitize_title( $id );
$optionals = '';
foreach ( $values as $arg_key => $form_key ) {
$form_values = $this->get_value( $form_key );
$optionals .= $this->get_optional_value_code( $form_values[ $key ], $this->get_default_value( $form_key ), $arg_key, true );
}
$sidebar_code .= "
\$args = array(
'id' => '$id',
$optionals);
register_sidebar( \$args );
";
}
}
return '// Add Sidebars
function ' . $this->get_value( 'function_name' ) . '() {
' . $sidebar_code . '
}
add_action( \'widgets_init\', \'' . $this->get_value( 'function_name' ) . '\' );';
}
}
@@ -0,0 +1,298 @@
<?php
/**
* Generate a snippet to enqueue styles.
*
* @package WPCode
*/
/**
* WPCode_Generator_Style class.
*/
class WPCode_Generator_Style extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'enqueue_style';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'core',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Register Stylesheets', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet to load CSS stylesheets using wp_register_style.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Using this generator you can create a WordPress function to register and enqueue styles.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => sprintf(
// Translators: the placeholders add a link to getboostrap.com.
__( 'You can use this to load external styles or even styles from a theme or plugin. For example, you could load %1$sfontawesome%2$s from a cdn.', 'insert-headers-and-footers' ),
'<a href="https://fontawesome.com/" target="_blank">',
'</a>'
),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'add_custom_style',
'default' => 'add_custom_style' . time(),
// This makes it unique for people who don't want to customize.
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Action (hook)', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: placeholders add links to documentation on wordpress.org.
__( 'Hook used to add the styles: %1$sfrontend%2$s, %3$sadmin%4$s, %5$slogin%6$s or %7$sembed%8$s.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/" target="_blank">',
'</a>',
'<a href="https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/" target="_blank">',
'</a>',
'<a href="https://developer.wordpress.org/reference/hooks/login_enqueue_scripts/" target="_blank">',
'</a>',
'<a href="https://developer.wordpress.org/reference/hooks/enqueue_embed_scripts/" target="_blank">',
'</a>'
),
'id' => 'hook',
'default' => 'wp_enqueue_scripts',
'options' => array(
// Translators: placeholder adds the hook name.
'wp_enqueue_scripts' => sprintf( __( 'Frontend (%s)', 'insert-headers-and-footers' ), 'wp_enqueue_scripts' ),
// Translators: placeholder adds the hook name.
'admin_enqueue_scripts' => sprintf( __( 'Admin (%s)', 'insert-headers-and-footers' ), 'admin_enqueue_scripts' ),
// Translators: placeholder adds the hook name.
'login_enqueue_scripts' => sprintf( __( 'Login (%s)', 'insert-headers-and-footers' ), 'login_enqueue_scripts' ),
// Translators: placeholder adds the hook name.
'enqueue_embed_scripts' => sprintf( __( 'Embed (%s)', 'insert-headers-and-footers' ), 'enqueue_embed_scripts' ),
),
),
),
),
),
'styles' => array(
'label' => __( 'Styles', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Style name', 'insert-headers-and-footers' ),
'description' => __( 'This will be used as an identifier in the code, should be lowercase with no spaces.', 'insert-headers-and-footers' ),
'id' => 'style_name',
'name' => 'style_name[]',
'default' => '',
'placeholder' => '',
'repeater' => 'style',
),
array(
'type' => 'text',
'label' => __( 'Stylesheet URL', 'insert-headers-and-footers' ),
'description' => __( 'The full URL for the stylesheet e.g. https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css.', 'insert-headers-and-footers' ),
'id' => 'style_url',
'name' => 'style_url[]',
'default' => '',
'placeholder' => '',
'repeater' => 'style',
),
array(
'type' => 'text',
'label' => __( 'Dependencies', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of styles required for this style to load, e.g. jquery', 'insert-headers-and-footers' ),
'id' => 'style_dependencies',
'name' => 'style_dependencies[]',
'default' => '',
'placeholder' => '',
'repeater' => 'style',
),
array(
'type' => 'text',
'label' => __( 'Style Version', 'insert-headers-and-footers' ),
'description' => __( 'The style version.', 'insert-headers-and-footers' ),
'id' => 'style_version',
'name' => 'style_version[]',
'default' => '1.0.0',
'placeholder' => '',
'repeater' => 'style',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Media', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: placeholders add a link to the W3.org reference.
__( 'Load the style %1$smedia type%2$s, usually "all".', 'insert-headers-and-footers' ),
'<a href="https://www.w3.org/TR/CSS2/media.html#media-types" target="_blank">',
'</a>'
),
'id' => 'style_media',
'name' => 'style_media[]',
'default' => 'all',
'repeater' => 'style',
),
array(
'type' => 'select',
'label' => __( 'Deregister style?', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: Placeholders for wp.org docs link.
__( 'Should the style be %1$sderegistered%2$s first? (for example, if you are replacing an existing style).', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/wp_deregister_style/" target="_blank">',
'</a>'
),
'id' => 'style_deregister',
'name' => 'style_deregister[]',
'default' => 'false',
'options' => array(
'false' => __( 'No', 'insert-headers-and-footers' ),
'true' => __( 'Yes', 'insert-headers-and-footers' ),
),
'repeater' => 'style',
),
array(
'type' => 'select',
'label' => __( 'Enqueue style?', 'insert-headers-and-footers' ),
'description' => sprintf(
// Translators: Placeholders for wp.org docs link.
__( 'Should the style be %1$senqueued%2$s or just registered? (select "No" only if you intend enqueueing it later.', 'insert-headers-and-footers' ),
'<a href="https://developer.wordpress.org/reference/functions/wp_enqueue_style/" target="_blank">',
'</a>'
),
'id' => 'style_enqueue',
'name' => 'style_enqueue[]',
'default' => 'true',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
'repeater' => 'style',
),
array(
'type' => 'spacer',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add more styles', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add style" button below to add multiple styles in this snippet.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add style', 'insert-headers-and-footers' ),
'id' => 'style', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$styles = $this->get_value( 'style_name' );
$styles_urls = $this->get_value( 'style_url' );
$styles_deps = $this->get_value( 'style_dependencies' );
$styles_versions = $this->get_value( 'style_version' );
$styles_media = $this->get_value( 'style_media' );
$styles_deregister = $this->get_value( 'style_deregister' );
$styles_enqueue = $this->get_value( 'style_enqueue' );
$code = '';
if ( ! empty( $styles ) ) {
foreach ( $styles as $key => $style ) {
if ( empty( $style ) ) {
continue;
}
$style = sanitize_title( $style );
$dependencies = explode( ',', $styles_deps[ $key ] );
$deregister = 'true' === $styles_deregister[ $key ] ? "wp_deregister_style( '$style' );" : '';
$enqueue = 'true' === $styles_enqueue[ $key ] ? "wp_enqueue_style( '$style' );" : '';
$media = 'all' !== $styles_media[ $key ] ? ", '$styles_media[$key]'" : '';
$code .= "
$deregister
wp_register_style( '$style', '$styles_urls[$key]', {$this->array_to_code_string($dependencies)}, '$styles_versions[$key]'$media );
$enqueue
";
}
}
return '// Add custom styles
function ' . $this->get_value( 'function_name' ) . '() {
' . $code . '
}
add_action( \'' . $this->get_value( 'hook' ) . '\', \'' . $this->get_value( 'function_name' ) . '\' );';
}
}
@@ -0,0 +1,622 @@
<?php
/**
* Generate a snippet to register a new taxonomy.
*
* @package WPCode
*/
/**
* The Taxonomy generator class.
*/
class WPCode_Generator_Taxonomy extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'taxonomy';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'content',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Taxonomy', 'insert-headers-and-footers' );
$this->description = __( 'Create a custom taxonomy for your posts using this generator.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Use this generator to create custom taxonomies for your WordPress site.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'Use this to add more taxonomies to posts or custom post types. For example, if you used the Post Type generator to create an Artist post type you can use this one to create a Genre taxonomy.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Function name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other snippets', 'insert-headers-and-footers' ),
'id' => 'function_name',
'placeholder' => 'register_custom_taxonomy',
'default' => 'register_custom_taxonomy' . time(),
// This makes it unique for people who don't want to customize.
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional text domain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'taxonomy' => array(
'label' => __( 'Taxonomy', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Taxonomy Key', 'insert-headers-and-footers' ),
'description' => __( 'Name of taxonomy used in the code, lowercase maximum 20 characters.', 'insert-headers-and-footers' ),
'id' => 'taxonomy',
'placeholder' => 'taxonomy',
'default' => 'taxonomy',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Name (Singular)', 'insert-headers-and-footers' ),
'description' => __( 'The singular taxonomy name (e.g. Genre, Year).', 'insert-headers-and-footers' ),
'id' => 'label',
'placeholder' => 'Taxonomy',
'default' => 'Taxonomy',
),
array(
'type' => 'text',
'label' => __( 'Name (Plural)', 'insert-headers-and-footers' ),
'description' => __( 'The taxonomy plural name (e.g. Genres, Years).', 'insert-headers-and-footers' ),
'id' => 'label_count',
'placeholder' => 'Taxonomies',
'default' => 'Taxonomies',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Link To Post Type(s)', 'insert-headers-and-footers' ),
'description' => __( 'Comma-separated list of Post Types (e.g. post, page)', 'insert-headers-and-footers' ),
'id' => 'post_types',
'placeholder' => 'post',
'default' => 'post',
),
array(
'type' => 'select',
'label' => __( 'Hierarchical', 'insert-headers-and-footers' ),
'description' => __( 'Hierarchical taxonomies can have descendants.', 'insert-headers-and-footers' ),
'id' => 'hierarchical',
'default' => 'false',
'options' => array(
'false' => __( 'No, like tags', 'insert-headers-and-footers' ),
'true' => __( 'Yes, like categories', 'insert-headers-and-footers' ),
),
),
),
),
),
'labels' => array(
'label' => __( 'Labels', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Menu Name', 'insert-headers-and-footers' ),
'id' => 'label_menu_name',
'placeholder' => 'Taxonomy',
'default' => 'Taxonomy',
),
array(
'type' => 'text',
'label' => __( 'All Items', 'insert-headers-and-footers' ),
'id' => 'label_all_items',
'placeholder' => 'All Items',
'default' => 'All Items',
),
array(
'type' => 'text',
'label' => __( 'Parent Item', 'insert-headers-and-footers' ),
'id' => 'label_parent_item',
'placeholder' => 'Parent Item',
'default' => 'Item Archives',
),
array(
'type' => 'text',
'label' => __( 'Parent Item colon', 'insert-headers-and-footers' ),
'id' => 'label_parent_item_colon',
'placeholder' => 'Parent Item:',
'default' => 'Parent Item:',
),
array(
'type' => 'text',
'label' => __( 'New Item Name', 'insert-headers-and-footers' ),
'id' => 'label_new_item',
'placeholder' => 'New Item Name',
'default' => 'New Item Name',
),
array(
'type' => 'text',
'label' => __( 'Add New Item', 'insert-headers-and-footers' ),
'id' => 'label_add_new_item',
'placeholder' => 'Add New Item',
'default' => 'Add New Item',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Edit Item', 'insert-headers-and-footers' ),
'id' => 'label_edit_item',
'placeholder' => 'Edit Item',
'default' => 'Edit Item',
),
array(
'type' => 'text',
'label' => __( 'Update Item', 'insert-headers-and-footers' ),
'id' => 'label_update_item',
'placeholder' => 'Update Item',
'default' => 'Update Item',
),
array(
'type' => 'text',
'label' => __( 'View Item', 'insert-headers-and-footers' ),
'id' => 'label_view_item',
'placeholder' => 'View Item',
'default' => 'View Item',
),
array(
'type' => 'text',
'label' => __( 'Separate Items with commas', 'insert-headers-and-footers' ),
'id' => 'label_separate_items_with_commas',
'placeholder' => 'Separate Items with commas',
'default' => 'Separate Items with commas',
),
array(
'type' => 'text',
'label' => __( 'Add or Remove Items', 'insert-headers-and-footers' ),
'id' => 'label_add_or_remove_items',
'placeholder' => 'Add or remove items',
'default' => 'Add or remove items',
),
array(
'type' => 'text',
'label' => __( 'Choose From Most Used', 'insert-headers-and-footers' ),
'id' => 'label_choose_from_most_used',
'placeholder' => 'Choose from the most used',
'default' => 'Choose from the most used',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Popular Items', 'insert-headers-and-footers' ),
'id' => 'label_popular_items',
'placeholder' => 'Popular Items',
'default' => 'Popular Items',
),
array(
'type' => 'text',
'label' => __( 'Search Items', 'insert-headers-and-footers' ),
'id' => 'label_search_items',
'placeholder' => 'Search Items',
'default' => 'Search Items',
),
array(
'type' => 'text',
'label' => __( 'Not Found', 'insert-headers-and-footers' ),
'id' => 'label_not_found',
'placeholder' => 'Not Found',
'default' => 'Not Found',
),
array(
'type' => 'text',
'label' => __( 'No items', 'insert-headers-and-footers' ),
'id' => 'label_no_items',
'placeholder' => 'No items',
'default' => 'No items',
),
array(
'type' => 'text',
'label' => __( 'Items list', 'insert-headers-and-footers' ),
'id' => 'label_items_list',
'placeholder' => 'Items list',
'default' => 'Items list',
),
array(
'type' => 'text',
'label' => __( 'Items list navigation', 'insert-headers-and-footers' ),
'id' => 'label_items_list_navigation',
'placeholder' => 'Items list navigation',
'default' => 'Items list navigation',
),
),
),
),
'visibility' => array(
'label' => __( 'Visibility', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Public', 'insert-headers-and-footers' ),
// Translators: Placeholders add a link to the wp.org documentation page.
'description' => sprintf( __( 'Should this taxonomy be %1$svisible to authors%2$s?', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_taxonomy/#additional-parameter-information" target="_blank">', '</a>' ),
'id' => 'public',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'select',
'label' => __( 'Show UI', 'insert-headers-and-footers' ),
'description' => __( 'Should this taxonomy have an User Interface for managing?', 'insert-headers-and-footers' ),
'id' => 'show_ui',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Show Admin Column', 'insert-headers-and-footers' ),
'description' => __( 'Should this taxonomy add a column in the list of associated post types?', 'insert-headers-and-footers' ),
'id' => 'show_admin_column',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Show Tag Cloud', 'insert-headers-and-footers' ),
'description' => __( 'Should this taxonomy be visible in the tag cloud widget?', 'insert-headers-and-footers' ),
'id' => 'show_tagcloud',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Show in Navigation Menus', 'insert-headers-and-footers' ),
'description' => __( 'Should this taxonomy be available in menus (Appearance > Menus).', 'insert-headers-and-footers' ),
'id' => 'show_in_nav_menus',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
),
),
),
'permalinks' => array(
'label' => __( 'Permalinks', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Permalink Rewrite', 'insert-headers-and-footers' ),
'description' => __( 'Use Default Permalinks, disable automatic rewriting or use custom permalinks.', 'insert-headers-and-footers' ),
'id' => 'rewrite',
'default' => 'true',
'options' => array(
'true' => __( 'Default (taxonomy key)', 'insert-headers-and-footers' ),
'false' => __( 'Disable permalink rewrites', 'insert-headers-and-footers' ),
'custom' => __( 'Custom permalink structure', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'URL Slug', 'insert-headers-and-footers' ),
'description' => __( 'If you selected custom permalinks use this field for the rewrite base, e.g. taxonomy in https://yoursite.com/taxonomy', 'insert-headers-and-footers' ),
'id' => 'rewrite_slug',
'default' => '',
'placeholder' => '',
),
),
// Column 3.
array(
array(
'type' => 'select',
'label' => __( 'Prepend permastruct', 'insert-headers-and-footers' ),
'description' => __( 'Should the permastruct be prepended to the url (with_front parameter).', 'insert-headers-and-footers' ),
'id' => 'rewrite_with_front',
'default' => 'true',
'options' => array(
'true' => __( 'Yes - default', 'insert-headers-and-footers' ),
'false' => __( 'No', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'select',
'label' => __( 'Hierarchical URL Slug', 'insert-headers-and-footers' ),
'description' => __( 'For hierarchical taxonomies use the whole hierarchy in the URL?', 'insert-headers-and-footers' ),
'id' => 'rewrite_hierarchical',
'default' => 'false',
'options' => array(
'false' => __( 'No - default', 'insert-headers-and-footers' ),
'true' => __( 'Yes', 'insert-headers-and-footers' ),
),
),
),
),
),
'capabilities' => array(
'label' => __( 'Capabilities', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Capabilities', 'insert-headers-and-footers' ),
// Translators: Placeholders add link to wp.org docs.
'description' => sprintf( __( 'User capabilities in relation to this taxonomy. %1$sSee Documentation.%2$s', 'insert-headers-and-footers' ), '<a href="https://developer.wordpress.org/reference/functions/register_taxonomy/#additional-parameter-information" target="_blank">', '</a>' ),
'id' => 'capabilities',
'default' => 'true',
'options' => array(
'true' => __( 'Base capabilities - default', 'insert-headers-and-footers' ),
'custom' => __( 'Custom Capabilities', 'insert-headers-and-footers' ),
),
),
array(
'type' => 'description',
'label' => __( 'Custom Capabilities', 'insert-headers-and-footers' ),
'content' => __( 'Use the fields on the right to assign custom capabilities for this taxonomy.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Edit Terms', 'insert-headers-and-footers' ),
'id' => 'edit_terms',
'default' => 'manage_categories',
'placeholder' => 'manage_categories',
),
array(
'type' => 'text',
'label' => __( 'Delete Terms', 'insert-headers-and-footers' ),
'id' => 'delete_terms',
'default' => 'manage_categories',
'placeholder' => 'manage_categories',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Manage Terms', 'insert-headers-and-footers' ),
'id' => 'manage_terms',
'default' => 'manage_categories',
'placeholder' => 'manage_categories',
),
array(
'type' => 'text',
'label' => __( 'Assign Terms', 'insert-headers-and-footers' ),
'id' => 'assign_terms',
'default' => 'edit_posts',
'placeholder' => 'edit_posts',
),
),
),
),
'rest_api' => array(
'label' => __( 'Rest API', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Show in Rest API?', 'insert-headers-and-footers' ),
'description' => __( 'Add the taxonomy to the WordPress wp-json API.', 'insert-headers-and-footers' ),
'id' => 'show_in_rest',
'default' => 'false',
'options' => array(
'true' => __( 'Yes', 'insert-headers-and-footers' ),
'false' => __( 'No - default', 'insert-headers-and-footers' ),
),
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Rest Base', 'insert-headers-and-footers' ),
'description' => __( 'The base slug that this taxonomy will use in the REST API.', 'insert-headers-and-footers' ),
'id' => 'rest_base',
'default' => '',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Rest Controller Class', 'insert-headers-and-footers' ),
'description' => __( 'The name of a custom Rest Controller class instead of WP_REST_Terms_Controller.', 'insert-headers-and-footers' ),
'id' => 'rest_controller_class',
'default' => '',
),
),
),
),
);
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$rewrite = $this->get_value( 'rewrite' );
$rewrite_options = '';
if ( 'true' === $rewrite ) {
$rewrite = '';
} elseif ( 'custom' === $rewrite ) {
$rewrite = "\t\t'rewrite' => \$rewrite_options,";
$rewrite_options = "
\$rewrite_options = array(
'slug' => '{$this->get_value('rewrite_slug')}',
'with_front' => {$this->get_value( 'rewrite_with_front')},
'hierarchical' => {$this->get_value( 'rewrite_hierarchical')},
);
";
} else {
$rewrite = "\t\t'rewrite' => $rewrite,";
}
$custom_capabilities = '';
$capabilities = $this->get_value( 'capabilities' );
if ( 'custom' === $capabilities ) {
$custom_capabilities = "
\$capabilities = array(
'edit_terms' => '{$this->get_value( 'edit_terms')}',
'delete_terms' => '{$this->get_value( 'delete_terms')}',
'manage_terms' => '{$this->get_value( 'manage_terms')}',
'assign_terms' => '{$this->get_value( 'assign_terms')}',
);
";
$capabilities = " 'capabilities' => \$capabilities,";
} else {
$capabilities = '';
}
return '// Register Custom Taxonomy
function ' . $this->get_value( 'function_name' ) . '() {
$labels = array(
\'name\' => _x( \'' . $this->get_value( 'label_count' ) . '\', \'Taxonomy General Name\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'singular_name\' => _x( \'' . $this->get_value( 'label' ) . '\', \'Taxonomy Singular Name\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'menu_name\' => __( \'' . $this->get_value( 'label_menu_name' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'all_items\' => __( \'' . $this->get_value( 'label_all_items' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'parent_item\' => __( \'' . $this->get_value( 'label_parent_item' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'parent_item_colon\' => __( \'' . $this->get_value( 'label_parent_item_colon' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'new_item_name\' => __( \'' . $this->get_value( 'label_new_item' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'add_new_item\' => __( \'' . $this->get_value( 'label_add_new_item' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'edit_item\' => __( \'' . $this->get_value( 'label_edit_item' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'update_item\' => __( \'' . $this->get_value( 'label_update_item' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'view_item\' => __( \'' . $this->get_value( 'label_view_item' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'separate_items_with_commas\' => __( \'' . $this->get_value( 'label_separate_items_with_commas' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'add_or_remove_items\' => __( \'' . $this->get_value( 'label_add_or_remove_items' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'choose_from_most_used\' => __( \'' . $this->get_value( 'label_choose_from_most_used' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'popular_items\' => __( \'' . $this->get_value( 'label_popular_items' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'search_items\' => __( \'' . $this->get_value( 'label_search_items' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'not_found\' => __( \'' . $this->get_value( 'label_not_found' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'no_terms\' => __( \'' . $this->get_value( 'label_no_items' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'items_list\' => __( \'' . $this->get_value( 'label_items_list' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'items_list_navigation\' => __( \'' . $this->get_value( 'label_items_list_navigation' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
);
' . $rewrite_options . '
' . $custom_capabilities . '
$args = array(
\'labels\' => $labels,
\'hierarchical\' => ' . $this->get_value( 'hierarchical' ) . ',
\'public\' => ' . $this->get_value( 'public' ) . ',
\'show_ui\' => ' . $this->get_value( 'show_ui' ) . ',
\'show_admin_column\' => ' . $this->get_value( 'show_admin_column' ) . ',
\'show_in_nav_menus\' => ' . $this->get_value( 'show_in_nav_menus' ) . ',
\'show_tagcloud\' => ' . $this->get_value( 'show_tagcloud' ) . ',
\'show_in_rest\' => ' . $this->get_value( 'show_in_rest' ) . ',
' . $rewrite . '
' . $capabilities . '
' . $this->get_optional_value( 'show_in_rest' ) . $this->get_optional_value( 'rest_base', true ) . $this->get_optional_value( 'rest_controller_class', true ) . '
);
register_taxonomy( \'' . $this->get_value( 'taxonomy' ) . '\', ' . $this->get_value_comma_separated( 'post_types' ) . ', $args );
}
add_action( \'init\', \'' . $this->get_value( 'function_name' ) . '\', 5 );';
}
}
@@ -0,0 +1,901 @@
<?php
/**
* Base for different types of snippet generators.
*
* @package WPCode
*/
abstract class WPCode_Generator_Type {
/**
* The name (slug) for this generator.
*
* @var string
*/
public $name;
/**
* The title of the generator (translatable field).
*
* @var string
*/
public $title;
/**
* The description of the generator.
* This will be displayed in the list of available generators.
*
* @var string
*/
public $description;
/**
* Array of categories for this generator.
*
* @var array
*/
public $categories;
/**
* Array of tabs for the generator fields.
*
* @var array;
*/
public $tabs;
/**
* Store the form data object in an array so we pick values from it.
*
* @var array
*/
public $form_data;
/**
* Catch here all the fields not using the default value.
*
* @var array
*/
public $fields_from_form = array();
/**
* Location where the snippet will run after being saved.
*
* @var string
*/
public $location = 'everywhere';
/**
* Array of tags to add to the saved snippet.
*
* @var string[]
*/
public $tags = array(
'generated',
);
/**
* Snippet code type for when it will be saved.
*
* @var string
*/
public $code_type = 'php';
/**
* Should the generated snippet be auto-inserted?
*
* @var int
*/
public $auto_insert = 1;
/**
* Constructor.
*/
public function __construct() {
$this->set_strings();
$this->load_tabs();
}
/**
* Replace this in the type to add translatable fields on init.
*
* @return void
*/
abstract protected function set_strings();
/**
* Load the data for the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array();
}
/**
* Let's use a method.
*
* @return string
*/
public function get_title() {
return $this->title;
}
/**
* Let's use a method.
*
* @return string
*/
public function get_description() {
return $this->description;
}
/**
* Let's use a method.
*
* @return string
*/
public function get_location() {
return $this->location;
}
/**
* Let's use a method.
*
* @return array
*/
public function get_tags() {
return $this->tags;
}
/**
* Let's use a method.
*
* @return string
*/
public function get_code_type() {
return $this->code_type;
}
/**
* Get the name.
*
* @return string
*/
public function get_name() {
return $this->name;
}
/**
* Get the categories of this generator.
*
* @return array
*/
public function get_categories() {
return $this->categories;
}
/**
* Takes a tab id and renders the form items.
*
* @param string $tab_id The tab id.
* @param array $snippet_data Data to prefill the form with from a generated snippet.
*
* @return void
*/
public function render_tab( $tab_id, $snippet_data ) {
$tab_info = $this->tabs[ $tab_id ];
foreach ( $tab_info['columns'] as $column_fields ) {
$repeater_groups_fields = array();
$repeater_groups_values = array();
?>
<div class="wpcode-generator-column">
<?php
foreach ( $column_fields as $field ) {
if ( isset( $field['id'] ) && isset( $snippet_data[ $field['id'] ] ) ) {
if ( isset( $field['repeater'] ) ) {
$repeater_groups_fields[ $field['repeater'] ][ $field['id'] ] = $field;
$repeater_groups_values[ $field['repeater'] ][ $field['id'] ] = $snippet_data[ $field['id'] ];
$field['value'] = $snippet_data[ $field['id'] ][0];
} else {
$field['value'] = $snippet_data[ $field['id'] ];
}
}
$this->render_field( $field );
}
// Render repeater fields values.
if ( ! empty( $repeater_groups_values ) ) {
$i = 0;
foreach ( $repeater_groups_values as $repeater_id => $repeater_values ) {
foreach ( $repeater_values as $field_id => $field_values ) {
foreach ( $field_values as $key => $field_value ) {
if ( 0 === $key ) {
// This one was already rendered.
continue;
}
?>
<div class="wpcode-repeater-group" data-id="<?php echo absint( $i ); ?>">
<?php
foreach ( $repeater_groups_fields[ $repeater_id ] as $repeater_field_id => $repeater_groups_field ) {
$repeater_groups_field['value'] = $repeater_values[ $repeater_field_id ][ $key ];
$this->render_field( $repeater_groups_field );
}
?>
<button type="button" class="wpcode-button wpcode-button-secondary wpcode-remove-row" data-target="<?php echo absint( $i ); ?>"><?php esc_html_e( 'Remove Row', 'insert-headers-and-footers' ); ?></button>
</div>
<?php
++$i;
}
continue 2;
}
}
}
?>
</div>
<?php
}
}
/**
* Takes a field config from the tabs object and renders it's input.
*
* @param array $field The field config.
*
* @return void
*/
public function render_field( $field ) {
// Check if the field type is set.
if ( ! isset( $field['type'] ) ) {
return;
}
$type = $field['type'];
// Check if we have a method of rendering the field.
if ( ! method_exists( $this, 'render_field_' . $type ) ) {
return;
}
$this->add_field_wrap( $field );
call_user_func_array( array( $this, 'render_field_' . $type ), array( $field ) );
$this->add_field_wrap( $field, true );
}
/**
* Add field wrap.
*
* @param array $field The field config.
* @param bool $end Whether to output the closing tag.
*
* @return void
*/
public function add_field_wrap( $field, $end = false ) {
if ( $end ) {
echo '</div>';
return;
}
$type = $field['type'];
$repeater = empty( $field['repeater'] ) ? '' : 'data-repeater="' . esc_attr( $field['repeater'] ) . '"';
$classes = array(
'wpcode-generator-field',
'wpcode-generator-field-' . $type,
);
if ( ! empty( $field['autocomplete'] ) ) {
$classes[] = 'wpcode-generator-field-autocomplete';
}
if ( ! empty( $field['is_image_url'] ) ) {
$classes[] = 'wpcode-generator-field-image-url';
}
echo '<div class="' . esc_attr( implode( ' ', $classes ) ) . '" ' . $repeater . '>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Render the description field.
*
* @param array $field The field array as defined in the tabs array.
*
* @return void
*/
public function render_field_description( $field ) {
$field = wp_parse_args(
$field,
array(
'label' => '',
'content' => '',
)
);
$this->text_field_label( $field['label'] );
if ( ! empty( $field['content'] ) ) {
?>
<p><?php echo wp_kses_post( $field['content'] ); ?></p>
<?php
}
}
/**
* Render a label for text-type fields (description, list, etc).
*
* @param string $label The label to render.
*
* @return void
*/
public function text_field_label( $label ) {
if ( empty( $label ) ) {
return;
}
?>
<label><?php echo wp_kses_post( $label ); ?></label>
<?php
}
/**
* Render a list from an array.
*
* @param array $field The field array.
*
* @return void
*/
public function render_field_list( $field ) {
$field = wp_parse_args(
$field,
array(
'label' => '',
'content' => array(),
)
);
$this->text_field_label( $field['label'] );
if ( ! empty( $field['content'] ) && is_array( $field['content'] ) ) {
?>
<ul>
<?php foreach ( $field['content'] as $li ) { ?>
<li><?php echo wp_kses_post( $li ); ?></li>
<?php } ?>
</ul>
<?php
}
}
/**
* Render a text input field.
*
* @param array $field The field array.
*
* @return void
*/
public function render_field_text( $field ) {
if ( empty( $field['id'] ) ) {
return;
}
if ( ! empty( $field['label'] ) ) {
$this->input_field_label( $field['label'], $field['id'] );
}
$id = $field['id'];
$placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : '';
$name = empty( $field['name'] ) ? $id : $field['name'];
$value = isset( $field['value'] ) ? $field['value'] : $this->get_default_value( $field['id'] );
// Check if this is an image URL field.
if ( ! empty( $field['is_image_url'] ) ) {
?>
<div class="wpcode-image-url-field">
<input type="text" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" class="wpcode-input-text wpcode-image-url-input"/>
<button type="button" class="wpcode-button wpcode-button-secondary wpcode-media-library-button" data-target="<?php echo esc_attr( $id ); ?>">
<?php esc_html_e( 'Choose Image', 'insert-headers-and-footers' ); ?>
</button>
</div>
<?php
} else {
?>
<input type="text" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" class="wpcode-input-text"/>
<?php
}
if ( ! empty( $field['description'] ) ) {
$this->input_field_description( $field['description'] );
}
if ( ! empty( $field['autocomplete'] ) ) {
?>
<script type="application/json" class="wpcode-field-autocomplete"><?php echo wp_json_encode( $field['autocomplete'] ); ?></script>
<?php
}
}
/**
* HTML field just extends the text one for now.
*
* @param array $field The field array.
*
* @return void
*/
public function render_field_html( $field ) {
$this->render_field_text( $field );
}
/**
* Render a label for an input.
*
* @param string $label The label text.
* @param string $id The id to use for the "for" attribute of the label.
*
* @return void
*/
public function input_field_label( $label, $id ) {
if ( empty( $label ) ) {
return;
}
?>
<label for="<?php echo esc_attr( $id ); ?>">
<?php echo wp_kses_post( $label ); ?>
</label>
<?php
}
/**
* Render a field's description.
*
* @param string $description The field description.
*
* @return void
*/
public function input_field_description( $description ) {
?>
<p class="wpcode-field-description"><?php echo wp_kses_post( $description ); ?></p>
<?php
}
/**
* Render a select dropdown.
*
* @param array $field The field options.
*
* @return void
*/
public function render_field_select( $field ) {
if ( empty( $field['id'] ) ) {
return;
}
if ( ! empty( $field['label'] ) ) {
$this->input_field_label( $field['label'], $field['id'] );
}
$id = $field['id'];
$name = empty( $field['name'] ) ? $id : $field['name'];
if ( ! empty( $field['options'] ) && is_array( $field['options'] ) ) {
reset( $field['options'] );
if ( isset( $field['value'] ) ) {
$selected = $field['value'];
} else {
$selected = isset( $field['default'] ) ? $field['default'] : key( $field['options'] );
}
?>
<select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $id ); ?>">
<?php
foreach ( $field['options'] as $value => $label ) {
?>
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $selected, $value ); ?>><?php echo esc_html( $label ); ?></option>
<?php } ?>
</select>
<?php
}
if ( ! empty( $field['description'] ) ) {
$this->input_field_description( $field['description'] );
}
}
/**
* Render a list of checkboxes from a field list of options.
*
* @param array $field The field settings array.
*
* @return void
*/
public function render_field_checkbox_list( $field ) {
if ( empty( $field['options'] ) ) {
return;
}
$checked = empty( $field['default'] ) ? array() : $field['default'];
if ( isset( $field['value'] ) ) {
$checked = $field['value'];
}
foreach ( $field['options'] as $value => $label ) {
?>
<div class="wpcode-checkbox-line">
<label class="wpcode-checkbox-toggle">
<input type="checkbox" name="<?php echo esc_attr( $field['id'] ); ?>[]" value="<?php echo esc_attr( $value ); ?>" id="<?php echo esc_attr( $field['id'] . '_' . $value ); ?>" <?php checked( in_array( $value, $checked, true ) ); ?>/>
<span class="wpcode-checkbox-toggle-slider"></span>
</label>
<label for="<?php echo esc_attr( $field['id'] . '_' . $value ); ?>"><?php echo esc_html( $label ); ?></label>
</div>
<?php
}
}
/**
* The repeater button used to add new repeater rows.
*
* @param array $field The field array.
*
* @return void
*/
public function render_field_repeater_button( $field ) {
if ( empty( $field['id'] ) ) {
return;
}
?>
<button type="button" class="wpcode-button wpcode-button-secondary wpcode-repeater-button" data-target="<?php echo esc_attr( $field['id'] ); ?>"><?php echo esc_html( $field['button_text'] ); ?></button>
<?php
}
/**
* Set the form data object from an array - usually the $_POST object.
*
* @param array $form_data The form data object.
*
* @return string
*/
public function process_form_data( $form_data ) {
$this->form_data = $form_data;
return $this->get_snippet_code();
}
/**
* Get the snippet code with the values added to it.
*
* @return string
*/
abstract public function get_snippet_code();
/**
* Get a value for output in the snippet code, if the form data is set
* we sanitise that and return it otherwise return the default value.
*
* @param string $field_id The field id.
*
* @return string
*/
public function get_value( $field_id ) {
return ! empty( $this->form_data[ $field_id ] ) ? $this->sanitize_form_data( $field_id ) : $this->get_default_value( $field_id );
}
/**
* Sanitize form value based on the field type.
*
* @param string $field_id The id of the field.
*
* @return string
*/
protected function sanitize_form_data( $field_id ) {
$field_type = $this->find_field_prop( $field_id, 'type' );
$value = $this->form_data[ $field_id ];
if ( 'text' === $field_type && is_array( $value ) ) {
$field_type = 'text_array';
}
if ( 'textarea' === $field_type && is_array( $value ) ) {
$field_type = 'textarea_array';
}
if ( 'select' === $field_type && is_array( $value ) ) {
$field_type = 'text_array';
}
if ( 'html' === $field_type && is_array( $value ) ) {
$field_type = 'html_array';
}
switch ( $field_type ) {
case 'text_array':
case 'checkbox_list':
$sanitized = array_map( 'sanitize_text_field', wp_unslash( $value ) );
foreach ( $sanitized as $item => $value ) {
$sanitized[ $item ] = '' === $value ? $this->get_default_value( $field_id ) : $value;
}
break;
case 'textarea_array':
$sanitized = array_map( 'sanitize_textarea_field', wp_unslash( $value ) );
foreach ( $sanitized as $item => $value ) {
$sanitized[ $item ] = '' === $value ? $this->get_default_value( $field_id ) : $value;
}
break;
case 'html_array':
$sanitized = array_map( 'wp_kses_post', wp_unslash( $value ) );
foreach ( $sanitized as $item => $value ) {
$sanitized[ $item ] = '' === $value ? $this->get_default_value( $field_id ) : $value;
}
break;
case 'textarea':
$sanitized = sanitize_textarea_field( wp_unslash( $value ) );
break;
case 'html':
$sanitized = wp_kses_post( wp_unslash( $value ) );
break;
case 'date':
case 'date_and_time':
$sanitized = sanitize_text_field( wp_unslash( $value ) );
break;
case 'text':
default:
$sanitized = sanitize_text_field( wp_unslash( $value ) );
}
if ( ! isset( $this->fields_from_form[ $field_id ] ) ) {
$this->fields_from_form[ $field_id ] = $sanitized;
}
return $sanitized;
}
/**
* Go through the tabs config and find a field value by its id.
*
* @param string $field_id The id of the field.
* @param string $field_value The key of the value (e.g. 'content').
*
* @return string
*/
public function find_field_prop( $field_id, $field_value ) {
$tabs = $this->get_tabs();
foreach ( $tabs as $tab ) {
foreach ( $tab['columns'] as $column_fields ) {
foreach ( $column_fields as $field ) {
if ( ! empty( $field['id'] ) && $field_id === $field['id'] ) {
return ! isset( $field[ $field_value ] ) ? '' : $field[ $field_value ];
}
}
}
}
return '';
}
/**
* Get the tabs for rendering.
*
* @return array
*/
public function get_tabs() {
return $this->tabs;
}
/**
* Go through the tabs config and find the default value for a field.
*
* @param string $field_id The id of the field for which we want the default value.
*
* @return string
*/
public function get_default_value( $field_id ) {
return $this->find_field_prop( $field_id, 'default' );
}
/**
* Get a string with values comma-separated and convert it to PHP array.
*
* @param string $field_id The id of the field to grab the data for.
*
* @return string
*/
public function get_value_comma_separated( $field_id ) {
return $this->get_value_comma_separated_code( $this->get_value( $field_id ) );
}
/**
* Get a comma separated string and return an array.
*
* @param string $value The value to explode.
* @param bool $quotes Whether to add quotes to the values or not.
*
* @return string
*/
public function get_value_comma_separated_code( $value, $quotes = true ) {
$items = explode( ',', $value );
return $this->array_to_code_string( $items, $quotes );
}
/**
* Takes an array of strings and returns php code for an array of strings.
*
* @param string[] $items The array to convert.
* @param bool $quotes Whether to add quotes to the values or not.
*
* @return string
*/
public function array_to_code_string( $items, $quotes = true ) {
if ( empty( $items ) || empty( $items[0] ) ) {
return 'array()';
}
$items = array_map( 'trim', $items );
if ( $quotes ) {
$items = array_map( array( $this, 'add_quotes' ), $items );
}
return 'array( ' . implode( ', ', $items ) . ' )';
}
/**
* Callback to add quotes because we can't use closures in PHP 5.2.
*
* @param string $item String to add quotes to.
*
* @return string
*/
private function add_quotes( $item ) {
return "'$item'";
}
/**
* Get value of array fields like checkboxes or select multiple.
*
* @param string $field_id The field id.
*
* @return string
*/
public function get_array_value( $field_id ) {
$value = $this->get_value( $field_id );
return $this->array_to_code_string( $value );
}
/**
* Get the fields that were updated using the form (not using the default value).
*
* @return array
*/
public function get_generator_data() {
return $this->fields_from_form;
}
/**
* If the generated snippet should be auto-inserted or not (used as a shortcode).
*
* @return bool
*/
public function get_auto_insert() {
return $this->auto_insert;
}
/**
* Get PHP array code for an optional parameter by field ID.
*
* @param string $field_id The field id to grab the value for.
* @param bool $quotes Wrap the output value in quotes?.
* @param string $array_key The array key if different from the field id, otherwise the field id is used.
*
* @return string
* @see get_optional_value_code
*/
public function get_optional_value( $field_id, $quotes = false, $array_key = '' ) {
if ( empty( $array_key ) ) {
$array_key = $field_id;
}
$value = $this->get_value( $field_id );
$default = $this->get_default_value( $field_id );
$comma_separated = $this->find_field_prop( $field_id, 'comma-separated' );
return $this->get_optional_value_code( $value, $default, $array_key, $quotes, $comma_separated );
}
/**
* Get PHP array code for an optional parameter.
* If the default value is used nothing will be output.
* It will also attempt to align all the values properly.
*
* @param string $value The current value to compare to the default.
* @param string $default The default value.
* @param string $array_key The array key to use if the value will be output.
* @param bool $quotes Whether to use quotes for the value output.
* @param bool $comma_separated If the value is actually a comma-separated list.
*
* @return string
*/
public function get_optional_value_code( $value, $default, $array_key, $quotes = false, $comma_separated = false ) {
if ( $value === $default ) {
return '';
}
if ( $comma_separated ) {
$value = $this->get_value_comma_separated_code( $value, $quotes );
} elseif ( $quotes ) {
$value = "'$value'";
}
$indent = 22 - strlen( $array_key );
$indent = str_repeat( ' ', $indent );
return "\t\t'$array_key'$indent=> $value,\n";
}
/**
* Output a simple spacer used to align repeater rows.
*
* @return void
*/
public function render_field_spacer() {
?>
<div class="wpcode-column-spacer"></div>
<?php
}
/**
* Render a textarea field, optionally a code editor.
*
* @param array $field The field settings.
*
* @return void
*/
public function render_field_textarea( $field ) {
if ( empty( $field['id'] ) ) {
return;
}
if ( ! empty( $field['label'] ) ) {
$this->input_field_label( $field['label'], $field['id'] );
}
$id = $field['id'];
$name = empty( $field['name'] ) ? $id : $field['name'];
$classes = array(
'wpcode-input-textarea',
);
if ( ! empty( $field['code'] ) ) {
$classes[] = 'wpcode-generator-code';
}
$value = isset( $field['value'] ) ? $field['value'] : '';
?>
<textarea name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"><?php echo esc_html( $value ); ?></textarea>
<?php
if ( ! empty( $field['description'] ) ) {
$this->input_field_description( $field['description'] );
}
}
/**
* Sanitize a value to be used as a PHP function name.
*
* @param string $value The name you want sanitized.
*
* @return string
*/
public function sanitize_function_name( $value ) {
return str_replace( '-', '_', sanitize_title_with_dashes( $value ) );
}
/**
* Render a date input field (date only).
*
* @param array $field The field array.
*
* @return void
*/
public function render_field_date( $field ) {
if ( empty( $field['id'] ) ) {
return;
}
if ( ! empty( $field['label'] ) ) {
$this->input_field_label( $field['label'], $field['id'] );
}
$id = $field['id'];
$placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : '';
$name = empty( $field['name'] ) ? $id : $field['name'];
$value = isset( $field['value'] ) ? $field['value'] : $this->get_default_value( $field['id'] );
?>
<input type="date" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" class="wpcode-input-date"/>
<?php
if ( ! empty( $field['description'] ) ) {
$this->input_field_description( $field['description'] );
}
}
/**
* Render a date and time input field.
*
* @param array $field The field array.
*
* @return void
*/
public function render_field_date_and_time( $field ) {
if ( empty( $field['id'] ) ) {
return;
}
if ( ! empty( $field['label'] ) ) {
$this->input_field_label( $field['label'], $field['id'] );
}
$id = $field['id'];
$placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : '';
$name = empty( $field['name'] ) ? $id : $field['name'];
$value = isset( $field['value'] ) ? $field['value'] : $this->get_default_value( $field['id'] );
?>
<input type="datetime-local" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" class="wpcode-input-date"/>
<?php
if ( ! empty( $field['description'] ) ) {
$this->input_field_description( $field['description'] );
}
}
}
@@ -0,0 +1,570 @@
<?php
/**
* Generate a snippet to add a custom Widget.
*
* @package WPCode
*/
/**
* WPCode_Generator_Script class.
*/
class WPCode_Generator_Widget extends WPCode_Generator_Type {
/**
* The generator slug.
*
* @var string
*/
public $name = 'widget';
/**
* The categories for this generator.
*
* @var string[]
*/
public $categories = array(
'design',
);
/**
* Set the translatable strings.
*
* @return void
*/
protected function set_strings() {
$this->title = __( 'Widget', 'insert-headers-and-footers' );
$this->description = __( 'Generate a snippet to register a custom sidebar widget for your website.', 'insert-headers-and-footers' );
}
/**
* Load the generator tabs.
*
* @return void
*/
protected function load_tabs() {
$this->tabs = array(
'info' => array(
'label' => __( 'Info', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
// Column 1 fields.
array(
'type' => 'description',
'label' => __( 'Overview', 'insert-headers-and-footers' ),
'content' => __( 'Using this generator you can easily add a custom sidebar widget with settings.', 'insert-headers-and-footers' ),
),
),
// Column 2.
array(
// Column 2 fields.
array(
'type' => 'list',
'label' => __( 'Usage', 'insert-headers-and-footers' ),
'content' => array(
__( 'Fill in the forms using the menu on the left.', 'insert-headers-and-footers' ),
__( 'Click the "Update Code" button.', 'insert-headers-and-footers' ),
__( 'Click on "Use Snippet" to create a new snippet with the generated code.', 'insert-headers-and-footers' ),
__( 'Activate and save the snippet and you\'re ready to go', 'insert-headers-and-footers' ),
),
),
),
// Column 3.
array(
// Column 3 fields.
array(
'type' => 'description',
'label' => __( 'Examples', 'insert-headers-and-footers' ),
'content' => __( 'Sidebar widgets are very useful when you want to display the same content on multiple pages, you can create a widget with contact methods, for example and fields to set a phone number, email, etc.', 'insert-headers-and-footers' ),
),
),
),
),
'general' => array(
'label' => __( 'General', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Class name', 'insert-headers-and-footers' ),
'description' => __( 'Make this unique to avoid conflicts with other similar snippets.', 'insert-headers-and-footers' ),
'id' => 'class_name',
'placeholder' => 'Custom_Generated_Widget',
'default' => 'Custom_Generated_Widget' . time(),
// This makes it unique for people who don't want to customize.
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Prefix', 'insert-headers-and-footers' ),
'description' => __( 'Used to prefix all the field names.', 'insert-headers-and-footers' ),
'id' => 'prefix',
'placeholder' => 'custom_',
'default' => 'custom' . time() . '_',
),
),
// Column 3.
array(
array(
'type' => 'text',
'label' => __( 'Text Domain', 'insert-headers-and-footers' ),
'description' => __( 'Optional textdomain for translations.', 'insert-headers-and-footers' ),
'id' => 'text_domain',
'placeholder' => 'text_domain',
'default' => 'text_domain',
),
),
),
),
'widget' => array(
'label' => __( 'Widget', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'text',
'label' => __( 'Widget ID', 'insert-headers-and-footers' ),
'description' => __( 'Unique id for the widget, used in the code.', 'insert-headers-and-footers' ),
'id' => 'widget_id',
'name' => 'widget_id',
'default' => 'custom_widget_id',
'placeholder' => '',
),
array(
'type' => 'text',
'label' => __( 'Widget Title', 'insert-headers-and-footers' ),
'description' => __( 'The title of the widget (displayed in the admin).', 'insert-headers-and-footers' ),
'id' => 'widget_title',
'name' => 'widget_title',
'default' => 'Custom Widget',
'placeholder' => '',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'Description used in the admin to explain what the widget is used for.', 'insert-headers-and-footers' ),
'id' => 'description',
'name' => 'description',
'default' => 'This is a custom widget generated with WPCode',
),
array(
'type' => 'text',
'label' => __( 'CSS Class', 'insert-headers-and-footers' ),
'description' => __( 'Widget-specific CSS class name.', 'insert-headers-and-footers' ),
'id' => 'css_class',
'default' => 'custom-generated-widget',
),
),
// Column 3.
array(
array(
'type' => 'textarea',
'label' => __( 'Widget Output Code', 'insert-headers-and-footers' ),
'description' => __( 'PHP Code used for outputting the fields in the frontend. If left empty it will output the fields values in a simple list.', 'insert-headers-and-footers' ),
'id' => 'code',
'code' => true,
),
),
),
),
'fields' => array(
'label' => __( 'Fields', 'insert-headers-and-footers' ),
'columns' => array(
// Column 1.
array(
array(
'type' => 'select',
'label' => __( 'Field Type', 'insert-headers-and-footers' ),
'description' => __( 'Pick the type of field you want to use for this setting.', 'insert-headers-and-footers' ),
'id' => 'field_type',
'name' => 'field_type[]',
'options' => array(
'text' => __( 'Text', 'insert-headers-and-footers' ),
'email' => __( 'Email', 'insert-headers-and-footers' ),
'url' => __( 'URL', 'insert-headers-and-footers' ),
'number' => __( 'Number', 'insert-headers-and-footers' ),
'textarea' => __( 'Textarea', 'insert-headers-and-footers' ),
'select' => __( 'Select', 'insert-headers-and-footers' ),
'checkbox' => __( 'Checkboxes', 'insert-headers-and-footers' ),
'radio' => __( 'Radio', 'insert-headers-and-footers' ),
),
'repeater' => 'fields',
),
array(
'type' => 'text',
'label' => __( 'Field ID', 'insert-headers-and-footers' ),
'description' => __( 'Unique id for this field, used in the code.', 'insert-headers-and-footers' ),
'id' => 'field_id',
'name' => 'field_id[]',
'repeater' => 'fields',
),
array(
'type' => 'text',
'label' => __( 'Field Label', 'insert-headers-and-footers' ),
'description' => __( 'The label displayed next to this field in the admin form.', 'insert-headers-and-footers' ),
'id' => 'field_label',
'name' => 'field_label[]',
'repeater' => 'fields',
),
array(
'type' => 'spacer',
),
),
// Column 2.
array(
array(
'type' => 'text',
'label' => __( 'Description', 'insert-headers-and-footers' ),
'description' => __( 'Display a short descriptive text below this field.', 'insert-headers-and-footers' ),
'id' => 'field_description',
'name' => 'field_description[]',
'repeater' => 'fields',
),
array(
'type' => 'text',
'label' => __( 'Default', 'insert-headers-and-footers' ),
'description' => __( 'Set the default value for this field.', 'insert-headers-and-footers' ),
'id' => 'field_default',
'name' => 'field_default[]',
'repeater' => 'fields',
),
array(
'type' => 'textarea',
'label' => __( 'Options', 'insert-headers-and-footers' ),
'description' => __( 'Use value|label for each line to add options for select, checkbox or radio.', 'insert-headers-and-footers' ),
'id' => 'field_options',
'name' => 'field_options[]',
'repeater' => 'fields',
),
),
// Column 3.
array(
array(
'type' => 'description',
'label' => __( 'Add another field', 'insert-headers-and-footers' ),
'content' => __( 'Use the "Add field" button below to add as many fields as you need.', 'insert-headers-and-footers' ),
),
array(
'type' => 'repeater_button',
'button_text' => __( 'Add field', 'insert-headers-and-footers' ),
'id' => 'fields', // Repeater to repeat when clicked.
),
),
),
),
);
}
/**
* Dynamically get the code for a widget field by type.
*
* @param string $type The type of field.
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param string $options The options for fields that have options.
*
* @return mixed|string
*/
public function get_widget_field_code( $type, $id, $label, $description, $options ) {
if ( ! method_exists( $this, 'widget_field_' . $type ) ) {
return '';
}
$options = preg_split( "/\r\n|[\r\n]/", $options );
$processed_options = array();
foreach ( $options as $option ) {
$split_option = explode( '|', $option );
$processed_options[ $split_option[0] ] = $split_option[0];
if ( isset( $split_option[1] ) ) {
$processed_options[ $split_option[0] ] = $split_option[1];
}
}
return call_user_func_array(
array( $this, 'widget_field_' . $type ),
array(
$id,
$label,
$description,
$processed_options,
)
);
}
/**
* Get the code for a text field.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param array $options The field options (unused here).
* @param string $type The input type, so we can reuse this for similar fields.
*
* @return string
*/
public function widget_field_text( $id, $label, $description, $options = array(), $type = 'text' ) {
return "
echo '<p>';
echo '<label for=\"'. \$this->get_field_id( '$id' ) .'\">'. __( '$label', '{$this->get_value( 'text_domain' ) }' ) .'</label>';
echo '<input type=\"$type\" id=\"'. \$this->get_field_id( '$id' ) .'\" name=\"'. \$this->get_field_name( '$id' ) .'\" class=\"widefat\" value=\"'. esc_attr(\$instance['$id']) .'\" />';
{$this->widget_field_description( $description )}
echo '</p>';
";
}
/**
* Email field, uses the text field with a different input type.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param array $options The field options (unused here).
*
* @return string
*/
public function widget_field_email( $id, $label, $description, $options = array() ) {
return $this->widget_field_text( $id, $label, $description, $options, 'email' );
}
/**
* URL field, uses the text field with a different input type.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param array $options The field options (unused here).
*
* @return string
*/
public function widget_field_url( $id, $label, $description, $options = array() ) {
return $this->widget_field_text( $id, $label, $description, $options, 'url' );
}
/**
* Number field, uses the text field with a different input type.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param array $options The field options (unused here).
*
* @return string
*/
public function widget_field_number( $id, $label, $description, $options = array() ) {
return $this->widget_field_text( $id, $label, $description, $options, 'number' );
}
/**
* Textarea field.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param array $options The field options (unused here).
*
* @return string
*/
public function widget_field_textarea( $id, $label, $description, $options = array() ) {
return "
echo '<p>';
echo '<label for=\"'. \$this->get_field_id( '$id' ) .'\">'. __( '$label', '{$this->get_value( 'text_domain' ) }' ) .'</label>';
echo '<textarea id=\"'. \$this->get_field_id( '$id' ) .'\" name=\"'. \$this->get_field_name( '$id' ) .'\" class=\"widefat\">'. esc_html(\$instance['$id']) .'</textarea>';
{$this->widget_field_description( $description )}
echo '</p>';
";
}
/**
* Get the code for a text field.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param string $options The field options.
*
* @return string
*/
public function widget_field_select( $id, $label, $description, $options = array() ) {
$field_code = "
echo '<p>';
echo '<label for=\"'. \$this->get_field_id( '$id' ) .'\">'. __( '$label', '{$this->get_value( 'text_domain' ) }' ) .'</label>';
echo '<select id=\"'. \$this->get_field_id( '$id' ) .'\" name=\"'. \$this->get_field_name( '$id' ) .'\" class=\"widefat\">';";
foreach ( $options as $value => $label ) {
if ( empty( $value ) ) {
continue;
}
$field_code .= "\n\t\t echo'<option value=\"$value\" '. selected('$value', \$instance['$id'], false) .'>$label</option>';";
}
$field_code .= "\n\t\techo '</select>';
{$this->widget_field_description( $description )}
echo '</p>';";
return $field_code;
}
/**
* Get the code for a checkbox field.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param string $options The field options.
*
* @return string
*/
public function widget_field_checkbox( $id, $label, $description, $options = array() ) {
$field_code = "
echo '<p>';
echo '<label for=\"'. \$this->get_field_id( '$id' ) .'\">'. __( '$label', '{$this->get_value( 'text_domain' ) }' ) .'</label>';";
foreach ( $options as $value => $label ) {
if ( empty( $value ) ) {
continue;
}
$field_code .= "\n\t\t echo'<div><label><input type=\"checkbox\" value=\"$value\" '. checked( in_array( '$value', \$instance['$id'], true ), true, false) .' name=\"'. \$this->get_field_name( '$id' ) .'[]\"> $label</label></div>';";
}
$field_code .= "{$this->widget_field_description( $description )}
echo '</p>';";
return $field_code;
}
/**
* Get the code for a radio field.
*
* @param string $id The field id.
* @param string $label The field label.
* @param string $description The field description.
* @param string $options The field options.
*
* @return string
*/
public function widget_field_radio( $id, $label, $description, $options = array() ) {
$field_code = "
echo '<p>';
echo '<label for=\"'. \$this->get_field_id( '$id' ) .'\">'. __( '$label', '{$this->get_value( 'text_domain' ) }' ) .'</label>';";
foreach ( $options as $value => $label ) {
if ( empty( $value ) ) {
continue;
}
$field_code .= "\n\t\t echo'<div><label><input type=\"radio\" value=\"$value\" '. checked( '$value', \$instance['$id'], false) .' name=\"'. \$this->get_field_name( '$id' ) .'\"> $label</label></div>';";
}
$field_code .= "\n{$this->widget_field_description( $description )}
echo '</p>';";
return $field_code;
}
/**
* Get standard markup for the description of a field.
*
* @param string $description The field description.
*
* @return string
*/
public function widget_field_description( $description ) {
if ( empty( $description ) ) {
return '';
}
return "echo '<span class=\"description\">' . __( '$description', '{$this->get_value( 'text_domain' ) }' ) . '</span>';";
}
/**
* Get the snippet code with dynamic values applied.
*
* @return string
*/
public function get_snippet_code() {
$instance_defaults = '';
$fields_markup = '';
$fields = $this->get_value( 'field_id' );
$labels = $this->get_value( 'field_label' );
$values = $this->get_value( 'field_default' );
$type = $this->get_value( 'field_type' );
$options = $this->get_value( 'field_options' );
$descriptions = $this->get_value( 'field_description' );
if ( ! empty( $fields ) && is_array( $fields ) ) {
foreach ( $fields as $key => $field_id ) {
if ( empty( $field_id ) ) {
continue;
}
$value = "'$values[$key]'";
if ( 'checkbox' === $type[ $key ] ) {
$value = "array('$values[$key]')";
}
$instance_defaults .= "\t\t\t'$field_id' => $value,\n";
$fields_markup .= $this->get_widget_field_code( $type[ $key ], $field_id, $labels[ $key ], $descriptions[ $key ], $options[ $key ] );
}
}
$widget_output = $this->get_value( 'code' );
if ( empty( $widget_output ) && ! empty( $fields ) && is_array( $fields ) ) {
// If there's no custom PHP code for the output build a simple list output.
$widget_output = "\n\t\techo '<ul>';\n";
foreach ( $fields as $key => $field_id ) {
if ( empty( $field_id ) ) {
continue;
}
$value = "\$instance['$field_id']";
if ( 'checkbox' === $type[ $key ] ) {
$value = "implode( ', ', $value )";
}
$widget_output .= "\t\t\techo '<li>{$labels[ $key ]}: ' . $value . '</li>';\n";
}
$widget_output .= "\t\techo '</ul>';\n";
}
return 'class ' . $this->get_value( 'class_name' ) . ' extends WP_Widget {
public function __construct() {
parent::__construct(
\'' . $this->get_value( 'widget_id' ) . '\',
__( \'' . $this->get_value( 'widget_title' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
array(
\'description\' => __( \'' . $this->get_value( 'description' ) . '\', \'' . $this->get_value( 'text_domain' ) . '\' ),
\'classname\' => \'' . $this->get_value( 'css_class' ) . '\',
)
);
}
public function widget( $args, $instance ) {
$instance = wp_parse_args( (array) $instance, array(
' . $instance_defaults . ' ) );
// Before widget tag
echo $args[\'before_widget\'];
' . $widget_output . '
// After widget tag
echo $args[\'after_widget\'];
}
public function form( $instance ) {
// Set default values
$instance = wp_parse_args( (array) $instance, array(
' . $instance_defaults . ' ) );
' . $fields_markup . '
}
}
function ' . $this->get_value( 'prefix' ) . 'register_widgets() {
register_widget( \'' . $this->get_value( 'class_name' ) . '\' );
}
add_action( \'widgets_init\', \'' . $this->get_value( 'prefix' ) . 'register_widgets\' );
';
}
}