Skip to content

Commit

Permalink
#1516 Enhacement : default content tab in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
RHSRSK committed Sep 30, 2024
1 parent 5ea606c commit 7783cbe
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 28 deletions.
25 changes: 16 additions & 9 deletions admin/wp-event-manager-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,34 +480,41 @@ protected function init_settings() {
array(
'name' => 'event_manager_timezone_setting',
'std' => 'site_timezone',
'label' => __('Event Timezone', 'wp-event-manager'),
'desc' => __('In case while submitting an event, if the timezone for each event is not selected, the WP Event Manager will take the default WordPress (website) timezone.', 'wp-event-manager'),
'label' => __( 'Event Timezone', 'wp-event-manager' ),
'desc' => __( 'In case while submitting an event, if the timezone for each event is not selected, the WP Event Manager will take the default WordPress (website) timezone.', 'wp-event-manager' ),
'type' => 'radio',
'options' => array(
'site_timezone' => __('Use website timezone.', 'wp-event-manager'),
'each_event' => __('Select a timezone on each event.', 'wp-event-manager'),
'site_timezone' => __( 'Use website timezone.', 'wp-event-manager' ),
'each_event' => __( 'Select a timezone on each event.', 'wp-event-manager' ),
),
),
),
),
'event_default_content' => array(
__('Default Content', 'wp-event-manager'),
__( 'Default Content', 'wp-event-manager' ),
array(
array(
'name' => 'default_organizer',
'std' => 'no_default',
'label' => __('Default Organizer', 'wp-event-manager'),
'label' => __( 'Default Organizer', 'wp-event-manager' ),
'type' => 'select',
'options' => $organizer_options,
'desc' => __('The current default organizer is: No default set', 'wp-event-manager'),
'desc' => __( 'You can choose default organizer from here.', 'wp-event-manager' ),
),
array(
'name' => 'default_venue',
'std' => 'no_default',
'label' => __('Default Venue', 'wp-event-manager'),
'label' => __( 'Default Venue', 'wp-event-manager' ),
'type' => 'select',
'options' => $venue_options,
'desc' => __('The current default venue is: No default set', 'wp-event-manager'),
'desc' => __( 'You can choose default venue from here.', 'wp-event-manager' ),
),
array(
'name' => 'default_address',
'std' => '',
'label' => __( 'Default Address', 'wp-event-manager' ),
'type' => 'text',
'desc' => __( 'You can set the default address from here.', 'wp-event-manager' ),
),
),
),
Expand Down
43 changes: 32 additions & 11 deletions admin/wp-event-manager-writepanels.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,28 +407,41 @@ public static function input_file($key, $field) {
* @param mixed $key
* @param mixed $field
*/
public static function input_text($key, $field) {
public static function input_text($key, $field) {
global $post_id;
if(!isset($field['value']) || empty($field['value'])) {
$field['value'] = esc_attr(get_post_meta($post_id, stripslashes($key), true));

// Get the default address from options
$default_address = get_option('default_address');

// Set the field value: prioritize post meta value, then default address, then empty
if (!isset($field['value']) || empty($field['value'])) {
$field['value'] = esc_attr(get_post_meta($post_id, stripslashes($key), true)) ?: esc_attr($default_address);
}
if(!empty($field['name'])) {

// Determine the name for the input field
if (!empty($field['name'])) {
$name = $field['name'];
} else {
$name = $key;
} ?>

}
?>

<p class="form-field">
<label for="<?php echo esc_attr($key); ?>"><?php _e(esc_attr($field['label']), 'wp-event-manager');?>:
<?php
if(!empty($field['description'])) : ?>
<label for="<?php echo esc_attr($key); ?>">
<?php _e(esc_attr($field['label']), 'wp-event-manager');?>:
<?php if (!empty($field['description'])) : ?>
<span class="tips" data-tip="<?php _e(esc_attr($field['description']), 'wp-event-manager');?>">[?]</span>
<?php endif; ?>
</label>
<input type="text" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($key); ?>" placeholder="<?php _e(esc_attr($field['placeholder']), 'wp-event-manager'); ?>" value="<?php echo esc_attr($field['value']); ?>" />
<input type="text"
name="<?php echo esc_attr($name); ?>"
id="<?php echo esc_attr($key); ?>"
placeholder="<?php _e(esc_attr($field['placeholder']), 'wp-event-manager'); ?>"
value="<?php echo esc_attr($field['value']); ?>" />
</p>
<?php
<?php
}


/**
* Manage of wp_editor.
Expand Down Expand Up @@ -669,8 +682,13 @@ public static function input_textarea($key, $field) {
*/
public static function input_select($key, $field) {
global $post_id;
$default_venue = get_option( 'default_venue' );
if(!isset($field['value']) || empty($field['value'])) {
$field['value'] = esc_attr(get_post_meta($post_id, stripslashes($key), true));
// If the meta value is still empty, use the default venue
if (empty($field['value']) && !empty($default_venue)) {
$field['value'] = $default_venue;
}
}
if(!empty($field['name'])) {
$name = $field['name'];
Expand Down Expand Up @@ -707,6 +725,7 @@ public static function input_select($key, $field) {
*/
public static function input_multiselect($key, $field) {
global $post_id;
$default_organizer = get_option('default_organizer');
if(!isset($field['value']) || empty($field['value'])) {
$field['value'] = get_post_meta($post_id, stripslashes($key), true);
}
Expand All @@ -726,6 +745,8 @@ public static function input_multiselect($key, $field) {
<option value="<?php echo esc_attr($key); ?>" <?php
if(!empty($field['value']) && is_array($field['value'])) {
selected(in_array($key, $field['value']), true);
}elseif ($key == $default_organizer) {
echo 'selected="selected"';
}
?>><?php echo esc_html($value); ?></option>
<?php endforeach; ?>
Expand Down
17 changes: 14 additions & 3 deletions forms/wp-event-manager-form-submit-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ public function get_default_event_fields( ) {

$organizer_description = is_admin() ? __('<div class="wpem-alert wpem-mt-2 wpem-mb-0 wpem-p-0">If it doesn\'t show organizer(s). Manage your organizer(s) from <a href="post-new.php?post_type=event_organizer" target="_blank" class="wpem_add_organizer_popup wpem-modal-button" data-modal-id="wpem_add_organizer_popup">here</a></div>','wp-event-manager') : __('<div class="wpem-alert wpem-mt-2 wpem-mb-0 wpem-p-0">If it doesn\'t show organizer(s). Manage your organizer(s) from <a href="#" onclick="javascript:void(0);" class="wpem_add_organizer_popup wpem-modal-button" data-modal-id="wpem_add_organizer_popup">here</a></div>','wp-event-manager');
$venue_description = is_admin() ? __('<div class="wpem-alert wpem-mt-2 wpem-mb-0 wpem-p-0">If it doesn\'t show venue(s). Manage your venue(s) from <a href="post-new.php?post_type=event_venue" target="_blank" class="wpem_add_venue_popup wpem-modal-button" data-modal-id="wpem_add_venue_popup">here</a></div>','wp-event-manager') : __('<div class="wpem-alert wpem-mt-2 wpem-mb-0 wpem-p-0">If it doesn\'t show venue(s). Manage your venue(s) from <a href="#" onclick="javascript:void(0);" class="wpem_add_venue_popup wpem-modal-button" data-modal-id="wpem_add_venue_popup">here</a></div>','wp-event-manager');


// Get default organizer
$default_organizer = get_option('default_organizer');
$default_organizer = is_array($default_organizer) ? $default_organizer : array($default_organizer);

// Get default venue
$default_venue = get_option('default_venue');

// Get default address
$default_address = get_option('default_address');

return apply_filters( 'submit_event_form_fields', array(
'event' => array(
'event_title' => array(
Expand Down Expand Up @@ -208,6 +218,7 @@ public function get_default_event_fields( ) {
'event_location' => array(
'label' => __( 'Event Location', 'wp-event-manager' ),
'type' => 'text',
'default' => $default_address,
'required' => true,
'placeholder' => __( 'Location for google map', 'wp-event-manager' ),
'priority' => 6,
Expand Down Expand Up @@ -351,7 +362,7 @@ public function get_default_event_fields( ) {
'event_organizer_ids' => array(
'label' => __( 'Organizer', 'wp-event-manager' ),
'type' => 'multiselect',
'default' => '',
'default' => $default_organizer,
'options' =>apply_filters('wpem_set_organizer_ids', ($current_user_id) ? get_all_organizer_array($current_user_id) : []),
'description' => $organizer_description,
'priority' => 20,
Expand All @@ -364,7 +375,7 @@ public function get_default_event_fields( ) {
'event_venue_ids' => array(
'label' => __( 'Venues', 'wp-event-manager' ),
'type' => 'select',
'default' => '',
'default' => $default_venue,
'options' => apply_filters('wpem_set_venue_ids', ($current_user_id) ? get_all_venue_array($current_user_id, '', true) : ['' => __( 'Select Venue', 'wp-event-manager')]),
'description' => $venue_description,
'priority' => 21,
Expand Down
12 changes: 9 additions & 3 deletions templates/form-fields/multiselect-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
wp_enqueue_style( 'chosen', EVENT_MANAGER_PLUGIN_URL . '/assets/css/chosen.css' ); ?>

<select multiple="multiple" name="<?php echo esc_attr(isset($field['name']) ? $field['name'] : $key); ?>[]" id="<?php echo esc_attr($key); ?>" class="event-manager-multiselect" data-no_results_text="<?php esc_attr_e('No results match', 'wp-event-manager'); ?>" attribute="<?php echo esc_attr(isset($field['attribute']) ? $field['attribute'] : ''); ?>" data-multiple_text="<?php esc_attr_e('Select Some Options', 'wp-event-manager'); ?>">
<?php foreach ($field['options'] as $key => $value) : ?>
<option value="<?php echo esc_attr($key); ?>" <?php if (!empty($field['value']) && is_array($field['value'])) selected(in_array($key, $field['value']), true); ?>><?php echo esc_html($value); ?></option>
<?php endforeach; ?>
<?php
// Get the default value (array of default organizers)
$default_value = isset($field['default']) ? (array)$field['default'] : []; // Ensure it's an array

foreach ($field['options'] as $option_key => $option_value) : ?>
<option value="<?php echo esc_attr($option_key); ?>" <?php echo in_array($option_key, $default_value) || (!empty($field['value']) && is_array($field['value']) && in_array($option_key, $field['value'])) ? 'selected' : ''; ?>>
<?php echo esc_html($option_value); ?>
</option>
<?php endforeach; ?>
</select>

<?php if (!empty($field['description'])) : ?>
Expand Down
15 changes: 13 additions & 2 deletions templates/form-fields/text-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@
* @version 1.8
*/
?>
<input type="text" class="input-text <?php echo esc_attr(isset($field['class']) ? $field['class'] : $key); ?>" name="<?php echo esc_attr(isset($field['name']) ? $field['name'] : $key); ?>" id="<?php echo isset($field['id']) ? esc_attr($field['id']) : esc_attr($key); ?>" placeholder="<?php echo empty($field['placeholder']) ? '' : __ (esc_attr($field['placeholder']), 'wp-event-manager'); ?>" attribute="<?php echo esc_attr(isset($field['attribute']) ? $field['attribute'] : ''); ?>" value="<?php echo isset($field['value']) ? esc_attr($field['value']) : ''; ?>" maxlength="<?php echo !empty($field['maxlength']) ? esc_attr($field['maxlength']) : ''; ?>" <?php if (!empty($field['required'])) echo esc_attr('required'); ?> <?php if (isset($field['disabled']) && !empty($field['disabled'])) echo esc_attr('disabled'); ?> />
<input type="text"
class="input-text <?php echo esc_attr(isset($field['class']) ? $field['class'] : $key); ?>"
name="<?php echo esc_attr(isset($field['name']) ? $field['name'] : $key); ?>"
id="<?php echo isset($field['id']) ? esc_attr($field['id']) : esc_attr($key); ?>"
placeholder="<?php echo empty($field['placeholder']) ? '' : __ (esc_attr($field['placeholder']), 'wp-event-manager'); ?>"
attribute="<?php echo esc_attr(isset($field['attribute']) ? $field['attribute'] : ''); ?>"
value="<?php echo esc_attr(isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '')); ?>"
maxlength="<?php echo !empty($field['maxlength']) ? esc_attr($field['maxlength']) : ''; ?>"
<?php if (!empty($field['required'])) echo esc_attr('required'); ?>
<?php if (isset($field['disabled']) && !empty($field['disabled'])) echo esc_attr('disabled'); ?>
/>

<?php if (!empty($field['description'])) : ?>
<small class="description">
<?php echo wp_kses_post($field['description']); ?>
</small>
<?php endif; ?>
<?php endif; ?>

0 comments on commit 7783cbe

Please sign in to comment.