Added: Clean Up settings

This commit is contained in:
Hoang Huu
2020-06-04 14:13:29 +07:00
parent c6a75c3b49
commit 13bc6c7ea1
13 changed files with 386 additions and 199 deletions

View File

@@ -353,75 +353,6 @@ function opalestate_hook_callback( $args ) {
do_action( 'opalestate_' . $args['id'] );
}
register_activation_hook( __FILE__, 'opalestate_active_cron_jobs' );
function opalestate_active_cron_jobs() {
if ( ! wp_next_scheduled( 'opalestate_cleanup' ) ) {
wp_schedule_event( time(), 'daily', 'opalestate_cleanup' );
}
}
register_deactivation_hook( __FILE__, 'opalestate_deactive_cron_jobs' );
function opalestate_deactive_cron_jobs() {
wp_clear_scheduled_hook( 'opalestate_cleanup' );
}
function opalestate_cleanup() {
$query = new WP_Query(
[
'post_type' => 'attachment',
'post_status' => 'inherit',
'date_query' => [
'column' => 'post_date',
'before' => date( 'Y-m-d', strtotime( '-1 days' ) ),
],
'meta_query' => [
[
'key' => '_pending_to_use_',
'value' => 1,
'compare' => '>=',
],
],
]
);
// clean up per day
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
wp_delete_attachment( get_the_ID() );
}
}
wp_reset_postdata();
// Change status expired properties.
$expired_query = new WP_Query( [
'post_type' => 'opalestate_property',
'post_status' => [ 'pending', 'publish' ],
'meta_query' => [
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'expired_time',
'value' => time(),
'compare' => '>=',
'type' => 'NUMERIC',
],
],
] );
if ( $expired_query->have_posts() ) {
while ( $expired_query->have_posts() ) {
$expired_query->the_post();
wp_update_post( [
'ID' => get_the_ID(),
'post_status' => 'expired',
] );
}
}
wp_reset_postdata();
}
/**
* Searches for users via ajax and returns a list of results
*

View File

@@ -25,6 +25,8 @@ class Opalestate_Admin_Property {
// add_action( 'transition_post_status', array( __CLASS__, 'save_post' ), 10, 3 );
add_action( 'parse_query', [ $this, 'search_custom_fields' ] );
add_filter( 'display_post_states', [ $this, 'display_post_states' ], 10, 2 );
}
/**
@@ -183,6 +185,20 @@ class Opalestate_Admin_Property {
$wp->query_vars['post__in'] = array_merge( $post_ids, [ 0 ] );
}
}
/**
* Filters the default post display states used in the posts list table.
*
* @param string[] $post_states An array of post display states.
* @param WP_Post $post The current post object.
*/
public function display_post_states( $post_states, $post ) {
if ( 'expired' == $post->post_status ) {
$post_states['expired'] = _x( 'Expired', 'post status', 'opalestate-pro' );
}
return $post_states;
}
}
new Opalestate_Admin_Property();

View File

