### Install Composer Dependencies Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Building.md Installs all project dependencies defined in the composer.json file. Composer must be installed. ```bash composer install ``` -------------------------------- ### Install onOffice SDK using Composer Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/SDK/README.md Provides the Composer command to install the onOffice SDK library. This is the recommended method for integrating the SDK into a PHP project. ```bash $ composer require onoffice/sdk:^0.2.0 ``` -------------------------------- ### Check PHP Platform Requirements (Composer) Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Building.md Verifies that the installed PHP environment meets the project's requirements, including necessary extensions. Composer must be installed. ```bash composer check-platform-reqs ``` -------------------------------- ### Quickstart: Initialize SDK, Set API Version, and Read Estate Data Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/SDK/README.md Demonstrates the basic usage of the onOffice SDK. It initializes the SDK, sets the API version to 'stable', defines parameters for reading estate data including fields, limits, sorting, and filters, and then sends the request using an access token and secret. Finally, it retrieves and exports the response as a PHP array. ```php $sdk = new onOfficeSDK(); $sdk->setApiVersion('stable'); $parametersReadEstate = [ 'data' => [ 'Id', 'kaufpreis', 'lage', ], 'listlimit' => 10, 'sortby' => [ 'kaufpreis' => 'ASC', 'warmmiete' => 'ASC', ], 'filter' => [ 'kaufpreis' => [ ['op' => '>', 'val' => 300000], ], 'status' => [ ['op' => '=', 'val' => 1], ], ], ]; $handleReadEstate = $sdk->callGeneric(onOfficeSDK::ACTION_ID_READ, 'estate', $parametersReadEstate); $sdk->sendRequests('put the token here', 'and secret here'); var_export($sdk->getResponseArray($handleReadEstate)); ``` -------------------------------- ### Clone Repository with Submodules Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Building.md Clones the oo-wp-plugin repository and its submodules. Ensure you have Git installed. ```bash git clone --recursive https://github.com/onOfficeGmbH/oo-wp-plugin.git ``` -------------------------------- ### Multisite and Translation Setup in PHP Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This PHP code checks if the plugin is running in a WordPress multisite network admin context and includes logic for loading translation files. It uses `load_plugin_textdomain` to make the plugin translatable, ensuring that the plugin's strings can be localized for different languages. ```php // Check if running in network admin (multisite) if (is_network_admin()) { // Network-level logic return; } // Load translations load_plugin_textdomain( 'onoffice-for-wp-websites', false, basename(ONOFFICE_PLUGIN_DIR) . '/languages' ); ``` -------------------------------- ### Display Address Lists and Details (Shortcodes & PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This code illustrates how to display address lists and detail views using shortcodes like '[oo_address view="agent-list"]'. It also shows how to generate these views programmatically in PHP templates and how to create direct URLs for address detail pages. The example includes validation of address IDs before generating detail links. ```html // Address list shortcode [oo_address view="agent-list"] // Address detail shortcode [oo_address view="agent-detail"] ``` ```php // In PHP template: get(AddressIdRequestGuard::class); // Validate address ID if ($pAddressIdGuard->isValid($addressId)) { $pAddressDetailUrl = $pDI->get(AddressDetailUrl::class); $url = $pAddressDetailUrl->createAddressDetailLink($addressId); echo 'View Agent Profile'; } ?> ``` -------------------------------- ### Customizing Estate List Template in PHP Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This snippet demonstrates how to create a custom template file for displaying an estate list. It specifies the template file's location and provides an example of iterating through estate data to generate HTML output. This allows for full control over the presentation of property listings. ```php

