Accessing WP core with my PHP script - php

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.

Related

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

creating wordpress theme using bootstrap and having issues with registering menu area

I am trying to create a WordPress theme from scratch using bootstrap
I am using a file I got from GitHub and have implemented a lot of things from it. You can find it in Github . The name is :
twittem/wp-bootstrap-navwalker
now I am creating menus / registering menu area and have used the following code :
<?php
require_once('wp_bootstrap_navwalker.php');
//theme support
function theme_setup(){
//nav menu
register_nav_menus(array(
'primary' => __('Primary Menu')
));
}
//for the above function to work we need tocreate an addaction function, which lets us choose a hook to run it
//the one we want is aftr set up theme
add_action('after_setup_theme','wpb_theme_setup');
After doing this the menu shows up but there is an error above it which is :
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wpb_theme_setup' not found or invalid function name in C:\wamp\www\wordpress-bootstrap\bootstrap\wp-includes\plugin.php on line525
Call Stack
# Time Memory Function Location
1 0.0005 241464 {main}( ) ..\index.php:0
2 0.0007 244632 require( 'C:\wamp\www\wordpress-bootstrap\bootstrap\wp-blog-header.php' ) ..\index.php:17
3 0.0011 264688 require_once( 'C:\wamp\www\wordpress-bootstrap\bootstrap\wp-load.php' ) ..\wp-blog-header.php:13
4 0.0016 275768 require_once( 'C:\wamp\www\wordpress-bootstrap\bootstrap\wp-config.php' ) ..\wp-load.php:37
5 0.0027 402232 require_once( 'C:\wamp\www\wordpress-bootstrap\bootstrap\wp-settings.php' ) ..\wp-config.php:89
6 0.3356 21979856 do_action( ) ..\wp-settings.php:377
7 0.3357 21981408 call_user_func_array:{C:\wamp\www\wordpress-bootstrap\bootstrap\wp-includes\plugin.php:525} ( )
I dont know how to solve this error or what to do about it. Can someone please help.
Change function theme_setup(){ to function wpb_theme_setup(){
The hook add_action('after_setup_theme','theme_setup'); is trying to call a function that doesn't exist.

Joomla's triggerEvent not working

I tried to call the jooomla triggerEvent function for rsform Pro's payment plugin from an external php file.
But I keep getting 500 errors and my server error log didn't cache the error code.
Below is my code and I also added my reference.
Please help me to find out the error source.
Thank you in advance.
define( '_JEXEC', 1 );
define('JPATH_BASE', '../');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once (JPATH_BASE. '/plugins/system/rsfppayment/rsfppayment.php');
jimport('joomla.application.component.controller');
$updatedSubmissionId = 168;
$mainframe = JFactory::getApplication();
$mainframe->triggerEvent('rsfp_afterConfirmPayment', array($updatedSubmissionId));
Its better to make your own function for your plugin then to use a function from another plugin. But I will give a short note on method to call plugins inside your own plugin code(latest for Joomla 3+):
Step 1:
Call JPluginHelper::importPlugin( 'plugingroup' );
plugingroup can be system or plugin folder where rsfppayment plugins are located.
Step 2:
$dispatcher = JEventDispatcher::getInstance();
Step 3:
$results = $dispatcher->trigger( 'rsfp_afterConfirmPayment', array($updatedSubmissionId) );
The below code should do the trick - a 'little' more information can be found on the docs.joomla.org site https://docs.joomla.org/Triggering_content_plugins_in_your_extension.
// Note JDispatcher is deprecated in favour of JEventDispatcher in Joomla 3.x however still works.
JPluginHelper::importPlugin('system');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('rsfp_afterConfirmPayment', array($updatedSubmissionId));

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.

Parse Error! using wordpress

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.

Categories