Server IP : 85.214.239.14 / Your IP : 216.73.216.9 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/wordpress/wp-content/plugins/really-simple-ssl/settings/src/Settings/ |
Upload File : |
/** * This file contains the PostDropdown component. * * This component displays a dropdown menu that allows the user to select a post * from a list of posts fetched from the WordPress database. The selected post * is then used to set a value in an options array stored in the WordPress * database. The component also allows the user to search for posts by typing * in a search box. */ import React, { useState, useEffect } from "react"; import { ThemeProvider } from '@mui/material/styles'; import apiFetch from '@wordpress/api-fetch'; import { __ } from '@wordpress/i18n'; import autoCompleteSharedTheme from '../utils/autoCompleteTheme'; import AutoCompleteControl from "../settings/AutoComplete/AutoCompleteControl"; import useFields from "./FieldsData"; const PostDropdown = ({ field }) => { const [posts, setPosts] = useState([]); const [selectedPost, setSelectedPost] = useState(""); const { updateField, setChangedField } = useFields(); useEffect(() => { // Fetch posts data when the component mounts apiFetch({ path: '/wp/v2/pages?per_page=100' }).then((data) => { const formattedData = data.map(post => ({ label: post.title.rendered, value: post.id })); setPosts([{ label: "404 (default)", value: "404_default" }, ...formattedData]); }); }, []); useEffect(() => { if (field.value !== "404_default") { apiFetch({ path: `wp/v2/pages/${field.value}` }) .then((data) => { if (data.title) { setSelectedPost({ label: data.title.rendered, value: field.value }); } else { setSelectedPost({ label: "404 (default)", value: "404_default" }); } }); } else { setSelectedPost({ label: "404 (default)", value: "404_default" }); } }, [field.value]); const handleChange = (newValue) => { const value = newValue ? newValue : '404_default'; updateField(field.id, value); setChangedField(field.id, value); }; return ( <ThemeProvider theme={autoCompleteSharedTheme}> <div> <label htmlFor="rsssl-filter-post-input"> {__("Redirect to this post when someone tries to access /wp-admin or /wp-login.php. The default is a 404 page.", "really-simple-ssl")} </label> <AutoCompleteControl className="rsssl-select" field={field} label={__("Search for a post.", "really-simple-ssl")} value={selectedPost} options={posts} onChange={handleChange} disabled={false} /> </div> </ThemeProvider> ); }; export default PostDropdown;