0

I'm sorry if this has been asked before but I want to create my own plugin in which you enter information in the admin panel and that information is displayed on your page. So far i have created a new admin menu with a form but it is not sending the information to my website. Please give me a hand.

 <?php

/*

Plugin Name: newsSlider-Plugin

*/

print_r($_SESSION);

add_action("admin_menu", "addMenu");

function addMenu()

{

    add_menu_page("News slider", "News slider", 5, "subMenu", "changeTextFunction");

    add_submenu_page("subMenu", "change style", "change style", 5, "changeStyle", 
"changeStyleFunction");

}

function changeTextFunction()

{

    echo "Write down the news you want to be displayed in the fields";

    echo '

    <form method="post" action="">

    News field 1<input type="text" name="newsSlide1">

    News field 2<input type="text" name="newsSlide2">

    <input type="submit" name="submit" value="Submit"> 

    </form>';

    echo $_SESSION["favcolor"];

}

function changeStyleFunction()

{

    echo "subsmenu hellooo";

}

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$newsSliderInput1= test_input($_POST["newsSlide1"]);

session_start();

$_SESSION["favcolor"] = "yellow";

}

function test_input($data) {

  $data = trim($data);

  $data = stripslashes($data);

  $data = htmlspecialchars($data);

  return $data;

}

add_action("the_content", "displayNewsSlider");

function displayNewsSlider()

{

    echo $newsSliderInput1;

    echo "hi";

    echo $_SESSION["favcolor"];

}

?>
0

Your input needs to be saved somewhere, so it can be retrieved when a user visits the website. To achieve this you could for example use the update_option() and get_option() functions from the WordPress Options API to store the values.

To store the value:

function changeStyleFunction() {
    update_option( 'newsSlide1', test_input($_POST["newsSlide1"]) );
}

To retrieve the value:

function displayNewsSlider() {
    echo get_option( 'newsSlide1', '' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.