DAILY TASK
/**
- Plugin Name: Daily Tasks
- Description: Set daily tasks for each day of the week and display them via shortcode.
- Version: 1.0
- Author: Marcin K
*/
// Hook to add settings page
add_action(‘admin_menu’, ‘dt_add_settings_page’);
function dt_add_settings_page() {
add_options_page(
‘Daily Tasks Settings’,
‘Daily Tasks’,
‘manage_options’,
‘daily-tasks’,
‘dt_render_settings_page’
);
// Register settings
add_action(‘admin_init’, ‘dt_register_settings’);
function dt_register_settings() {
register_setting(‘dt_settings_group’, ‘dt_tasks’);
}
// Render settings page
function dt_render_settings_page() {
$days = [‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Sunday’];
$tasks = get_option(‘dt_tasks’, []);
?>
Daily Tasks Settings
<?php echo esc_textarea($tasks[$day] ?? ”); ?> Comma-separated list of tasks for . |
<?php
}
// Shortcode to display todayβs tasks
add_shortcode(‘daily_tasks’, ‘dt_display_tasks_for_today’);
function dt_display_tasks_for_today() {
$tasks = get_option(‘dt_tasks’, []);
$today = date(‘l’); // Monday, Tuesday, etc.
if (!isset($tasks[$today]) || empty($tasks[$today])) {
return "<p>No tasks set for today ($today).</p>";
}
$task_list = array_map('trim', explode(',', $tasks[$today]));
$output = "<h3>Tasks for $today</h3><ul>";
foreach ($task_list as $task) {
$output .= "<li>" . esc_html($task) . "</li>";
}
$output .= "</ul>";
return $output;
}
HEADER DATE
<?php
/**
- Plugin Name: Show Header Date
- Description: JUst show date
- Version: 0.1
- Author: MK
*/
add_action(‘wp_body_open’, ‘show_date_in_header’);
function show_date_in_header() {
echo ‘
π Today is ‘ . current_time(‘l, F j, Y’) . ‘ ‘;
}
TESTIMONIAL MANAGER
ID, ‘_client_name’, true); $client_company = get_post_meta($post->ID, ‘_client_company’, true); ?>
<p>
<label for="client_name">Client Name:</label><br>
<input type="text" name="client_name" id="client_name" value="<?php echo esc_attr($client_name); ?>" style="width:100%;">
</p>
<p>
<label for="client_company">Client Company:</label><br>
<input type="text" name="client_company" id="client_company" value="<?php echo esc_attr($client_company); ?>" style="width:100%;">
</p>
<?php
}
add_action(‘save_post’, ‘tm_save_testimonial_meta’);
function tm_save_testimonial_meta($post_id) {
// Security checks
if (!isset($_POST[‘tm_testimonial_nonce’]) ||
!wp_verify_nonce($_POST[‘tm_testimonial_nonce’], basename(FILE))) {
return $post_id;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
if ('testimonial' !== $_POST['post_type'] || !current_user_can('edit_post', $post_id)) {
return $post_id;
}
// Save fields
$client_name = sanitize_text_field($_POST['client_name'] ?? '');
$client_company = sanitize_text_field($_POST['client_company'] ?? '');
update_post_meta($post_id, '_client_name', $client_name);
update_post_meta($post_id, '_client_company', $client_company);
}
function tm_custom_post_testimonial() {
// Set the labels. This variable is used in the $args array
$labels = array(
‘name’ => ( ‘Custom Testimonials’ ), ‘singular_name’ => ( ‘Custom Testimonial’ ),
‘add_new’ => ( ‘Add Custom Testimonial’ ), ‘add_new_item’ => ( ‘Add Custom Testimonial’ ),
‘edit_item’ => ( ‘Edit Custom Testimonial’ ), ‘new_item’ => ( ‘New Custom Testimonial’ ),
‘all_items’ => ( ‘All Custom Testimonials’ ), ‘view_item’ => ( ‘View Custom Testimonial’ ),
‘search_items’ => __( ‘Search Custom Testimonial’ ),
‘featured_image’ => ‘Poster’,
‘set_featured_image’ => ‘Add Poster’
);
$args = array(
‘labels’ => $labels,
‘description’ => ‘Holds our custom testimonials post specific data’,
‘public’ => true,
‘menu_position’ => 5,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘excerpt’, ‘comments’, ‘custom-fields’ ),
‘has_archive’ => true,
‘show_in_admin_bar’ => true,
‘show_in_nav_menus’ => true,
‘query_var’ => true,
);
register_post_type(‘testimonial’, $args);
}
add_shortcode(‘latest_testimonials’, ‘tm_display_latest_testimonials’);
function tm_display_latest_testimonials($atts) {
// Query the latest 5 testimonials
$args = array(
‘post_type’ => ‘testimonial’,
‘posts_per_page’ => 5,
‘post_status’ => ‘publish’,
);
$testimonials = new WP_Query($args);
if (!$testimonials->have_posts()) {
return '<p>No testimonials found.</p>';
}
$output = '<div class="tm-testimonials">';
while ($testimonials->have_posts()) {
$testimonials->the_post();
$client_name = get_post_meta(get_the_ID(), '_client_name', true);
$client_company = get_post_meta(get_the_ID(), '_client_company', true);
$output .= '<blockquote style="margin-bottom:20px;">';
$output .= '<p style="font-style:italic;">β' . get_the_content() . 'β</p>';
$output .= '<footer style="margin-top:10px;">β ' . esc_html($client_name);
if (!empty($client_company)) {
$output .= ', ' . esc_html($client_company);
}
$output .= '</footer>';
$output .= '</blockquote>';
}
$output .= '</div>';
wp_reset_postdata();
return $output;
}
HOW USE FILTER
add_filter()
allows you to modify data before itβs used β titles, content, options, markup, emails, etc.
add_filter( ‘some_hook’, ‘your_callback’ );
add_filter( $hook_name, $callback, $priority, $accepted_args );
$hook_name
β string name of the filter (like the_content
, excerpt_length
)
$callback
β your function name
$priority
β order to run (lower = earlier). Default: 10
$accepted_args
β how many arguments your function accepts. Default: 1
function my_custom_site_title( $title ) {
return ‘π ‘ . $title;
}
add_filter( ‘wp_title’, ‘my_custom_site_title’ );
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 20 );
function custom_excerpt_length( $length ) {
return 30;
}
β Here’s What You Do Need to Know
π§ Core Concepts
These are must-know:
- Plugin structure
- Header comment block
functions.php
vs plugin code- Hook system (
add_action()
,add_filter()
)
- Hooks
- How to use
add_action()
andadd_filter()
- Know a few key hooks:
init
admin_menu
wp_enqueue_scripts
save_post
wp_footer
,wp_body_open
- How to use
- Shortcodes
add_shortcode()
return
vsecho
(like we discussed earlier)
- Custom post types (CPTs)
register_post_type()
register_taxonomy()
(optional but nice)
- Custom fields / Meta boxes
add_meta_box()
get_post_meta()
,update_post_meta()
wp_nonce_field()
+ security checks
- Settings API (basic)
register_setting()
settings_fields()
,get_option()
,update_option()