芝麻web文件管理V1.00
编辑当前文件:/home/felaukpo/public_html/wp-content/themes/Divi/onboarding/ajax.php
$upload->get_error_message() ] ); } $attachment_id = is_wp_error( $upload ) ? 0 : $upload; $image_url = get_attached_file( $attachment_id ); $image_editor = wp_get_image_editor( $image_url ); if ( ! is_wp_error( $image_editor ) ) { $image_editor->set_quality( 80 ); $saved = $image_editor->save( null, 'image/jpeg' ); if ( ! is_wp_error( $saved ) ) { wp_delete_attachment( $attachment_id, true ); $attachment_id = wp_insert_attachment( [ 'post_mime_type' => 'image/jpeg', 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $saved['path'] ) ), 'post_content' => '', 'post_status' => 'inherit', ], $saved['path'] ); wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $saved['path'] ) ); } } wp_send_json_success( [ 'localImageID' => $attachment_id, 'localImageURL' => wp_get_attachment_url( $attachment_id ), ] ); } } add_action( 'wp_ajax_et_onboarding_upload_layout_image', __NAMESPACE__ . '\\upload_layout_image' ); /** * Handles creating a page via AJAX. * * @since ?? */ function create_page() { \et_core_security_check( 'manage_options', 'et_onboarding_create_page', '_ajax_nonce' ); $page_title = isset( $_POST['page_title'] ) ? sanitize_text_field( $_POST['page_title'] ) : ''; $result = wp_insert_post( [ 'post_title' => $page_title, 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'page', ] ); if ( ! $result ) { wp_send_json_error(); } update_post_meta( $result, '_et_pb_use_builder', 'on' ); update_post_meta( $result, '_et_pb_page_layout', 'et_full_width_page' ); update_post_meta( $result, '_et_pb_built_for_post_type', 'page' ); update_post_meta( $result, '_et_onboarding_created', '1' ); wp_send_json_success( $result ); } add_action( 'wp_ajax_et_onboarding_create_page', __NAMESPACE__ . '\\create_page' ); /** * Handles restoring pre-generation state via AJAX. * * @since ?? */ function restore_pre_generation_state() { \et_core_security_check( 'manage_options', 'et_onboarding_restore_pre_generation_state', '_ajax_nonce' ); // Restore site info. Helpers\restore_theme_builder(); Helpers\restore_primary_menu(); Helpers\purge_onboarding_pages(); Helpers\restore_homepage_settings(); wp_send_json_success(); } add_action( 'wp_ajax_et_onboarding_restore_pre_generation_state', __NAMESPACE__ . '\\restore_pre_generation_state' ); /** * Publish pages. */ function publish_new_pages() { \et_core_security_check( 'manage_options', 'et_onboarding_publish_new_pages', '_ajax_nonce' ); $args = array( 'post_type' => 'page', 'post_status' => 'draft', 'meta_key' => '_et_onboarding_created', 'posts_per_page' => -1, 'fields' => 'ids', ); $query = new \WP_Query( $args ); $posts = $query->get_posts(); if ( $query->have_posts() ) { foreach ( $posts as $post_id ) { wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish', ) ); } } wp_reset_postdata(); } add_action( 'wp_ajax_et_onboarding_publish_new_pages', __NAMESPACE__ . '\\publish_new_pages' ); /** * Clean up '_et_onboarding_created' meta from pages, theme builder template and menu. */ function clear_flag_meta() { \et_core_security_check( 'manage_options', 'et_onboarding_clear_flag_meta', '_ajax_nonce' ); $args = array( 'post_type' => [ 'page', ET_THEME_BUILDER_TEMPLATE_POST_TYPE ], 'post_status' => 'publish', 'meta_key' => '_et_onboarding_created', 'posts_per_page' => -1, 'fields' => 'ids', ); $posts = get_posts( $args ); if ( ! empty( $posts ) ) { foreach ( $posts as $post_id ) { delete_post_meta( $post_id, '_et_onboarding_created' ); } } $menus = wp_get_nav_menus(); foreach ( $menus as $menu ) { delete_term_meta( $menu->term_id, '_et_onboarding_created' ); } } add_action( 'wp_ajax_et_onboarding_clear_flag_meta', __NAMESPACE__ . '\\clear_flag_meta' ); /* * AJAX handler to check if WooCommerce is installed. */ function is_woocommerce_installed() { \et_core_security_check( 'manage_options', 'et_onboarding_is_woocommerce_installed', '_ajax_nonce' ); $is_installed = false; $all_plugins = get_plugins(); if ( array_key_exists( 'woocommerce/woocommerce.php', $all_plugins ) ) { $is_installed = true; } wp_send_json_success( [ 'is_installed' => $is_installed ] ); } add_action( 'wp_ajax_et_onboarding_is_woocommerce_installed', __NAMESPACE__ . '\\is_woocommerce_installed' ); /** * AJAX handler to check if WooCommerce is active. */ function is_woocommerce_active() { \et_core_security_check( 'manage_options', 'et_onboarding_is_woocommerce_active', '_ajax_nonce' ); include_once ABSPATH . 'wp-admin/includes/plugin.php'; $is_active = false; if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { $is_active = true; } wp_send_json_success( [ 'is_active' => $is_active ] ); } add_action( 'wp_ajax_et_onboarding_is_woocommerce_active', __NAMESPACE__ . '\\is_woocommerce_active' );