This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
I am very new to coding - I was actually just trying to learn to edit an old website for a friend using WordPress, to make it more visually appealing and fresh.
Everything was way out of date, so I backed up the site, then started updating things in what I thought was the right order, but I was probably wrong since once I updated the plugins I got a Parse Syntax error and can't get into the wp-admin now.
I went through the steps in this tutorial (using FileZilla and Notepad++) to try and fix it, but it keeps giving me a new Parse Syntax error in the same file. Now I'm worried I'm just making things worse in there and I'm not certain what I should do.
The initial error was an unexpected "[" (or "]"? idr now...) on line 344, so I thought I needed to just get rid of it, but I don't think I was right. This is the error I have now, after trying to change things 2-3 times:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/67/14065667/html/wp-content/plugins/page-links-to/classes/plugin.php on line 346
Here is the section of coding I've been having issues in (lines 340-351):
public function enqueue_block_editor_assets() {
// Gutenberg.
if ( self::is_block_editor() && self::is_supported_post_type() ) {
wp_enqueue_script( 'plt-block-editor', $this->get_url() . 'dist/block-editor.js', array( 'wp-edit-post', 'wp-element', 'wp-plugins' ), self::CSS_JS_VERSION, true );
wp_localize_script( 'plt-block-editor', 'pltOptions',
'supports'
'newTab' => self::supports( 'new_tab' ),
],
]);
do_action( 'page_links_to_enqueue_block_editor_assets' );
}
}
What can I try to fix this?
Seems your argument list for wp_localize_script is malformed. It should be something like
wp_localize_script( string $handle, string $object_name, array $l10n )
Address that and you should be good. Without more context of what should belong to the $handle, $object_name and $l10n, can't fully type an answer to clear it up.
WP Localized Script Docs
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
Syntax error while using this code , An example from paymentwall
$widget = new Paymentwall_Widget(
''. $_SESSION['PLR_ACCOUNT']['PLR_ID'] .'',
'p10_1',
array(
new Paymentwall_Product(
'product2',
9.99,
'USD',
'Elite 3 months',
Paymentwall_Product::TYPE_SUBSCRIPTION,
1,
Paymentwall_Product::PERIOD_TYPE_MONTH,
true
),
array(
'email' => 'user#hostname.com',
'history[registration_date]' => 'registered_date_of_user',
'ps' => 'all'
)
echo $widget->getUrl();
)
}
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ')'
in C:\Users\Arlindi\Desktop\X-Portal - V2.6.8 -
FINAL\test-server\root\pages\premium_info.php on line 301
Line 301 is
echo $widget->getUrl();
How to solve it ?
Look at your code context!
When you get syntax error it means you have typo or your code is somehow wrong
as in PHP parse/syntax errors; and how to solve them? explained when you see syntax error,
Always look at the code context. The syntax mistake often hides in the mentioned or in previous code lines. Compare your code against
syntax examples from the manual.
In your example you used echo in your function argument and after array(...)
It is not right in php
function(array(...)echo something;) is not correct syntax in php
As you didn't say what you want your code actually do, I don't know what can be your correct code but I guess you should close Paymentwall_Widget() parentheses before echo and put one semicolon after the parentheses before echo line
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I'm coding a custom Woocommerce theme. All works well in local, but when I deploy on my server, this error occurs when I go to a product details:
Parse error: syntax error, unexpected end of file in /wp-content/themes/customtheme/content-single-product.php on line 231
Here's the concerned file code (Pastebin since it's a big amount of code and it display the lines number) : https://pastebin.com/bzgLQTmD
I really don't know where is this error given that I don't have it in local development.
I tried code validators, but they didn't gave me any clues.
The problem is with short tags, which are not enabled by default. So, either enable them from php.ini or
Change all of these:
<? endif; ?>
To Proper full tags like:
<?php endif; ?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Hey I am trying to add a customize option in a wordpress theme that allows for the user to upload there own image in in a showcase but im getting a syntax error in my customize.php file. Can any one help me write this the correct way? thanks!
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/themes/wpbootstrap/inc/customizer.php on line 13
$wp_customize->add_setting('showcase_image', array(
'default' => get_bloginfo('template_directory').'/img/showcase.jpg', 'wpbootstrap'),
line 13 'type' => 'theme_mod'
));
Without spoon feeding the answer (as requested to #community above), but giving a re-usable technique to find these types of bugs ...
Temporarily reformat your code so all function paramters and/or array elements are on their own line and using identing appropriately. Eventually you'll likely see something that is not what you intended. Example below (you're almost there).
$wp_customize->add_setting(
'showcase_image', // func parm
array(
'default' => get_bloginfo(
'template_directory'
).'/img/showcase.jpg',
'wpbootstrap'
),
'type' => 'theme_mod'
)
);
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
When attempting to bake views, I consistently get stopped with syntax errors as follows:
Parse error: syntax error, unexpected '$this' (T_VARIABLE), expecting identifier (T_STRING) in /vagrant/lib/Cake/Console/Templates/default/views/index.ctp on line 27
The context for the code causing the error here doesn't seem problematic to me.
<?
foreach ($fields as $field):
if (!in_array($field, array('created', 'body', 'description', 'position', 'slug'))) {
echo "\t\t<th><?php echo $this->Paginator->sort('{$field}'); ?></th>\n";
}
endforeach;
?>
It seems to have problems because it is trying to interpret the code it should generate in the string as code it should run, and thus thinks the string '$this->Paginator->sort(...)' is an object variable calling a function, and so on.
I am running PHP 5.3.37-1 on Ubuntu Trusty x64 on a Vagrant box.
You really shouldn't modify the core, actually you souldn't modify any vendor files at all! If you need custom bake output, then do it the proper way as described in the docs:
Cookbook > Shells, Tasks & Console Tools > Code Generation with Bake > Modify default HTML produced by “baked” templates
That being said, you are using double quotes, hence $ has a special meaning, to actually echo a $ you have to escape it using \, ie like this:
echo "\t\t<th><?php echo \$this->Paginator->sort('{$field}'); ?></th>\n";
Which is also what is used in the original bake template. Also, as mentioned in another answer, do not use short open tags!
Don't use short tags: <?
Use <?php to open a PHP script and use <?= to echo when out of PHP.
As others are saying it is a simple syntax error. If you have trouble seeing syntax errors, or understanding what your logs are telling you, you may want to consider using an IDE that would help highlight these mistakes.
<?php
foreach ($fields as $field) {
if (!in_array($field, array('created', 'body', 'description', 'position', 'slug'))) {
echo "\t\t<th>" . $this->Paginator->sort($field) . "</th>\n";
}
}
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am trying to fopen() a debugging text file, which I have simply named debug.txt and put it on my desktop. I am using PHP. My code is simply
$debug_file = fopen( "C:\\Users\\joe\\Desktop\\debug.txt", "w" );
I keep getting this error
Parse error: syntax error, unexpected '$debug_file' (T_VARIABLE) ` on line 755, which is the line of code above.
I have checked the code before this line for a missing semicolon, as that often is the source of a syntax error, but the previous code is fine. If I comment out my one line of code, the PHP file no longer gives a syntax error.
I was thinking that there is something wrong with the way I write the string literal file path to open. I have tried to make it ok by escaping the backslashes. I'm using Windows 10. But that hasn't fixed the problem. For the life of me I can't figure out what the syntax error is.
Thanks for any help.
EDIT: As requested, the previous lines of code are:
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}
The problem is the line(s) above, you either didn't end it with a semicolon or there's an open bracket, or something along those lines.