id = 'offices'; $this->label = __( 'Offices', 'propertyhive' ); add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 10 ); add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) ); add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) ); add_action( 'propertyhive_sections_' . $this->id, array( $this, 'output_sections' ) ); add_action( 'propertyhive_admin_field_offices', array( $this, 'offices_setting' ) ); } /** * Get settings array * * @return array */ public function get_settings() { return apply_filters( 'propertyhive_office_settings', array( array( 'title' => __( 'Offices', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'offices_options' ), array( 'type' => 'offices', ), array( 'type' => 'sectionend', 'id' => 'offices_options' ), )); } /** * Get add/edit office settings array * * @return array */ public function get_office_settings() { global $current_section; $current_id = empty( $_REQUEST['id'] ) ? '' : (int)$_REQUEST['id']; $args = array( array( 'title' => __( ( $current_section == 'add' ? 'Add New Office' : 'Edit Office Details' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'office_options' ), array( 'title' => __( 'Office Name', 'propertyhive' ), 'id' => 'office_name', //'css' => 'width:50px;', 'default' => get_the_title($current_id), 'type' => 'text', 'desc_tip' => false, ), array( 'title' => __( 'Address Line 1', 'propertyhive' ), 'id' => '_office_address_1', //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_address_1', TRUE), 'type' => 'text', 'desc_tip' => false, ), array( 'title' => __( 'Address Line 2', 'propertyhive' ), 'id' => '_office_address_2', //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_address_2', TRUE), 'type' => 'text', 'desc_tip' => false, ), array( 'title' => __( 'Address Line 3', 'propertyhive' ), 'id' => '_office_address_3', //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_address_3', TRUE), 'type' => 'text', 'desc_tip' => false, ), array( 'title' => __( 'Address Line 4', 'propertyhive' ), 'id' => '_office_address_4', //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_address_4', TRUE), 'type' => 'text', 'desc_tip' => false, ), array( 'title' => __( 'Postcode', 'propertyhive' ), 'id' => '_office_address_postcode', 'css' => 'width:85px;', 'default' => get_post_meta($current_id, '_office_address_postcode', TRUE), 'type' => 'text', 'desc_tip' => false, ), array( 'type' => 'sectionend', 'id' => 'office_options' ), array( 'title' => __( 'Contact Details', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'office_contact_options' ), ); $departments = ph_get_departments(); foreach ( $departments as $key => $value ) { if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' ) { $args[] = array( 'title' => sprintf( /* translators: %s: department (e.g. Sales, Lettings, Commercial) */ __( 'Telephone Number (%s)', 'propertyhive' ), $value ), 'id' => '_office_telephone_number_' . str_replace("residential-", "", $key), //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_telephone_number_' . str_replace("residential-", "", $key), TRUE), 'type' => 'text', 'desc_tip' => false, ); $args[] = array( 'title' => sprintf( /* translators: %s: department (e.g. Sales, Lettings, Commercial) */ __( 'Email Address (%s)', 'propertyhive' ), $value ), 'id' => '_office_email_address_' . str_replace("residential-", "", $key), //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_email_address_' . str_replace("residential-", "", $key), TRUE), 'type' => 'text', 'desc_tip' => false, ); } } $args[] = array( 'type' => 'sectionend', 'id' => 'office_contact_options' ); $args[] = array( 'title' => __( 'Office Location', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'office_location_options' ); $args[] = array( 'title' => __( 'Latitude', 'propertyhive' ), 'id' => '_office_latitude', //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_latitude', TRUE), 'type' => 'text', 'desc_tip' => false, ); $args[] = array( 'title' => __( 'Longitude', 'propertyhive' ), 'id' => '_office_longitude', //'css' => 'width:50px;', 'default' => get_post_meta($current_id, '_office_longitude', TRUE), 'type' => 'text', 'desc_tip' => false, ); $args[] = array( 'type' => 'sectionend', 'id' => 'office_location_options' ); return apply_filters( 'propertyhive_office_details_settings', $args ); } /** * Get delete office settings array * * @return array */ public function get_office_delete() { global $save_button_text, $post; $save_button_text = __( 'Delete', 'propertyhive' ); if ( isset($_POST['confirm_removal']) && $_POST['confirm_removal'] == 1 ) { // A term has just been deleted global $hide_save_button, $show_cancel_button, $cancel_button_href; $hide_save_button = TRUE; $show_cancel_button = TRUE; $cancel_button_href = admin_url( 'admin.php?page=ph-settings&tab=offices' ); $args = array(); $args[] = array( 'title' => __( 'Successfully Deleted Office', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'office_delete' ); $args[] = array( 'title' => __( 'Office Deleted', 'propertyhive' ), 'id' => '', 'html' => __('Office deleted successfully', 'propertyhive' ) . ' ' . __( 'Go Back', 'propertyhive' ) . '', 'type' => 'html', 'desc_tip' => false, ); $args[] = array( 'type' => 'sectionend', 'id' => 'office_delete' ); } else { $current_id = empty( $_REQUEST['id'] ) ? '' : (int)$_REQUEST['id']; if ($current_id == '') { die("ID not passed"); } else { $post_type = get_post_type( $current_id ); if ( $post_type == 'office' ) { $args = array(); $args[] = array( 'title' => __( 'Delete Office', 'propertyhive' ) . ': ' . get_the_title( $current_id ), 'type' => 'title', 'desc' => '', 'id' => 'office_delete_options' ); // Get number of properties assigned to this term $query_args = array( 'post_type' => 'property', 'nopaging' => true, 'post_status' => array( 'pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash' ), 'meta_query' => array( array( 'key' => '_office_id', 'value' => $current_id, 'compare' => '=' ) ) ); $property_query = new WP_Query( $query_args ); $num_properties = $property_query->found_posts; // Get number of applicants assigned to this term (future) if ($num_properties > 0) { $alternative_offices = array(); $query_args = array( 'post_type' => 'office', 'nopaging' => true, 'post__not_in' => array( $current_id ), 'orderby' => 'title', 'order' => 'ASC' ); $office_query = new WP_Query( $query_args ); if ( $office_query->have_posts() ) { while ( $office_query->have_posts() ) { $office_query->the_post(); $alternative_terms[$post->ID] = get_the_title(); } } // There are properties assigned to this term $args[] = array( 'title' => __( 'Re-assign to', 'propertyhive' ), 'id' => 'reassign_to', 'default' => '', 'options' => $alternative_terms, 'type' => 'select', 'desc_tip' => false, 'desc' => __( 'There are properties that are assigned to the office being deleted. Which office should they be reassigned to?' , 'propertyhive' ) ); } $args[] = array( 'title' => __( 'Confirm removal?', 'propertyhive' ), 'id' => 'confirm_removal', 'type' => 'checkbox', 'desc_tip' => false, ); $args[] = array( 'type' => 'sectionend', 'id' => 'office_delete_options' ); } else { die("Trying to delete a post that isn't an office."); } } } return apply_filters( 'propertyhive_office_delete_settings', $args ); } /** * Output the settings */ public function output() { global $current_section, $redirect_after_save; if ( $current_section == 'add' ) { remove_action('propertyhive_admin_field_offices', array( $this, 'offices_setting' )); $settings = $this->get_office_settings(); $redirect_after_save = admin_url('admin.php?page=ph-settings&tab=offices'); PH_Admin_Settings::output_fields( $settings ); } elseif ( $current_section == 'edit' ) { remove_action('propertyhive_admin_field_offices', array( $this, 'offices_setting' )); $current_id = empty( $_REQUEST['id'] ) ? '' : (int)$_REQUEST['id']; $settings = $this->get_office_settings(); $redirect_after_save = admin_url('admin.php?page=ph-settings&tab=offices'); PH_Admin_Settings::output_fields( $settings ); } elseif ( $current_section == 'delete' ) { remove_action('propertyhive_admin_field_offices', array( $this, 'offices_setting' )); $current_id = empty( $_REQUEST['id'] ) ? '' : (int)$_REQUEST['id']; $settings = $this->get_office_delete(); PH_Admin_Settings::output_fields( $settings ); } else { $settings = $this->get_settings(); PH_Admin_Settings::output_fields( $settings ); } } /** * Output list of offices * * @access public * @return void */ public function offices_setting() { global $post; ?>
| ID, 'primary', TRUE), '1', false ) . ' /> | ' . esc_html(get_the_title()) . ' | ' . esc_html($address) . ' | ' . $contact_details . ' | '; do_action( 'propertyhive_office_table_row_columns', get_the_ID() ); echo '' . esc_html(__( 'Edit', 'propertyhive' )) . ' '; if ( $num_offices > 1 && get_post_meta($post->ID, 'primary', TRUE) != '1' ) { echo '' . esc_html(__( 'Delete', 'propertyhive' )) . ''; } echo ' |