View Details
Estates > Edit View > Template: custom-list ``` -------------------------------- ### Extend Plugin Functionality with WordPress Hooks and Filters (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt Demonstrates how to extend the onOffice plugin's functionality using WordPress action and filter hooks. Examples include disabling redirections, customizing admin capabilities, adding toolbar menu items, hooking into form submissions, and modifying estate query parameters. Dependencies: WordPress core functions, onOffice WPlugin Controller UserCapabilities. ```php // Disable estate detail page redirection add_filter('oo_is_detailpage_redirection', '__return_false'); // Disable address detail page redirection add_filter('oo_is_address_detail_page_redirection', '__return_false'); // Customize admin capabilities use onOffice\WPlugin\Controller\UserCapabilities; add_action('init', function() { if (current_user_can(UserCapabilities::OO_PLUGINCAP_MANAGE_VIEW_MENU)) { // User can manage onOffice views } }); // Add custom toolbar menu items add_action('admin_bar_menu', function($wp_admin_bar) { if (current_user_can('manage_options')) { $wp_admin_bar->add_node([ 'id' => 'onoffice-custom', 'title' => 'Custom onOffice Tool', 'href' => admin_url('admin.php?page=custom-onoffice'), 'parent' => 'onoffice', ]); } }, 500); // Hook into form submission add_action('wp', function() { // Custom logic before form processing FormPostHandler::initialCheck(); }); // Modify estate query parameters add_filter('onoffice_estate_list_parameters', function($parameters) { // Add custom filter $parameters['filter']['verkauft'] = [['op' => '=', 'val' => 0]]; return $parameters; }); ``` -------------------------------- ### Git Commands for Tag Reset Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Releasing.md Provides Git commands to delete a local tag and remove it from the remote repository (GitHub). This is useful if a tag was created incorrectly and needs to be reset. Requires admin access to the repository. ```bash git tag -d v3.2 git push origin :v3.2 ``` -------------------------------- ### Embed Forms using Shortcode (WordPress) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This snippet illustrates how to embed various forms (contact, owner, interest, applicant search) into WordPress pages using the `[oo_form]` shortcode. It can be used directly in the content editor or programmatically in PHP templates. The shortcode requires specifying the desired form name. The programmatic example shows form building and rendering. ```html // In WordPress content editor: // Contact form [oo_form form="contact-form-name"] // Owner form [oo_form form="owner-registration"] // Interest form for property inquiries [oo_form form="property-interest"] // Applicant search form [oo_form form="buyer-search"] ``` ```php // In PHP template files: loadByFormName('contact-form-name'); $template = $pFormConfig->getTemplate(); $pTemplate = new Template(); $pTemplate = $pTemplate->withTemplateName($template); $pFormBuilder = new FormBuilder(); $pForm = $pFormBuilder->build('contact-form-name', $pFormConfig->getFormType()); echo $pTemplate->withForm($pForm)->render(); ?> ``` -------------------------------- ### Retrieve API Response as a PHP Array Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/SDK/README.md Shows the method to get the response data from a previously sent API request. The `getResponseArray` method takes a handle (returned by `callGeneric`) and returns the corresponding response as a PHP array. ```php var_export($sdk->getResponseArray($handleReadEstate)); ``` -------------------------------- ### Integrate with onOffice API using API Client (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This snippet demonstrates how to use the onOffice API client for custom integrations. It shows initializing the SDK wrapper, creating an API client action for reading data, setting parameters for data fields, limits, and filters. The code includes sending requests, checking results, and handling potential API errors. ```php use onOffice\WPlugin\API\APIClientActionGeneric; use onOffice\WPlugin\SDKWrapper; use onOffice\SDK\onOfficeSDK; // Initialize SDK wrapper $pSDKWrapper = new SDKWrapper(); // Create API client action $pAPIClient = new APIClientActionGeneric( $pSDKWrapper, onOfficeSDK::ACTION_ID_READ, 'estate' ); // Set parameters $pAPIClient->setParameters([ 'data' => ['Id', 'objekttitel', 'kaufpreis'], 'listlimit' => 20, 'filter' => [ 'status' => [['op' => '=', 'val' => 1]], ], ]); // Add to queue and send $pAPIClient->addRequestToQueue(); $pAPIClient->sendRequests(); // Check result status if ($pAPIClient->getResultStatus()) { $records = $pAPIClient->getResultRecords(); $meta = $pAPIClient->getResultMeta(); foreach ($records as $record) { echo "Property: " . $record['elements']['objekttitel'] . "\n"; echo "Price: " . $record['elements']['kaufpreis'] . "\n"; } } else { $errorCode = $pAPIClient->getErrorCode(); $errorMessage = $pAPIClient->getErrorMessage(); error_log("API Error $errorCode: $errorMessage"); } ``` -------------------------------- ### Update CSS Version in AdminViewController.php Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Releasing.md This snippet shows how to update the CSS version in the `AdminViewController.php` file to prevent caching issues. It requires modifying the `wp_enqueue_style` function call with the new version number. ```php wp_enqueue_style('onoffice-admin-css', plugins_url('/css/admin.css', ONOFFICE_PLUGIN_DIR.'/index.php'), array(), 'v4.20'); ``` -------------------------------- ### Initialize onOffice SDK Client Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/SDK/README.md This snippet shows how to create an instance of the onOfficeSDK class and set the desired API version. The API version defaults to 'stable' if not explicitly set. ```php $sdk = new onOfficeSDK(); $sdk->setApiVersion('stable'); ``` -------------------------------- ### Generate and Download PDF Documents for Property Exposés (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt Generates and downloads PDF documents for property details. It uses PdfDocumentModel and PdfDownload classes for programmatic generation and provides a URL structure for direct download. Error handling for validation and download failures is included. Dependencies: onOffice WPlugin PDF classes. ```php use onOffice\WPlugin\PDF\PdfDocumentModel; use onOffice\WPlugin\PDF\PdfDownload; // PDF download URL structure // https://yoursite.com/?document_pdf=1&estate_id=123&view=detail // Programmatic PDF generation try { $estateId = 123; $viewName = 'detail'; $pPdfDocumentModel = new PdfDocumentModel($estateId, $viewName); $pPdfDownload = $pDI->get(PdfDownload::class); // This triggers download and exits $pPdfDownload->download($pPdfDocumentModel); } catch (PdfDocumentModelValidationException $e) { // Invalid estate ID or view wp_die('Invalid PDF request', 'Error', ['response' => 404]); } catch (PdfDownloadException $e) { // Download failed error_log('PDF download error: ' . $e->getMessage()); wp_die('PDF generation failed', 'Error', ['response' => 500]); } // PDF link in templates $pdfUrl = add_query_arg([ 'document_pdf' => '1', 'estate_id' => 123, 'view' => 'detail', ], home_url('/')); echo 'Download PDF'; ``` -------------------------------- ### Display Estate List and Detail Views via Shortcode (WordPress) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This snippet shows how to use WordPress shortcodes to display estate listings and detail views. The `[oo_estate]` shortcode can be used in the content editor or programmatically via PHP. It supports different views and unit display options. No external dependencies beyond WordPress and the plugin itself are required. ```html // In WordPress content editor or PHP template: // Basic estate list [oo_estate view="my-estate-list"] // Estate list with units (for complex properties) [oo_estate view="my-estate-list" units="true"] // Estate detail view [oo_estate view="detail"] ``` ```php // In PHP template files: 'my-estate-list', 'units' => null, 'address' => null, ]; // The shortcode handler automatically determines if it's a list or detail view // and delegates to the appropriate controller $content = $pContentFilterShortCodeEstate->replaceShortCodes($attributes); echo $content; ?> ``` -------------------------------- ### Define Parameters for Reading Estate Data Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/SDK/README.md Illustrates how to structure the parameters for an API request to read estate data. This includes specifying the data fields to retrieve, setting a list limit, defining sorting criteria, and applying filters based on specific conditions. ```php $parametersReadEstate = [ 'data' => [ 'Id', 'kaufpreis', 'lage', ], 'listlimit' => 10, 'sortby' => [ 'kaufpreis' => 'ASC', 'warmmiete' => 'ASC', ], 'filter' => [ 'kaufpreis' => [ ['op' => '>', 'val' => 300000], ], 'status' => [ ['op' => '=', 'val' => 1], ], ], ]; ``` -------------------------------- ### Manage Plugin Cache Programmatically and via Admin (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This code covers cache management within the plugin. It shows how to clear the cache programmatically, configure cache duration via WordPress options, and clear cache directly through an admin URL. Additionally, it demonstrates scheduling cache renewals using WordPress cron and caching API responses for a specified duration. ```php // Clear cache programmatically use onOffice\WPlugin\Cache\CacheHandler; $pCacheHandler = $pDI->get(CacheHandler::class); $pCacheHandler->renew(); // Cache configuration (in wp-config.php or theme functions.php) update_option('onoffice-settings-duration-cache', 'six_hours'); // Available options: 'ten_minutes', 'thirty_minutes', 'hourly', 'six_hours', 'daily' // Clear cache via admin URL // https://yoursite.com/wp-admin/admin.php?action=onoffice-clear-cache // Schedule cache renewal $timestamp = wp_next_scheduled('oo_cache_renew'); if ($timestamp) { wp_unschedule_event($timestamp, 'oo_cache_renew'); } wp_schedule_event(time(), 'six_hours', 'oo_cache_renew'); // Cache output for API responses use onOffice\WPlugin\Cache\CachedOutput; $pCachedOutput = $pDI->get(CachedOutput::class); $content = json_encode(['data' => 'your data']); header('Content-Type: application/json; charset='.get_option('blog_charset')); $pCachedOutput->outputCached($content, 60 * 60 * 24 * 2); // Cache for 2 days ``` -------------------------------- ### WPML Language Switcher Integration for Estate Details (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This PHP code snippet integrates with the WPML Language Switcher to correctly generate URLs for estate detail pages when switching languages. It hooks into the 'wpml_ls_language_url' filter, retrieves the current estate ID, and uses helper classes to construct the appropriate multilingual URL. ```php // WPML language switcher integration for estate detail pages add_filter('wpml_ls_language_url', function($url, $data) use ($pDI) { $pWPQueryWrapper = $pDI->get(WPQueryWrapper::class); $estateId = (int) $pWPQueryWrapper->getWPQuery()->get('estate_id', 0); if (!empty($estateId)) { $pEstateIdGuard = $pDI->get(EstateIdRequestGuard::class); $pEstateDetailUrl = $pDI->get(EstateDetailUrl::class); $oldUrl = $pDI->get(Redirector::class)->getCurrentLink(); return $pEstateIdGuard->createEstateDetailLinkForSwitchLanguageWPML( $url, $estateId, $pEstateDetailUrl, $oldUrl, $data['default_locale'] ); } return $url; }, 10, 2); ``` -------------------------------- ### Retrieve Estate Data using onOffice SDK (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This snippet demonstrates how to retrieve estate data from the onOffice API using the SDK. It configures search parameters like fields, sorting, and filters for active properties above a certain price. Dependencies include the onOffice SDK. The output is an array of estate records. ```php use onOffice\SDK\onOfficeSDK; // Initialize SDK $sdk = new onOfficeSDK(); $sdk->setApiVersion('stable'); // Configure estate search parameters $parametersReadEstate = [ 'data' => [ 'Id', 'kaufpreis', // Purchase price 'lage', // Location 'objekttitel', // Property title 'objektart', // Property type 'wohnflaeche', // Living area ], 'listlimit' => 10, 'sortby' => [ 'kaufpreis' => 'ASC', 'warmmiete' => 'ASC', ], 'filter' => [ 'kaufpreis' => [ ['op' => '>', 'val' => 300000], ], 'status' => [ ['op' => '=', 'val' => 1], // Active status ], ], ]; // Queue the request $handleReadEstate = $sdk->callGeneric( onOfficeSDK::ACTION_ID_READ, 'estate', $parametersReadEstate ); // Send request with credentials $sdk->sendRequests('your-api-token', 'your-api-secret'); // Retrieve results $response = $sdk->getResponseArray($handleReadEstate); // Process response if (isset($response['data']['records'])) { foreach ($response['data']['records'] as $estate) { echo "Estate ID: " . $estate['id'] . "\n"; echo "Price: " . $estate['elements']['kaufpreis'] . "\n"; } } ``` -------------------------------- ### Send API Request using callGeneric and Authentication Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/SDK/README.md This code segment demonstrates how to initiate an API request using the `callGeneric` method, specifying the action ID, resource type, and parameters. It then shows how to send the prepared requests to the API using an access token and secret, and how to obtain the response. ```php $handleReadEstate = $sdk->callGeneric(onOfficeSDK::ACTION_ID_READ, 'estate', $parametersReadEstate); $sdk->sendRequests('put the token here', 'and secret here'); ``` -------------------------------- ### Handle Form Submissions with WordPress Hooks (PHP) Source: https://context7.com/onoffice-web-org/oo-wp-plugin/llms.txt This snippet demonstrates how the plugin automatically handles form submissions using WordPress action hooks. It also shows how to manually process custom forms by retrieving and configuring form instances. The plugin sanitizes input data and loads form configurations before processing. ```php // Form submission is handled automatically via WordPress 'wp' action hook // plugin.php:204 add_action('wp', [FormPostHandler::class, 'initialCheck']); // Custom form processing (for advanced use cases) use onOffice\WPlugin\FormPostHandler; use onOffice\WPlugin\Form; // Get form post instance for specific form type $formType = Form::TYPE_CONTACT; // or TYPE_OWNER, TYPE_INTEREST, TYPE_APPLICANT_SEARCH $pFormPostInstance = FormPostHandler::getInstance($formType); // Form data is automatically sanitized $formName = RequestVariablesSanitizer::filterInputString(INPUT_POST, 'oo_formid'); $formNo = filter_input(INPUT_POST, 'oo_formno', FILTER_SANITIZE_NUMBER_INT); // Load form configuration and process submission if ($formName !== null && $formNo !== null) { $pDataFormConfigurationFactory = new DataFormConfigurationFactory(); $pFormConfig = $pDataFormConfigurationFactory->loadByFormName($formName); $pFormPostInstance->initialCheck($pFormConfig, $formNo); } // Available form types: // Form::TYPE_CONTACT - General contact forms // Form::TYPE_OWNER - Property owner registration // Form::TYPE_INTEREST - Property interest inquiries // Form::TYPE_APPLICANT_SEARCH - Buyer/tenant search criteria ``` -------------------------------- ### Build Release Zip Archive (Makefile) Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Building.md Generates a release zip file for the WordPress plugin using a Makefile. Requires the `make` utility and an absolute path for the PREFIX environment variable. The output zip will be located at the specified PREFIX path. ```bash PREFIX=/tmp/release/onoffice-for-wp-websites make release ``` -------------------------------- ### Create WordPress Plugin Zip Archive Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Building.md Creates a zip archive of the plugin for WordPress upload. It's necessary to `cd` into the release directory first to ensure the correct folder structure within the zip file. The zip file will be created in the current directory. ```bash cd /tmp/release zip -r onoffice-for-wp-websites.zip ./onoffice-for-wp-websites ``` -------------------------------- ### Update Plugin Version (sed) Source: https://github.com/onoffice-web-org/oo-wp-plugin/blob/master/documentation/Building.md Overwrites the version number in the plugin.php file with the current Git tag. This command uses `sed` for text replacement. It's crucial to run this after the release build. ```bash sed -i "s/Version: .*$/Version: $(git describe --tags)/" /tmp/release/onoffice-for-wp-websites/plugin.php ```