Wordpress/Elementor/PHP Code Widget: PHP code is not execute and everything after “=>” renders as...












0















I want to execute some PHP code in an WordPress Elementor template with the PHP Code Widget. Everything works fine as long as I am logged in.



If I log out, the code is not executed and everything after "=>" shows as plain text.



So e.g. the code



<?php
echo 'before';
$someArray = ['foo' => 'bar'];
echo 'after';
?>
<b>some HTML</b>


would result in the following string:



 'bar']; echo 'after'; ?>


The HTML after this is fine.



If I place the same code in another widget outside of Elementor (e.g. the footer of the theme), everything also works fine.



I am the admin of this single WordPress installation.



Has anyone an idea, how to stop this behaviour?










share|improve this question























  • so when you logged-in as admin then this code runs? yes? what output it is giving at that time?

    – Alive to Die
    Nov 14 '17 at 4:22











  • Yes. The code also runs, when I am logged in with an account, that has only the author role. The output is what I would expect: beforeafter

    – cgdannie
    Nov 14 '17 at 18:16


















0















I want to execute some PHP code in an WordPress Elementor template with the PHP Code Widget. Everything works fine as long as I am logged in.



If I log out, the code is not executed and everything after "=>" shows as plain text.



So e.g. the code



<?php
echo 'before';
$someArray = ['foo' => 'bar'];
echo 'after';
?>
<b>some HTML</b>


would result in the following string:



 'bar']; echo 'after'; ?>


The HTML after this is fine.



If I place the same code in another widget outside of Elementor (e.g. the footer of the theme), everything also works fine.



I am the admin of this single WordPress installation.



Has anyone an idea, how to stop this behaviour?










share|improve this question























  • so when you logged-in as admin then this code runs? yes? what output it is giving at that time?

    – Alive to Die
    Nov 14 '17 at 4:22











  • Yes. The code also runs, when I am logged in with an account, that has only the author role. The output is what I would expect: beforeafter

    – cgdannie
    Nov 14 '17 at 18:16
















0












0








0








I want to execute some PHP code in an WordPress Elementor template with the PHP Code Widget. Everything works fine as long as I am logged in.



If I log out, the code is not executed and everything after "=>" shows as plain text.



So e.g. the code



<?php
echo 'before';
$someArray = ['foo' => 'bar'];
echo 'after';
?>
<b>some HTML</b>


would result in the following string:



 'bar']; echo 'after'; ?>


The HTML after this is fine.



If I place the same code in another widget outside of Elementor (e.g. the footer of the theme), everything also works fine.



I am the admin of this single WordPress installation.



Has anyone an idea, how to stop this behaviour?










share|improve this question














I want to execute some PHP code in an WordPress Elementor template with the PHP Code Widget. Everything works fine as long as I am logged in.



If I log out, the code is not executed and everything after "=>" shows as plain text.



So e.g. the code



<?php
echo 'before';
$someArray = ['foo' => 'bar'];
echo 'after';
?>
<b>some HTML</b>


would result in the following string:



 'bar']; echo 'after'; ?>


The HTML after this is fine.



If I place the same code in another widget outside of Elementor (e.g. the footer of the theme), everything also works fine.



I am the admin of this single WordPress installation.



Has anyone an idea, how to stop this behaviour?







php wordpress widget elementor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '17 at 4:18









cgdanniecgdannie

848




848













  • so when you logged-in as admin then this code runs? yes? what output it is giving at that time?

    – Alive to Die
    Nov 14 '17 at 4:22











  • Yes. The code also runs, when I am logged in with an account, that has only the author role. The output is what I would expect: beforeafter

    – cgdannie
    Nov 14 '17 at 18:16





















  • so when you logged-in as admin then this code runs? yes? what output it is giving at that time?

    – Alive to Die
    Nov 14 '17 at 4:22











  • Yes. The code also runs, when I am logged in with an account, that has only the author role. The output is what I would expect: beforeafter

    – cgdannie
    Nov 14 '17 at 18:16



















so when you logged-in as admin then this code runs? yes? what output it is giving at that time?

– Alive to Die
Nov 14 '17 at 4:22





