Plugin alla laadimine
Kuidas seadistada “Daily Tip” pluginat
1. Paigalda ja aktiveeri plugin
- Ava WordPress → Plugins → Lisa uus
- Kliki “Laadi plugin üles” ja vali fail
daily-tip-plugin.zip
- Aktiveeri plugin

2. Lisa mõned nõuanded
- Ava adminpaneelis uus menüü “Daily Tips”
- Kliki “Add New” ja sisesta pealkiri ning sisu

3. Muuda pealkiri seadetes
- Mine Settings → Daily Tip Settings

- Kirjuta pealkiri, mis kuvatakse enne nõuannet (nt. “💡 Päeva nõuanne”)

4. Kasuta lühikoodi
- Et näidata nõuannet, lisa lühikood ’daily_tip’ lehele või postitusse.

Lühikoodi kasutamine:
Päeva näpunäide
Как так вышло?
Я хз
Minu pugini kood:
<?php
/**
* Plugin Name: Daily Tip
* Description: Displays a random tip using the shortcode [daily_tip].
* Version: 1.1
* Author: Bogdan Viblyy
*/
if ( ! defined( 'ABSPATH' ) ) exit;
function dtp_register_daily_tip_post_type() {
register_post_type( 'daily_tip',
[
'labels' => [
'name' => 'Tips',
'singular_name' => 'Tip',
'add_new' => 'Add New Tip',
'add_new_item' => 'Add New Tip',
'edit_item' => 'Edit Tip',
'new_item' => 'New Tip',
'view_item' => 'View Tip',
'search_items' => 'Search Tips',
'not_found' => 'No tips found',
'not_found_in_trash' => 'No tips found in Trash',
'all_items' => 'All Tips',
'menu_name' => 'Daily Tips',
'name_admin_bar' => 'Tip',
],
'public' => true,
'has_archive' => false,
'show_in_rest' => true,
'supports' => ['title', 'editor'],
'menu_icon' => 'dashicons-lightbulb',
]
);
}
add_action( 'init', 'dtp_register_daily_tip_post_type' );
function dtp_add_settings_page() {
add_options_page(
'Daily Tip Settings',
'Daily Tip Settings',
'manage_options',
'daily-tip-settings',
'dtp_render_settings_page'
);
}
add_action( 'admin_menu', 'dtp_add_settings_page' );
function dtp_register_settings() {
register_setting( 'dtp_settings_group', 'dtp_tip_title' );
}
add_action( 'admin_init', 'dtp_register_settings' );
function dtp_render_settings_page() {
?>
<div class="wrap">
<h1>Daily Tip Settings</h1>
<form method="post" action="options.php">
<?php settings_fields( 'dtp_settings_group' ); ?>
<?php do_settings_sections( 'dtp_settings_group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Tip Section Title</th>
<td>
<input type="text" name="dtp_tip_title" value="<?php echo esc_attr( get_option('dtp_tip_title', '💡 Tip of the Day') ); ?>" style="width: 300px;" />
<p class="description">This title will appear above the random tip.</p>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
function dtp_random_tip_shortcode() {
$args = [
'post_type' => 'daily_tip',
'posts_per_page' => 1,
'orderby' => 'rand',
];
$tip_query = new WP_Query( $args );
if ( $tip_query->have_posts() ) {
ob_start();
$custom_title = get_option('dtp_tip_title', '💡 Tip of the Day');
echo '<div class="daily-tip">';
echo '<h3>' . esc_html($custom_title) . '</h3>';
while ( $tip_query->have_posts() ) {
$tip_query->the_post();
echo '<strong>' . get_the_title() . '</strong>';
echo '<p>' . get_the_content() . '</p>';
}
echo '</div>';
wp_reset_postdata();
return ob_get_clean();
} else {
return '<p>No tips available.</p>';
}
}
add_shortcode( 'daily_tip', 'dtp_random_tip_shortcode' );