When I enable the plug-in "crayon-syntax-highlighter" version 2.8.4, my website shows nothing in each page.
---Error message:----
Fatal error: Uncaught Error: Call to a member function id() on array in
/var/www/it/wp-content/plugins/
crayon-syntax-highlighter/crayon_formatter.class.php:36
Try to modify this file : crayon_langs.class.php
File location: /wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php
Going to line# 340
[Before]
return preg_replace('/[^\w-+#]/msi', '', $id);
Need to add a '' behind w
[After]
return preg_replace('/[^\w\-+#]/msi', '', $id);
refer to https://crunchify.com/fix-for-crayon-syntax-highlighter-wordpress-plugin-and-php-7-3-fatal-error
Related
I started with facebook business sdk for php. Was following this doc: https://developers.facebook.com/docs/business-sdk/getting-started/ installed without trouble, then tried testing as they instructed, created src/test.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
$app_id = "{app-id}";
$app_secret = "{appsecret}";
$access_token = "{access-token}";
$account_id = "act_{{adaccount-id}}";
Api::init($app_id, $app_secret, $access_token);
$account = new AdAccount($account_id);
$cursor = $account->getCampaigns();
// Loop over objects
foreach ($cursor as $campaign) {
echo $campaign->{CampaignFields::NAME}.PHP_EOL;
}
filled in the required values. and ran the file. Getting this:
FacebookAds\CrashReporter : Enabled
FacebookAds\CrashReporter : Error detected!
PHP Catchable fatal error: Argument 1 passed to FacebookAds\CrashReporter::buildParamsFromException() must be an instance of Throwable, instance of ErrorException given, called in /var/www/clients/client1/web1/web/vendor/facebook/php-business-sdk/src/FacebookAds/CrashReporter.php on line 146 and defined in /var/www/clients/client1/web1/web/vendor/facebook/php-business-sdk/src/FacebookAds/CrashReporter.php on line 167
Not sure what I am doing wrong. Didnt find much by searching. Can anyone please help?
i have read many pages to find out howto create a simple endpoint into my simple WP-Plugin.
links of good articles i have read for that:
https://developers.shopware.com/developers-guide/rest-api/plugin-api-extension/ , https://wptips.dev/custom-rest-api/ , https://torquemag.io/2016/07/adding-custom-endpoints-extra-touches/ , https://www.cloudways.com/blog/wordpress-rest-api-to-fetch-posts/#get-wp-v2-posts , https://www.cloudways.com/blog/wordpress-rest-api-to-fetch-posts/#wordpress-rest-api-using-json , https://developer.wordpress.org/rest-api/
this gives me most hope to get success with it and i used the source from here:
https://stackoverflow.com/a/64331655/2891692
My URL i using in Web-Browser:
http://localhost/wordpress/wp-json/a0plugin/v1/testing
excerpt of my complete source from gist
htdocs/wp-content/plugins/a0plugin/a0plugin.php
<?php
/**
* Plugin Name: a0plugin
*/
function at_rest_testing_endpoint(){
return new WP_REST_Response('Howdy!!');
}
function at_rest_init(){
$namespace = 'a0plugin/v1';
$route = 'testing';
register_rest_route($namespace, $route, array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'at_rest_testing_endpoint'
));
}
add_action('rest_api_init', 'at_rest_init');
?>
complete source:
https://gist.github.com/sl5net/10d21e8bd358b9149968885a93862424
SyntaxError: JSON.parse
Error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
if the comments are left out, the error disappears. these are not listed in the so-called relevant source text excerpt. the cause is unknown to me.
When I run the file on my localhost it works, but when i upload it to my server using winSCP, I'm getting this error
PHP Fatal error: Uncaught Mpdf\MpdfException: Temporary files directory "E:\Inetpub\vhosts\gsm.org.my\httpdocs\print/custom/temp/dir/path" is not writable in E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\vendor\mpdf\mpdf\src\Cache.php:17
Stack trace:
#1 E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\vendor\mpdf\mpdf\src\Mpdf.php(1054): Mpdf\ServiceFactory->getServices(Object(Mpdf\Mpdf), Object(Psr\Log\NullLogger), Array, 0, Object(Mpdf\Language\LanguageToFont), Object(Mpdf\Language\ScriptToLanguage), NULL, NULL, NULL, NULL)
#2 E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\print-form.php(88): Mpdf\Mpdf->__construct(Array)
#3 {main} thrown in E:\Inetpub\vhosts\gsm.org.my\httpdocs\print\vendor\mpdf\mpdf\src\Cache.php on line 17
Is it because the server couldn't find the file path or I wrote it wrong?
I tried giving permission on folder src but it said cannot change properties of file src. I am a beginner in this field. I tried search the solution on google regarding this error but I couldn't find anything.
In case you want to give mPDF another try:
it seems you are not providing the proper configuration to mPDF but we can't tell for sure as that part of your code (line 88 of your print-form.php) is missing. Taken from my last code using mPDF:
try {
$mpdf = new \Mpdf\Mpdf([
'tempDir' => __DIR__ . '/../tmp', // uses the current directory's parent "tmp" subfolder
'setAutoTopMargin' => 'stretch',
'setAutoBottomMargin' => 'stretch'
]);
} catch (\Mpdf\MpdfException $e) {
print "Creating an mPDF object failed with" . $e->getMessage();
}
Line 17 in Cache.php is part of the Cache constructor and throws an error in case the temporary directory is either not writable or not a directory:
// taken from method "createBasePath($basePath)"
if (!is_writable($basePath) || !is_dir($basePath)) {
return false;
}
To test if you see the error due to insufficient file permissions or a non-existing directory, upload a file with this content to your server and navigate to it with your preferred browser:
<?php
$pathToCheck= "E:\\Inetpub\\vhosts\\gsm.org.my\\httpdocs\\print//custom//temp//dir//path";
print 'Folder exists: '.(is_dir($pathToCheck) ? 'yes' : 'no').'<br />';
print 'Folder is writable: '.(is_writable($pathToCheck) ? 'yes' : 'no').'<br />';
You are on a Windows server so you will need to add the right user to the "tmp" folder under "Properties"->"Security", additionally check if the folder has the Attribute "Read-only" unticked.
Additional advice:
Please post relevant code in your future question (like the relevant portions of your print-form.php) as this reduces the risks of having to guess what might be the cause.
My site uninstalled all plugins so I reactivated and since then I have been greeted by Error 500 everytime I try to get to Customise (WP).
I checked out error_log and it's pointing to the funtions.php line 659 (starts 3rd line down):
function thrive_exclude_category($query)
{
$hide_cat_option = thrive_get_theme_options('hide_cats_from_blog');
if (!is_string($hide_cat_option)) {
$hide_cat_option = "";
}
$hide_categories = is_array(json_decode($hide_cat_option)) ? json_decode($hide_cat_option) : array();
$temp_query_string_part = "";
foreach ($hide_categories as $temp_cat_id) {
$temp_query_string_part .= "-" . $temp_cat_id . " ";
}
This is probably simple stuff, however, I suck. I have been lumbered with maintaining the sites and really have no say in the matter. Thanks in advance
In one of the projects I found this problem too. After study logs and debug project I find this function don't know about another function which used in theme PHP message: PHP Fatal error: Uncaught Error: Call to undefined function thrive_get_theme_options(). The main problem here in filter which running before all files will be included in theme. So function thrive_exclude_category don't find where declared thrive_get_theme_options because pre_get_posts running before we included files:
add_filter('pre_get_posts', 'thrive_exclude_category')
We need run this filter after use after_setup_theme
function run_func(){
add_filter('pre_get_posts', 'thrive_exclude_category', 999);
}
add_action('after_setup_theme', 'run_func`);
After this you not get any error and you can use your filter.
Try reactivate all plugins required by Thrive theme because of Fatal: Call to undefined function thrive_get_theme_options()
I'm making a custom form action.php and currently it looks like this:
<?php
// Collect Data
$first = $_POST["first_name"];
$last = $_POST["last_name"];
$email = $_POST["email"];
$pass = $_POST["password"];
$pass2 = $_POST["confirm_password"];
$cat = $_POST["category"];
$tAndC = $_POST["terms_and_conditions"];
$privacy = $_POST["privacy_policy"];
$newsletter = $_POST["newsletter"];
die();
?>
Essentially nothing going on - the problem though is when I want to call a WordPress hook such as something like this:
$user_name = $email;
$user_id = username_exists( $user_name );
it returns an error:
Fatal error: Call to undefined function username_exists()...
I'm aware that there are probably header files I am not calling for the 'undefined function' to actually run.
I have tried adding at the top of the page: wp_head(); - but I get the following error:
Fatal error: Call to undefined function wp_head()
Include
$base_dir = dirname(dirname(__FILE__));
require_once($base_dir."/wp-load.php");
With your desired path and check
Include wp-load.php file (in the root of your wordpress installation) in your php script file like so,
require_once("/path/to/wordpress/wp-load.php");
you will have to provide the abspath of the wp-load file, now you can use all the functions of wordpress in your php script.