so when you logged-in as admin then this code runs? yes? what output it is giving at that time?

– Alive to Die
Nov 14 '17 at 4:22













Yes. The code also runs, when I am logged in with an account, that has only the author role. The output is what I would expect: beforeafter

– cgdannie
Nov 14 '17 at 18:16







Yes. The code also runs, when I am logged in with an account, that has only the author role. The output is what I would expect: beforeafter

– cgdannie
Nov 14 '17 at 18:16














2 Answers
2






active

oldest

votes


















0














Only users with the unfiltered_html role will be allowed to insert unfiltered HTML. This includes PHP code, so users without admin or editor permissions will not be able to use this to execute code, even if they have widget editing permissions.



taken form https://wordpress.org/plugins/php-code-widget/






share|improve this answer
























  • Thanks, but I wrote "I am the admin of this single WordPress installation."

    – cgdannie
    Sep 12 '18 at 9:06





















0














I could reproduce the problem.



One way to work around this: use an Elementor HTML widget with an iframe in it and write the PHP code in the src-file as a complete HTML page.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47277596%2fwordpress-elementor-php-code-widget-php-code-is-not-execute-and-everything-afte%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Only users with the unfiltered_html role will be allowed to insert unfiltered HTML. This includes PHP code, so users without admin or editor permissions will not be able to use this to execute code, even if they have widget editing permissions.



    taken form https://wordpress.org/plugins/php-code-widget/






    share|improve this answer
























    • Thanks, but I wrote "I am the admin of this single WordPress installation."

      – cgdannie
      Sep 12 '18 at 9:06


















    0














    Only users with the unfiltered_html role will be allowed to insert unfiltered HTML. This includes PHP code, so users without admin or editor permissions will not be able to use this to execute code, even if they have widget editing permissions.



    taken form https://wordpress.org/plugins/php-code-widget/






    share|improve this answer
























    • Thanks, but I wrote "I am the admin of this single WordPress installation."

      – cgdannie
      Sep 12 '18 at 9:06
















    0












    0








    0







    Only users with the unfiltered_html role will be allowed to insert unfiltered HTML. This includes PHP code, so users without admin or editor permissions will not be able to use this to execute code, even if they have widget editing permissions.



    taken form https://wordpress.org/plugins/php-code-widget/






    share|improve this answer













    Only users with the unfiltered_html role will be allowed to insert unfiltered HTML. This includes PHP code, so users without admin or editor permissions will not be able to use this to execute code, even if they have widget editing permissions.



    taken form https://wordpress.org/plugins/php-code-widget/







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 11 '18 at 1:45









    Louis van WykLouis van Wyk

    1




    1













    • Thanks, but I wrote "I am the admin of this single WordPress installation."

      – cgdannie
      Sep 12 '18 at 9:06





















    • Thanks, but I wrote "I am the admin of this single WordPress installation."

      – cgdannie
      Sep 12 '18 at 9:06



















    Thanks, but I wrote "I am the admin of this single WordPress installation."

    – cgdannie
    Sep 12 '18 at 9:06







    Thanks, but I wrote "I am the admin of this single WordPress installation."

    – cgdannie
    Sep 12 '18 at 9:06















    0














    I could reproduce the problem.



    One way to work around this: use an Elementor HTML widget with an iframe in it and write the PHP code in the src-file as a complete HTML page.






    share|improve this answer






























      0














      I could reproduce the problem.



      One way to work around this: use an Elementor HTML widget with an iframe in it and write the PHP code in the src-file as a complete HTML page.






      share|improve this answer




























        0












        0








        0







        I could reproduce the problem.



        One way to work around this: use an Elementor HTML widget with an iframe in it and write the PHP code in the src-file as a complete HTML page.






        share|improve this answer















        I could reproduce the problem.



        One way to work around this: use an Elementor HTML widget with an iframe in it and write the PHP code in the src-file as a complete HTML page.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 20:20









        trincot

        128k1688123




        128k1688123










        answered Jan 1 at 19:31









        Paul_CPaul_C

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47277596%2fwordpress-elementor-php-code-widget-php-code-is-not-execute-and-everything-afte%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith