如何覆盖现有的wordpress Bookly插件文件

时间:2019-08-17 03:18:47

标签: php wordpress wordpress-plugin-creation

我想对现有的书本插件文件进行一些更改,但不影响原始的插件文件,但是当我尝试覆盖插件模板并将其放到wordpress主题目录中但不起作用时。

这是我的插件文件,我进行了一些更改,但我不知道如何在主题目录中覆盖。

plugins / bookly-response-appointment-booking-tool / backend / components / dialogs / appointment / edit / Ajax.php

我已经把这个目录放在了

wp-content / themes / themify-ultra-child / bookly-response-appointment-booking-tool / backend / components / dialogs / appointment / edit / Ajax.php

public static function getDataForAppointmentForm()
    {
        $type = self::parameter( 'type', false ) == 'package'
            ? Lib\Entities\Service::TYPE_PACKAGE
            : Lib\Entities\Service::TYPE_SIMPLE;

        $statuses = Lib\Proxy\CustomStatuses::prepareAllStatuses( array(
            Lib\Entities\CustomerAppointment::STATUS_PENDING,
            Lib\Entities\CustomerAppointment::STATUS_APPROVED,
            Lib\Entities\CustomerAppointment::STATUS_CANCELLED,
            Lib\Entities\CustomerAppointment::STATUS_REJECTED,
            Lib\Entities\CustomerAppointment::STATUS_WAITLISTED,
            Lib\Entities\CustomerAppointment::STATUS_DONE,
        ) );
        $status_items = array();
        foreach ( $statuses as $status ) {
            $status_items[ $status ] = Lib\Entities\CustomerAppointment::statusToString( $status );
        }

        $result = array(
            'staff'                    => array(),
            'customers'                => array(),
            'start_time'               => array(),
            'end_time'                 => array(),
            'app_start_time'           => null,  // Appointment start time which may not be in the list of start times.
            'app_end_time'             => null,  // Appointment end time which may not be in the list of end times.
            'week_days'                => array(),
            'time_interval'            => Lib\Config::getTimeSlotLength(),
            'status'                   => array(
                'items' => $status_items,
            ),
            'extras_consider_duration' => (int) Lib\Proxy\ServiceExtras::considerDuration( true ),
            'extras_multiply_nop'      => (int) get_option( 'bookly_service_extras_multiply_nop', 1 ),
        );

        // Staff list.
        $staff         = Lib\Entities\Staff::query()->findOne();
        $staff_members = $staff ? Lib\Config::proActive() ? Lib\Utils\Common::isCurrentUserSupervisor() ? Lib\Entities\Staff::query()->sortBy( 'position' )->find() : Lib\Entities\Staff::query()->where( 'wp_user_id', get_current_user_id() )->find() : array( $staff ) : array();
        $postfix_archived = sprintf( ' (%s)', __( 'Archived', 'bookly' ) );

        $max_duration  = 0;
        $has_categories = (bool) Lib\Entities\Category::query()->findOne();

        foreach ( $staff_members as $staff_member ) {
            $services = array();
            if ( $type == Lib\Entities\Service::TYPE_SIMPLE ) {
                $services = Proxy\Pro::addCustomService( $services );
            }
            foreach ( $staff_member->getStaffServices( $type ) as $staff_service ) {
                $sub_services = $staff_service->service->getSubServices();
                if ( $type == Lib\Entities\Service::TYPE_SIMPLE || ! empty( $sub_services ) ) {
                    if ( $staff_service->getLocationId() === null || Lib\Proxy\Locations::prepareStaffLocationId( $staff_service->getLocationId(), $staff_service->getStaffId() ) == $staff_service->getLocationId() ) {
                        if ( ! in_array( $staff_service->service->getId(), array_map( function ( $service ) { return $service['id']; }, $services ) ) ) {
                            $category = Lib\Entities\Category::find( Lib\Entities\Service::find( $staff_service->getServiceId() )->getCategoryId() );
                            $services[] = array(
                                'id'              => $staff_service->service->getId(),
                                'title'           => sprintf(
                                    '%s (%s)',
                                    $staff_service->service->getTitle(),
                                    Lib\Utils\DateTime::secondsToInterval( $staff_service->service->getDuration() )
                                ),
                                'category'        => $category ? $category->getName() : ( $has_categories ? __( 'Uncategorized', 'bookly' ) : ''),
                                'duration'        => $staff_service->service->getDuration(),
                                'units_min'       => $staff_service->service->getUnitsMin(),
                                'units_max'       => $staff_service->service->getUnitsMax(),
                                'locations'       => array(
                                    ( $staff_service->getLocationId() ?: 0 ) => array(
                                        'capacity_min' => Lib\Config::groupBookingActive() ? $staff_service->getCapacityMin() : 1,
                                        'capacity_max' => Lib\Config::groupBookingActive() ? $staff_service->getCapacityMax() : 1,
                                    ),
                                ),
                            );
                            $max_duration = max( $max_duration, $staff_service->service->getUnitsMax() * $staff_service->service->getDuration() );
                        } else {
                            array_walk( $services, function ( &$item ) use ( $staff_service ) {
                                if ( $item['id'] == $staff_service->service->getId() ) {
                                    $item['locations'][ $staff_service->getLocationId() ?: 0 ] = array(
                                        'capacity_min' => Lib\Config::groupBookingActive() ? $staff_service->getCapacityMin() : 1,
                                        'capacity_max' => Lib\Config::groupBookingActive() ? $staff_service->getCapacityMax() : 1,
                                    );
                                }
                            } );
                        }
                    }
                }
            }
            $locations = array();
            foreach ( (array) Lib\Proxy\Locations::findByStaffId( $staff_member->getId() ) as $location ) {
                $locations[] = array(
                    'id'   => $location->getId(),
                    'name' => $location->getName(),
                );
            }
            $result['staff'][] = array(
                'id'        => $staff_member->getId(),
                'full_name' => $staff_member->getFullName() . ( $staff_member->getVisibility() == 'archive' ? $postfix_archived : '' ),
                'archived'  => $staff_member->getVisibility() == 'archive',
                'services'  => $services,
                'locations' => $locations,
                'category'  => Lib\Proxy\Pro::getStaffCategoryName( $staff_member->getCategoryId() ),
            );
        }

        /** @var Lib\Entities\Customer $customer */
        // Customers list.
        foreach ( Lib\Entities\Customer::query()->sortBy( 'full_name' )->find() as $customer ) {
            $name = $customer->getFullName();
            if ( $customer->getEmail() != '' || $customer->getPhone() != '' ) {
                // $name .= ' (' . trim( $customer->getEmail() . ', ' . $customer->getPhone(), ', ' ) . ')';
                     // $name .= ' (sdsfd)';

                     // echo '<pre>',print_r($customer->getCity()),'</pre>';
                $name .= ' ('.trim($customer->getStreet().', ' .$customer->getPostcode()).')';
            }

            $result['customers'][] = array(
                'id'                 => $customer->getId(),
                'name'               => $name,
                'status'             => Lib\Proxy\CustomerGroups::prepareDefaultAppointmentStatus( get_option( 'bookly_gen_default_appointment_status' ), $customer->getGroupId() ),
                'custom_fields'      => array(),
                'timezone'           => Lib\Proxy\Pro::getLastCustomerTimezone( $customer->getId() ),
                'number_of_persons'  => 1,
            );
        }

        // Time list.
        $ts_length  = Lib\Config::getTimeSlotLength();
        $time_start = 0;
        $time_end   = max( $max_duration + DAY_IN_SECONDS, DAY_IN_SECONDS * 2 );

        // Run the loop.
        while ( $time_start <= $time_end ) {
            $slot = array(
                'value' => Lib\Utils\DateTime::buildTimeString( $time_start, false ),
                'title' => Lib\Utils\DateTime::formatTime( $time_start ),
            );
            if ( $time_start < DAY_IN_SECONDS ) {
                $result['start_time'][] = $slot;
            }
            $result['end_time'][] = $slot;
            $time_start += $ts_length;
        }

        $days_times = Lib\Config::getDaysAndTimes();
        $weekdays  = array( 1 => 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', );
        foreach ( $days_times['days'] as $index => $abbrev ) {
            $result['week_days'][] = $weekdays[ $index ];
        }

        if ( $type == Lib\Entities\Service::TYPE_PACKAGE ) {
            $result = Proxy\Shared::prepareDataForPackage( $result );
        }

        wp_send_json( $result );
    }

不覆盖主题文件夹中的插件。

1 个答案:

答案 0 :(得分:0)

即使在提出此问题一年后,Bookly仍然不允许自定义(就像几乎每个人在Wordpress开发中一样)。

作为示例,您可以尝试搜索用于此提议的重要功能的每种用法(例如do_action),但不会找到超过20个结果,对于同等大小的插件而言,这是非常低的-并且大多数情况与wpml_register_single_string挂钩有关。

几个月前开张的topic也这样说,Bookly回答了。