php 在app_my_appointments短代码中显示其他字段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在app_my_appointments短代码中显示其他字段相关的知识,希望对你有一定的参考价值。
<?php
/**
* Plugin Name: Appointment display additional fields
* Plugin URI: https://premium.wpmudev.org/
* Description: Display additional fields in app_my_appointments shortcode
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'AppoinementDisplayAdditionalFields' ) ) {
class AppoinementDisplayAdditionalFields {
private static $_instance = null;
public static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new AppoinementDisplayAdditionalFields();
}
return self::$_instance;
}
private function __construct() {
if ( !function_exists('appointments_get_app_additional_fields') ) return;
// Add Additional Column after date column
add_filter('app_my_appointments_column_name', array( $this, 'app_my_appointments_column_name' ), 10, 1);
// Add Additional Column Value after date column
add_filter('app-shortcode-my_appointments-after_date', array( $this, 'app_shortcode_my_appointments_after_date' ), 10, 2);
}
public function app_my_appointments_column_name( $rows ) {
// Create Array of old row headings
$rows = array_map( function($row) {
return $row . '</th>';
}, array_filter( explode( '</th>', $rows )));
// Move "Status" row from position 3 to 4
$rows[4] = $rows[3];
// Assign New row on position 3 before "Status" row
$rows[3] = '<th class="my-appointments-custom-field">'. __( 'My Field Title', 'appointments' ).'</th>'; // Change the "My Field Title" as you need.
// Return all the rows as string including new rows.
return implode('', $rows);
}
public function app_shortcode_my_appointments_after_date( $row, $r ) {
global $appointments;
// Get the additional fields as array
$additional_fields = appointments_get_app_additional_fields( $r->ID );
// Check the additional field is exist and generate the row
if ( $additional_fields && isset($additional_fields['cufield1']) ) { // change the "cufield1" to your field name, make sure all are lower case and no space.
$row = '<td>'. $additional_fields['cufield1'] .'</td>'; // change the "cufield1" to your field name, make sure all are lower case and no space.
}
// Return the row, which will appear after date
return $row;
}
}
function render_appoinement_display_additional_fields(){
$GLOBALS['AppoinementDisplayAdditionalFields'] = AppoinementDisplayAdditionalFields::get_instance();
}
add_action( 'plugins_loaded', 'render_appoinement_display_additional_fields' );
}
以上是关于php 在app_my_appointments短代码中显示其他字段的主要内容,如果未能解决你的问题,请参考以下文章