function create_custom_post_type() {
$labels = array(
'name' => __( 'Events' ),
'singular_name' => __( 'Event' ),
'add_new' => __( 'Add New Event' ),
'add_new_item' => __( 'Add New Event' ),
'edit_item' => __( 'Edit Event' ),
'new_item' => __( 'New Event' ),
'all_items' => __( 'All Events' ),
'view_item' => __( 'View Event' ),
'search_items' => __( 'Search Events' ),
'not_found' => __( 'No events found' ),
'not_found_in_trash' => __( 'No events found in Trash' ),
'menu_name' => __( 'Events' )
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' ),
'rewrite' => array( 'slug' => 'events' ),
);
register_post_type( 'event', $args );
}
add_action( 'init', 'create_custom_post_type' );function enqueue_plugin_scripts() {
wp_enqueue_script( 'my-plugin-ajax', plugin_dir_url( __FILE__ ) . 'js/plugin-ajax.js', array('jquery'), null, true );
wp_localize_script( 'my-plugin-ajax', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
add_action( 'wp_enqueue_scripts', 'enqueue_plugin_scripts' );jQuery(document).ready(function ($) {
$("#my-button").on("click", function () {
$.ajax({
url: ajax_object.ajax_url,
type: "POST",
data: {
action: "my_ajax_action",
data: "test",
},
success: function (response) {
alert("Response: " + response);
},
});
});
});function display_events_shortcode() {
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
);
$events = new WP_Query( $args );
$output = '<ul>';
if ( $events->have_posts() ) {
while ( $events->have_posts() ) {
$events->the_post();
$output .= '<li>' . get_the_title() . ' - ' . get_the_date() . '</li>';
}
} else {
$output .= '<li>No events found.</li>';
}
$output .= '</ul>';
wp_reset_postdata();
return $output;
}
add_shortcode( 'events_list', 'display_events_shortcode' );<?php get_header(); ?>
<div class="event-content">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?>
<h1><?php the_title(); ?></h1>
<div class="event-meta">
<p>Date: <?php echo get_post_meta( get_the_ID(), 'event_date', true ); ?></p>
<p>Location: <?php echo get_post_meta( get_the_ID(), 'event_location', true ); ?></p>
</div>
<div class="event-description">
<?php the_content(); ?>
</div>
<?php
endwhile;
endif;
?>
</div>
<?php get_footer(); ?>module: {
rules: [
// ...existing rules
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
],
},
],
},import "./styles/main.scss";function create_event_taxonomies() {
$labels = array(
'name' => __( 'Event Types' ),
'singular_name' => __( 'Event Type' ),
'search_items' => __( 'Search Event Types' ),
'all_items' => __( 'All Event Types' ),
'parent_item' => __( 'Parent Event Type' ),
'parent_item_colon' => __( 'Parent Event Type:' ),
'edit_item' => __( 'Edit Event Type' ),
'update_item' => __( 'Update Event Type' ),
'add_new_item' => __( 'Add New Event Type' ),
'new_item_name' => __( 'New Event Type Name' ),
'menu_name' => __( 'Event Types' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'event-type' ),
);
register_taxonomy( 'event_type', array( 'event' ), $args );
}
add_action( 'init', 'create_event_taxonomies', 0 );function my_plugin_menu() {
add_menu_page( 'Events Management', 'Events', 'manage_options', 'events', 'events_page', 'dashicons-calendar', 6 );
}
add_action( 'admin_menu', 'my_plugin_menu' );function events_page() {
echo '<div class="wrap"><h1>Events Management</h1>';
// Add settings forms or data display here.
echo '</div>';
}function my_plugin_settings() {
register_setting( 'my-plugin-settings-group', 'my_option_name' );
}
add_action( 'admin_init', 'my_plugin_settings' );function events_page() {
?>
<div class="wrap">
<h1>Events Management</h1>
<form method="post" action="options.php">
<?php settings_fields( 'my-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Option Name</th>
<td><input type="text" name="my_option_name" value="<?php echo esc_attr( get_option('my_option_name') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}function my_ajax_action() {
$data = $_POST['data'];
// Process data here.
echo 'Received: ' . $data;
wp_die(); // All AJAX handlers should die when finished.
}
add_action( 'wp_ajax_my_ajax_action', 'my_ajax_action' );
add_action( 'wp_ajax_nopriv_my_ajax_action', 'my_ajax_action' );import $ from "jquery";
$(document).ready(function () {
$("#my-button").on("click", function () {
$.ajax({
url: ajax_object.ajax_url,
type: "POST",
data: {
action: "my_ajax_action",
data: "test",
},
success: function (response) {
alert("Response: " + response);
},
});
});
});npm install --save-dev node-sass$response = wp_remote_get( 'https://api.eventbriteapi.com/v3/events/search/?token=YOUR_API_TOKEN' );
if ( is_array( $response ) && ! is_wp_error( $response ) ) {
$body = $response['body']; // use the content
$data = json_decode( $body );
}