Файловый менеджер - Редактировать - /home/digitalm/invisalign/wp-content/themes/healthy-smiles/admin/installer/importer/wpforms.php
Назад
<?php namespace HealthySmilesSpace\Admin\Installer\Importer; use HealthySmilesSpace\Core\Utils\API_Requests; use HealthySmilesSpace\Core\Utils\Utils; use Elementor\Plugin as Elementor_Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * WPForms handler class is responsible for different methods on importing "WPForms" plugin forms. * * @since 1.0.0 */ class WPForms { /** * WPForms Import constructor. * * @since 1.0.0 */ public function __construct() { add_action( 'cmsmasters_set_import_status', array( get_called_class(), 'set_import_status' ) ); if ( self::activation_status() && API_Requests::check_token_status() ) { add_action( 'admin_init', array( $this, 'admin_init_actions' ) ); add_action( 'cmsmasters_regenerate_content_wpforms_ids', array( $this, 'regenerate_content_forms_ids' ) ); } } /** * Activation status. * * @since 1.0.0 * * @return bool Activation status. */ public static function activation_status() { return function_exists( 'wpforms' ); } /** * Get import status. * * @since 1.0.0 * * @param string $default Import status by default, may be pending or done. * * @return string Import status. */ public static function get_import_status( $default = 'done' ) { return get_option( 'cmsmasters_healthy-smiles_' . Utils::get_demo() . '_wpforms_import', $default ); } /** * Set import status. * * @since 1.0.0 * * @param string $status Import status, may be pending or done. */ public static function set_import_status( $status = 'pending' ) { if ( 'done' === self::get_import_status( false ) ) { return; } update_option( 'cmsmasters_healthy-smiles_' . Utils::get_demo() . '_wpforms_import', $status ); } /** * Actions on admin_init hook. * * @since 1.0.0 */ public function admin_init_actions() { if ( 'pending' !== self::get_import_status( 'done' ) ) { return; } $this->import_forms(); self::set_import_status( 'done' ); } /** * Import forms. * * @since 1.0.0 */ protected function import_forms() { $response = API_Requests::post_request( 'get-wpforms', array( 'demo' => Utils::get_demo() ) ); $response_code = wp_remote_retrieve_response_code( $response ); if ( 200 !== $response_code ) { return; } $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); $data = $response_body['data']; if ( empty( $data ) ) { return; } $forms = json_decode( $data, true ); if ( empty( $forms ) || ! is_array( $forms ) ) { return; } foreach ( $forms as $form ) { $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : ''; $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : ''; $new_id = wp_insert_post( array( 'post_title' => $title, 'post_status' => 'publish', 'post_type' => 'wpforms', 'post_excerpt' => $desc, ) ); if ( $new_id ) { $demo = Utils::get_demo(); $forms_ids = get_transient( "cmsmasters_healthy-smiles_{$demo}_wpforms_import_forms_ids" ); if ( false === $forms_ids ) { $forms_ids = array(); } $forms_ids[ $form['id'] ] = $new_id; set_transient( "cmsmasters_healthy-smiles_{$demo}_wpforms_import_forms_ids", $forms_ids, HOUR_IN_SECONDS ); $form['id'] = $new_id; wp_update_post( array( 'ID' => $new_id, 'post_content' => wpforms_encode( $form ), ) ); } } } /** * Regenerate forms ids in elementor widgets. * * @since 1.0.0 */ public function regenerate_content_forms_ids() { $forms_ids = get_transient( 'cmsmasters_healthy-smiles_' . Utils::get_demo() . '_wpforms_import_forms_ids' ); if ( empty( $forms_ids ) ) { return; } $post_ids = Utils::get_elementor_post_ids(); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $document = Elementor_Plugin::$instance->documents->get( $post_id ); if ( $document ) { $data = $document->get_elements_data(); } if ( empty( $data ) ) { continue; } $data = Elementor_Plugin::$instance->db->iterate_data( $data, function( $element ) use ( $forms_ids ) { if ( empty( $element['widgetType'] ) || 'cmsmasters-wp-form' !== $element['widgetType'] || ! isset( $element['settings']['form_list'] ) ) { return $element; } $old_id = $element['settings']['form_list']; if ( isset( $forms_ids[ $old_id ] ) ) { $element['settings']['form_list'] = strval( $forms_ids[ $old_id ] ); } return $element; } ); $document->save( array( 'elements' => $data, ) ); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Генерация страницы: 0.03 |
proxy
|
phpinfo
|
Настройка