Parse Error! using wordpress - php

Here is the error I'm getting:
Parse error: syntax error, unexpected '' );' (T_ENCAPSED_AND_WHITESPACE) in /htdocs/index.php on line 17
Here is the index.php code:
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* #package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* #var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . ‘/wordpress/wp-blog-header.php' );
I know it's something simple, but I can't figure it out!

I think You have a syntax error on this line:(Look at the opening and ending single quotes, they are look different)
require( dirname( __FILE__ ) . ‘/wordpress/wp-blog-header.php' );
the correct one should be like this:
require(dirname( __FILE__ ) . '/wordpress/wp-blog-header.php');
hope this will help you.

Related

Wordpress problem, fail to open stream in function.php

I'm getting this weird message while trying to enter some of the pages of my WordPress.
Warning: require_once(/home3/alexismoyano/calendario/calendario/wp-content/themes/twentynineteen/includes/bootstrap.php): failed to open stream: No such file or directory in /home3/alexismoyano/calendario/calendario/wp-content/themes/Avada/functions.php on line 51
Fatal error: require_once(): Failed opening required '/home3/alexismoyano/calendario/calendario/wp-content/themes/twentynineteen/includes/bootstrap.php' (include_path='.:/opt/php70/lib/php') in /home3/alexismoyano/calendario/calendario/wp-content/themes/Avada/functions.php on line 51
I don't understand what could it be, it seems to be related to the theme "Twentnineteen" despite I'm not even using it.
This is what it's on LINE 51:
This is what it says on line 51:
LINE 51 : " require_once get_template_directory() . '/includes/bootstrap.php'; "
/**
* Check that the site meets the minimum requirements for the theme before proceeding.
* #since 6.0
*/
if ( version_compare( $GLOBALS['wp_version'], AVADA_MIN_WP_VER_REQUIRED, '<' ) || version_compare( PHP_VERSION, AVADA_MIN_PHP_VER_REQUIRED, '<' ) ) {
require_once get_template_directory() . '/includes/bootstrap-compat.php';
return;
}
/**
* Bootstrap the theme.
*
* #since 6.0
*/
require_once get_template_directory() . '/includes/bootstrap.php';
Does someone know how can I solve it?
Based on your comments, it looks like the twentynineteen theme is set as a template theme, and Avada is set as a child theme.
The function get_template_directory() is identical to get_stylesheet_directory() except for the fact it looks at the Template/Parent theme first instead of the current (child) theme.
Take a look at the documentation for Child Themes. You'll notice there's a comment block at the top of the style.css file that determines the parent/template theme, as an example:
/*
Theme Name: Some Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentynineteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
You see in line in there Template: twentynineteen, that's telling your active theme to use that as a parent theme.
Now, I'm not familiar with Avada, but is it supposed to be a child theme of Twentynineteen? I don't believe so, but if it is, try reinstalling the twentynineteen theme. If it's not supposed to be, then make sure you don't have a Template: twentynineteen line in your style.css file.
If neither of those things work, you could also try replacing the get_template_{…}() functions with get_stylesheet_{…}() functions, but those would get reverted if/when you updated the theme.

Class 'Timber' not found when running timber-starter-theme

I have recently installed Timber on to my WordPress instance but whenever I try to run single.php for the timber-starter I get the following error:
Fatal error: Uncaught Error: Class 'Timber' not found in
www\Website\wp\wp-content\plugins\timber-library\timber-starter-theme\single.php:12
Stack trace: #0 {main} thrown in
www\Website\wp\wp-content\plugins\timber-library\timber-starter-theme\single.php
on line 12
I have read that there can be issues with namespace and to update it to Timber\Timber. I have tried this also and get the same class not found for Timber\Timber. Interestingly, if I open it in PHPStorm I can navigate to the function directly from the class call so it is able to recognise it there.
Does anyone have any ideas? I've tried different versions of PHP, different versions of WordPress and installing via WP-Admin and manually. None of these options are fixing this issue. (Please note, I also get this error for going to index.php in this directory).
Here is the code from single.php with the added namespace definition.
<?php
/**
* The Template for displaying all single posts
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* #package WordPress
* #subpackage Timber
* #since Timber 0.1
*/
use Timber\Timber;
$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
if ( post_password_required( $post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );
}
It must seems trivial, but this error is commonly caused by a misinstallation.
If you use Timber as a plugin, check if it is activated.
If you have installed trough a package manager, check you have used the right package name composer require timber/timber.
You can also try to remove your package and re-install it.
If all is correct, check your functions.php, myabe there is a misuse of the Timber Instance

How to create a new php file which uses wp's functions and wp's connection

I need to create a very simple REST API (GET ONLY BY NOW)
but tables for query are not native of wordpress then I need to create a new php file,
this is not going to be a template
then how can I Access to wordpress functions and wordpress connection object for not create a new mysql connection object.
I tried but I got
Call to a member function get_results()
thanks
<?php
/**
* api
* #package accesspresslite
*/
define( 'SHORTINT',true);
require_once('./wp-load.php')
global $wpdb;
$results = $wpdb->get_results('select email from wp_wysija_user',OBJECT);
?>
This is the path where wp-load.php file is.
and i got
Parse error: syntax error, unexpected 'global' (T_GLOBAL) in C:\xampp\htdocs\IniYuc\wp-content\themes\accesspress-lite-child\api.php on line 11
You can load the wordpress functions/objects from outside the framework. Consider the following code:
define( 'SHORTINIT', true );
require_once(PATH_TO_YOUR_INSTALLATION . '/wp-load.php' );
Afterwards, alle the known objects (e.g. $wpdb) will be present.
Create a new php file in your THEME directory like:
wp-content/themes/accesspress-lite-child/NEW-FILE.php
And put the bellow lines at top of the file:
<?php
define( 'SHORTINIT', true );
//Add file from = C:\xampp\htdocs\IniYuc\
require_once('../../../wp-load.php' );
Note: set the proper path to wp-load.php so it loads the required file.
You can use WP functions now.

Accessing WP core with my PHP script

I'm trying to create a script that would download and install wordpress + plugins + themes automatically.
All the stages until installing are working out. The files are downloaded and the wp-config.php is working - but when I try to run the wp install I get the following error:
Fatal error: Call to undefined method stdClass::add_query_var() in C:\Apache24\htdocs\wp\wp\wp-includes\taxonomy.php on line 371
From doing some research - it seems that the problem is finding the right way to include wordpress functions in my script - this is my code
define( 'WP_INSTALLING', true );
global $wp;
require_once( $directory . 'wp-blog-header.php' );
/** Load WordPress Bootstrap */
require_once( $directory . 'wp-load.php' );
/** Load WordPress Administration Upgrade API */
require_once( $directory . 'wp-admin/includes/upgrade.php' );
/** Load wpdb */
require_once( $directory . 'wp-includes/wp-db.php' );
var_dump($wp);
// WordPress installation
wp_install( $data[ 'weblog_title' ], $data['user_login'], $data['admin_email'], (int) $data[ 'blog_public' ], '', $data['admin_password'] );
in taxonomy line 371 theres a function call :
$wp->add_query_var( $args['query_var'] );
I suspect that $wp never gets defined.
Does anyone know what I should change to do that?
I made sure that it crashes on the wp_install - never goes past that in my script.

Error when migrating wordpress site from subfolder to root folder

This is what I'm seeing in the browser, after going through the steps at http://wp.smashingmagazine.com/2013/04/08/moving-wordpress-website/
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home4/brycepj/public_html/index.php on line 17
Parse error: syntax error, unexpected '.' in /home4/brycepj/public_html/index.php on line 17
Here's the code from the relevant file:
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* #package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* #var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require ('./dev/wp-blog-header.php);
What am I missing? Thanks in advance!
Figured it out! Just missing an apostrophe after the wp-blog-header.php --- if you're using Smashing Magazine's tutorial, this is your problem. I copy and pasted directly from their post.

Categories