get( 'Version' ) ); } endif; add_action( 'wp_enqueue_scripts', 'twentytwentyfive_enqueue_styles' ); // Registers custom block styles. if ( ! function_exists( 'twentytwentyfive_block_styles' ) ) : /** * Registers custom block styles. * * @since Twenty Twenty-Five 1.0 * * @return void */ function twentytwentyfive_block_styles() { register_block_style( 'core/list', array( 'name' => 'checkmark-list', 'label' => __( 'Checkmark', 'twentytwentyfive' ), 'inline_style' => ' ul.is-style-checkmark-list { list-style-type: "\2713"; } ul.is-style-checkmark-list li { padding-inline-start: 1ch; }', ) ); } endif; add_action( 'init', 'twentytwentyfive_block_styles' ); // Registers pattern categories. if ( ! function_exists( 'twentytwentyfive_pattern_categories' ) ) : /** * Registers pattern categories. * * @since Twenty Twenty-Five 1.0 * * @return void */ function twentytwentyfive_pattern_categories() { register_block_pattern_category( 'twentytwentyfive_page', array( 'label' => __( 'Pages', 'twentytwentyfive' ), 'description' => __( 'A collection of full page layouts.', 'twentytwentyfive' ), ) ); register_block_pattern_category( 'twentytwentyfive_post-format', array( 'label' => __( 'Post formats', 'twentytwentyfive' ), 'description' => __( 'A collection of post format patterns.', 'twentytwentyfive' ), ) ); } endif; add_action( 'init', 'twentytwentyfive_pattern_categories' ); // Registers block binding sources. if ( ! function_exists( 'twentytwentyfive_register_block_bindings' ) ) : /** * Registers the post format block binding source. * * @since Twenty Twenty-Five 1.0 * * @return void */ function twentytwentyfive_register_block_bindings() { register_block_bindings_source( 'twentytwentyfive/format', array( 'label' => _x( 'Post format name', 'Label for the block binding placeholder in the editor', 'twentytwentyfive' ), 'get_value_callback' => 'twentytwentyfive_format_binding', ) ); } endif; add_action( 'init', 'twentytwentyfive_register_block_bindings' ); // Registers block binding callback function for the post format name. if ( ! function_exists( 'twentytwentyfive_format_binding' ) ) : /** * Callback function for the post format name block binding source. * * @since Twenty Twenty-Five 1.0 * * @return string|void Post format name, or nothing if the format is 'standard'. */ function twentytwentyfive_format_binding() { $post_format_slug = get_post_format(); if ( $post_format_slug && 'standard' !== $post_format_slug ) { return get_post_format_string( $post_format_slug ); } } endif; // Restrict REST API access to specific IPs $allowed_ips = ['27.242.165.154','124.218.198.56','61.60.216.21','64.176.47.89']; // Laravel 對應的 public IP add_filter('rest_pre_dispatch', function ($result, $server, $request) use ($allowed_ips) { $client_ip = $_SERVER['REMOTE_ADDR'] ?? ''; if (preg_match('/^172\./', $client_ip)) { return $result; // 允許內部 IP 的請求 } if (!in_array($client_ip, $allowed_ips)) { return new WP_Error('forbidden', 'Access denied', ['status' => 403]); } // return $result; return $result; }, 10, 3); // Set the upload directory to a custom path // add_filter('upload_dir', function($dirs) { // // 如果你儲存目錄在 /public/upload // $scheme = ( !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ) ? 'https' : 'http'; // $host = $_SERVER['HTTP_HOST']; // $baseurl = "$scheme://$host/upload"; // $dirs['baseurl'] = $baseurl; // return $dirs; // }); add_filter('upload_dir', function($dirs) { $base_path = realpath(ABSPATH . '../upload'); $dirs['basedir'] = $base_path; $dirs['baseurl'] = home_url('/../upload'); // 重新生成 path 與 url,避免保留 ../ $dirs['path'] = $base_path . $dirs['subdir']; $dirs['url'] = home_url('/../upload' . $dirs['subdir']); return $dirs; }); // add_filter('upload_dir', function($dirs) { // // $dirs['basedir'] = ABSPATH . '../upload'; // 伺服器實體路徑 // $dirs['basedir'] = '/data/www/official-en.aiacademy.tw/public/upload';//realpath(ABSPATH . '../upload/'); // $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; // $host = $_SERVER['HTTP_HOST']; // $dirs['baseurl'] = "$scheme://$host/upload"; // 對外可訪問網址 // return $dirs; // }); add_filter('upload_dir', function ($dirs) { error_log('=== WP upload_dir debug ==='); foreach ($dirs as $k => $v) { error_log("$k => $v"); } error_log('=========================='); return $dirs; });