Undefines function get_field() on PLESK Schedulation Tasks - wordpress

I'm trying to create a schedule script php from PLESK but i have a problem when i've use get_field() function from ACF.
Plesk retriew the error:
" PHP Fatal error: Uncaught Error: Call to undefined function get_field()..... "
I have the same problem with all function called from Wordpress.
The code inside the PHP script is:
$my_var = get_field('indirizzo_ip','options');
echo $my_var;
Can someone help me?
Thanks

Include these files at the top of your script and you`ll have all the WordPress functions available:
define('WP_USE_THEMES', false);
require('/path/to/your/httpdocs/wp-blog-header.php');
require('/path/to/your/httpdocs/wp-admin/includes/admin.php');
Regards Tom

Related

Unable to send mail (Wordpress and AWS)

Context:
I am using Amazon Web Services to build and run a Wordpress site.
Issue:
The problem I have is with sending e-mails from the site. I also installed the plugin "Post SMTP". The error message I am getting is "Email could not be resent. Error: Unable to send mail. ".
What I tried so far:
I reached out to AWS and they wrote me to use Amazon SES service. I have created and configured an identity on SES. The issue is still there.
I don't know where to look anymore. Can anyone help who faced same or similar issues?
Thanks!
Check if the phpmail function is working properly. You can use the following code to check it.
<?PHP
$sender = 'someone#somedomain.tld';
$recipient = 'you#yourdomain.tld';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
Create a php test file using a text editor and save it e.g. as test.php
Change the $sender and $recipient in the code.
Upload the php file to your webserver.
Open the uploaded php file in your browser to execute the php script.
The output show either "Message accepted" or "Error: Message not accepted".
If it's showing "Error: Message not accepted"Tell your provider that the standard php "mail()" function returns FALSE.
It's recommended to include the used php test script to show your provider, that the problem is not caused by the php script used.

when i display my wordpress website post on other php script which resides in the same directory

It is not Displaying it and when enable ERROR REPORTING to Check Issue it Show me Fatal error: Cannot redeclare clean_url() (previously declared in /home/a107853262/public_html/TECHNICALLY-SPEAKING.ORG/small-seo-tools/core/functions.php:237) in /home/a107853262/public_html/TECHNICALLY-SPEAKING.ORG/wp-includes/deprecated.php on line 2039. Thank in Advance
You are trying to re-declare the function clean_url().
Refer this answer
Also clean_url() is deprecated and should be replaced by esc_url(). WordPress Code Reference

Can you use odbc_connect() on openshift?

In openshift this code
<?php
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
~
returns
PHP Fatal error: Call to undefined function odbc_connect()
Can you use odbc_connect() on openshift?
I do not believe that OpenShift includes the iODBC driver, you can check for sure by creating a php page with the following contents and then checking it for iODBC support
<?php
phpinfo();
You should add your request to have iODBC support at https://ideas.openshift.com and get people to vote on it.

User Friendly Error page in Symfony2

Whenever I am getting error like Fatal error: Call to a member function getName() on a non-object in /var/www/...Controller.php on line 143, My symfony2-app shows a blank page in prod-environment. The above message available in dev-environment. I want to show a custom page in prod-environment for such errors. How can I implement it in Symfony2?
Update:
May kernel.event_listener help me?
You cannot really implement that in symfony. Fatal errors are not handled by symfony but by the PHP extension itself. The Symfony code never gets a chance to finish executing because of the fatal error leaving php to handle the error by its own devices. PHP error handling is set by error_reporting() and the error_handler set by set_error_handler(). In the dev environment, php error reporting is set to E_ALL to show all errors. In a production environment, errors and debug messages are set to 0 and are not displayed for aesthetic and security reasons (some error messages may display password, etc). The best advice would be to fix all fatal errors before deploying to production. To catch and display a custom page for fatal errors must be done using php set error handling - http://php.net/manual/en/function.set-error-handler.php.
For non-fatal errors, you can create a custom error page view that can be displayed - http://symfony.com/doc/2.0/cookbook/controller/error_pages.html
I do it this way:
class ErrorExceptionHandler {
function __construct() {
register_shutdown_function(array($this, 'fatalErrorHandler'));
}
function fatalErrorHandler() {
$error = error_get_last();
if ($error['type'] === E_ERROR) {
header('Location: /error-page-url');
}
}
}
ErrorExceptionHandler(); // add to app.php
Of course please remember about namespace etc.

Error While Activating A New WordPress Plugin

I m learning to develop plugin and I am getting error on activation saying
The plugin generated 157 characters of unexpected output during
activation. If you notice “headers already sent” messages, problems
with syndication feeds or other issues, try deactivating or removing
this plugin.
I tried removing and making a new one but same error. here is my code (basic PHP comment to start a plugin, nothing fancy).
/*
Plugin Name: Awesomeness
Plugin URI: http://www.example.com/
Author URI: http://www.example.com/
Author: abc
Description: Just a fun plugin
*/
function fubs(){
error.log("this is working");
}
register_activation_hook(__FILE__,'fubs');
There is no white space before or ending on PHP code.
error is an undefined constant in your PHP code. You try to mix JavaScript with PHP, so PHP prints an error message.
Solution: Use PHP code in PHP and JavaScript code in JavaScript.

Resources