Support

Account

Home Forums General Issues Execute PHP In Text Field?

Solving

Execute PHP In Text Field?

  • Greetings:

    I am trying to run some simple php through a text field. I am already of aware of potential security issues so please do not feel motivated to warn about that.

    I am trying to put something like:

    <?php echo bloginfl('url'); ?>/the_rest_of_the_url.com

    Is this possible because when I try it, it basically breaks the page and does not load any content.

    Please advise…best regards!

  • Hi @john.marcello

    PHP has a function called eval which you can use to run PHP functionality from a string:
    http://www.php.net/eval

    So you could run it like this:

    
    eval( get_field('field_name') );
    

    The only problem you will have is that your ‘string’ is not PHP, it is HTML with some PHP in it. I’m not sure if the eval function will recognize opening and closing PHP tags.

    This is something that Google will know more about than me.

    Good luck

    Thanks
    E

  • I am not sure this is the type of solution I am looking for. Can anyone shed some light on this subject.

    Seems like this would be a pretty common request to keep all links and file paths universal and versatile in case you want to migrate or clone your site to a different domain in the future.

    Any help is greatly appreciated…thanks in advance!

  • Seems like this would be a pretty common request to keep all links and file paths universal and versatile in case you want to migrate or clone your site to a different domain in the future.

    Any help is greatly appreciated…thanks in advance!

  • Hi @john.marcello

    If your client enters a link such as this:
    http://www.website.com

    Then, when you migrate the website and change the domain, you would simple do a find and replace in the SQL export file.

    So you would find ‘www.website.com’ and replace with ‘www.website.com.au’

    Hope that helps

    Thanks
    E

  • Elliot:

    Not really sure this answers my question. It might be a work around for domains, but it requires a programmer. Most end-users are not that saavy.

    I do not use a SQL export file anyways for migration, typically just use a tool like WP Twin. Plus, I know that there may clearly be other instances where I want PHP to execute in the input fields…

    Any help on this is greatly appreciated…

    Regards,
    John

  • Hi @john.marcello

    I would jump on google and see what you can find as possible solutions for URL strings and migration.

    Because this is a simple text value, the issue is not 100% related to the ACF plugin, it is a common WP / Web issue.

    On projects of my own, I would not allow my client to enter PHP into a string. This is simply asking for problems. Instead, I would allow them to enter a string url, or perhaps use a post_object field type to link to a post / page?

    There is a great plugin called ‘Migrate DB Pro’ which will pull / push DB to another website and also do a string replace for urls!

    Thanks
    E

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Execute PHP In Text Field?’ is closed to new replies.