@@ -37,7 +37,7 @@ class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
'name' => esc_html__( 'General Settings', 'opalestate-pro' ),
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_1',
'id' => 'opalestate_title_general_settings',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
@@ -62,37 +62,12 @@ class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
],
],
[
'name' => esc_html__( 'Maximum Upload Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximum volumn size having < x MB', 'opalestate-pro' ),
'id' => 'upload_image_max_size',
'type' => 'text',
'default' => '0.5',
],
[
'name' => esc_html__( 'Maximum Upload Image Files', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximum volumn size having < x MB', 'opalestate-pro' ),
'id' => 'upload_image_max_files',
'type' => 'text',
'default' => '10',
],
[
'name' => esc_html__( 'Maximum Upload Other Size', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximum volumn size having < x MB for upload docx, pdf...', 'opalestate-pro' ),
'id' => 'upload_other_max_size',
'type' => 'text',
'default' => '0.8',
],
[
'name' => esc_html__( 'Maximum Upload Other Files', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximum volumn size having < x MB for upload docx, pdf...', 'opalestate-pro' ),
'id' => 'upload_other_max_files',
'type' => 'text',
'default' => '10',
'after_row' => '<hr>',
'name' => esc_html__( 'Image Settings', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_image_settings',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Agent Image Size', 'opalestate-pro' ),
@@ -115,8 +90,6 @@ class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
'options' => opalestate_get_featured_image_sizes(),
],
[
'name' => esc_html__( 'Loop Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'The Loop Image is an image that is chosen as the representative image in grid and list.', 'opalestate-pro' ),
@@ -126,8 +99,6 @@ class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
'default' => 'large',
'options' => opalestate_get_featured_image_sizes(),
],
[
'name' => esc_html__( 'Featured Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'The Featured Image is an image that is chosen as the representative image in single page. .', 'opalestate-pro' ),
@@ -138,46 +109,18 @@ class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
'after_row' => '<em>' . __( 'To generate images with new image sizes, you can use this <a href="https://goo.gl/FuXFex" target="_blank">Force Regenerate Thumbnails</a>',
'opalestate-pro' ) . '</em>',
],
[
'name' => esc_html__( 'Minimum of Target Price For Agent', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter minimum of price for starting search agent by target', 'opalestate-pro' ),
'id' => 'search_agent_min_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 0,
],
[
'name' => esc_html__( 'Maximum of Target Price For Agent', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter maximum of price for starting search agent by target', 'opalestate-pro' ),
'id' => 'search_agent_max_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 1000000,
],
[
'name' => esc_html__( 'Single Layout Page', 'opalestate-pro' ),
'desc' => esc_html__( 'Choose layout for single property.', 'opalestate-pro' ),
'id' => 'layout',
'type' => 'select',
'options' => apply_filters( 'opalestate_single_layout_templates', [ '' => esc_html__( 'Inherit', 'opalestate-pro' ) ] ),
],
[
'name' => esc_html__( 'Currency Settings', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_2',
'id' => 'opalestate_title_currency_settings',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Currency', 'opalestate-pro' ),
'desc' => 'Choose your currency. Note that some payment gateways have currency restrictions.',
'desc' => esc_html__( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'opalestate-pro' ),
'id' => 'currency',
'type' => 'select',
'options' => opalestate_get_currencies(),
@@ -234,6 +177,51 @@ class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
'options' => opalestate_get_time_formats(),
'default' => '12_hour',
],
[
'name' => esc_html__( 'Others', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_others_settings',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Minimum of Target Price For Agent', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter minimum of price for starting search agent by target', 'opalestate-pro' ),
'id' => 'search_agent_min_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 0,
],
[
'name' => esc_html__( 'Maximum of Target Price For Agent', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter maximum of price for starting search agent by target', 'opalestate-pro' ),
'id' => 'search_agent_max_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 1000000,
],
[
'name' => esc_html__( 'Advanced', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_advanced_settings',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Clean Up Interval', 'opalestate-pro' ),
'desc' => esc_html__( 'Set a schedule to automatically clean up expired properties and attachments.', 'opalestate-pro' ),
'id' => 'schedule',
'type' => 'select',
'options' => opalestate_get_schedule_interval_options(),
'default' => 0,
],
]
);
}

View File

@@ -238,12 +238,11 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
];
$fields[] = [
'name' => esc_html__( 'Horizontal Search Fields', 'opalestate-pro' ),
'desc' => esc_html__( 'Disable or enable fields appearing in search form', 'opalestate-pro' ),
'name' => esc_html__( 'Search Fields', 'opalestate-pro' ),
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_1',
'id' => 'opalestate_title_search_fields',
'before_row' => '<hr>',
'after_row' => '<hr>',
'after_row' => '<em>' . __( 'Enable/Disable fields appearing in search properties form.', 'opalestate-pro' ) . '</em><hr>',
];
$fields[] = [
@@ -280,12 +279,11 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
}
$fields[] = [
'name' => esc_html__( 'Setting type fields search', 'opalestate-pro' ),
'desc' => esc_html__( 'Setting type fields search', 'opalestate-pro' ) . '<hr>',
'name' => esc_html__( 'Search Fields type', 'opalestate-pro' ),
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_type_search',
'before_row' => '<hr>',
'after_row' => '<hr>',
'after_row' => '<em>' . __( 'Input type for search fields.', 'opalestate-pro' ) . '</em>',
];
$metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
@@ -367,6 +365,14 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
private function get_subtab_detail_fields() {
$fields = [];
$fields[] = [
'name' => esc_html__( 'Single Layout Page', 'opalestate-pro' ),
'desc' => esc_html__( 'Choose layout for single property.', 'opalestate-pro' ),
'id' => 'layout',
'type' => 'select',
'options' => apply_filters( 'opalestate_single_layout_templates', [ '' => esc_html__( 'Inherit', 'opalestate-pro' ) ] ),
];
$fields[] = [
'name' => esc_html__( 'Enable Request Viewing', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Request Viewing feature in the single property page.', 'opalestate-pro' ),