It may be a silly question, but I cant understand how I can access every function (from functions.php for example) in WordPress without any include or require calls, I know if I want to create a new script I can simply require wp-load.php from that particular script, just dont understand why this is isn't needed in other template files.
WordPress does that automatically. Whenever there is a functions.php file for the active theme, WP will load it for you. The magic happens in wp-settings.php, specifically among the following lines:
if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
include( TEMPLATEPATH . '/functions.php' );
}
Related
I'm trying load my websites Wordpress page but get the error
Warning: require(__DIR__/wp-load.php) [function.require]: failed to open stream: No such file or directory in /home/content/39/4124639/html/wp-login.php on line 12
Fatal error: require() [function.require]: Failed opening required '__DIR__/wp-load.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/39/4124639/html/wp-login.php on line 12
Inside the wp-login.php file on line 12 is: require __DIR__ . '/wp-load.php';
I confirmed the file wp-load.php is there. Can someone help?
I haven't changed my wp-blog-header.php file it is:
<?php
/**
* Loads the WordPress environment and template.
*
* #package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
// Set up the WordPress query.
wp();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
The wp-load.php file is (I haven't messed around with it either):
<?php
/**
* Bootstrap file for setting the ABSPATH constant
* and loading the wp-config.php file. The wp-config.php
* file will then load the wp-settings.php file, which
* will then set up the WordPress environment.
*
* If the wp-config.php file is not found then an error
* will be displayed asking the visitor to set up the
* wp-config.php file.
*
* Will also search for wp-config.php in WordPress' parent
* directory to allow the WordPress directory to remain
* untouched.
*
* #package WordPress
*/
/** Define ABSPATH as this file's directory */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
/*
* If wp-config.php exists in the WordPress root, or if it exists in the root and wp-settings.php
* doesn't, load wp-config.php. The secondary check for wp-settings.php has the added benefit
* of avoiding cases where the current directory is a nested installation, e.g. / is WordPress(a)
* and /blog/ is WordPress(b).
*
* If neither set of conditions is true, initiate loading the setup process.
*/
if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
/** The config file resides in ABSPATH */
require_once ABSPATH . 'wp-config.php';
} elseif ( #file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! #file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
/** The config file resides one level above ABSPATH but is not part of another installation */
require_once dirname( ABSPATH ) . '/wp-config.php';
} else {
// A config file doesn't exist.
define( 'WPINC', 'wp-includes' );
require_once ABSPATH . WPINC . '/load.php';
// Standardize $_SERVER variables across setups.
wp_fix_server_vars();
require_once ABSPATH . WPINC . '/functions.php';
$path = wp_guess_url() . '/wp-admin/setup-config.php';
/*
* We're going to redirect to setup-config.php. While this shouldn't result
* in an infinite loop, that's a silly thing to assume, don't you think? If
* we're traveling in circles, our last-ditch effort is "Need more help?"
*/
if ( false === strpos( $_SERVER['REQUEST_URI'], 'setup-config' ) ) {
header( 'Location: ' . $path );
exit;
}
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
require_once ABSPATH . WPINC . '/version.php';
wp_check_php_mysql_versions();
wp_load_translations_early();
// Die with an error message
$die = sprintf(
/* translators: %s: wp-config.php */
__( "There doesn't seem to be a %s file. I need this before we can get started." ),
'<code>wp-config.php</code>'
) . '</p>';
$die .= '<p>' . sprintf(
/* translators: %s: Documentation URL. */
__( "Need more help? <a href='%s'>We got it</a>." ),
__( 'https://wordpress.org/support/article/editing-wp-config-php/' )
) . '</p>';
$die .= '<p>' . sprintf(
/* translators: %s: wp-config.php */
__( "You can create a %s file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file." ),
'<code>wp-config.php</code>'
) . '</p>';
$die .= '<p>' . __( 'Create a Configuration File' ) . '';
wp_die( $die, __( 'WordPress › Error' ) );
}
First, sorry for my english.
I am developing a web application that works on wordpress. I have a folder called GSC, and inside it is my application.
The problem I have, is when I have to control access to users to that directory since all that part will be private, only for registered users.
I have tried with some plugin as wishlist member and only protects the main folder and has no control in subfolders so the application fails since it can not load all the necessary.
So I've searched everywhere and I can not find any more plugin, or I do not know if I should be by programming in each php file controlling if there is a user session, or if wordpress has something else to control access to folders, even look if it you can configure htaccess so that it depends on wordpress users but I do not know if you can.
If someone can give me some idea.
Thank you
Update:
My htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*gsc/formulario-clientes/.*
RewriteRule ^(.*)$ /wp-private.php?file=$1 [QSA,L]
Wp-private.php
<?php
/*
* dl-file.php
*
* Protect uploaded files with login.
*
* #link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* #author hakre <http://hakre.wordpress.com/>
* #license GPL-3.0+
* #registry SPDX
*/
require_once('wp-load.php');
require_once ABSPATH . WPINC . '/formatting.php';
require_once ABSPATH . WPINC . '/capabilities.php';
require_once ABSPATH . WPINC . '/user.php';
require_once ABSPATH . WPINC . '/meta.php';
require_once ABSPATH . WPINC . '/post.php';
require_once ABSPATH . WPINC . '/pluggable.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
$path = get_home_path()."gsc" ;
is_user_logged_in() || auth_redirect();
//list($basedir) = array_values(array_intersect_key(wp_upload_dir(), array('basedir' => 1)))+array(NULL);
$basedir = $path;
$file = rtrim($basedir,'/').'/'.str_replace('..', '', isset($_GET[ 'file' ])?'formulario-clientes/'.$_GET[ 'file' ]:'');
if (!$basedir || !is_file($file)) {
status_header(404);
// wp_redirect(home_url());
die('404 — File not found.'.$file);
exit();
}
$mime = wp_check_filetype($file);
if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) )
$mime[ 'type' ] = mime_content_type( $file );
if( $mime[ 'type' ] )
$mimetype = $mime[ 'type' ];
else
$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
header( 'Content-Type: ' . $mimetype ); // always send this
if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
header( 'Content-Length: ' . filesize( $file ) );
$last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
$etag = '"' . md5( $last_modified ) . '"';
header( "Last-Modified: $last_modified GMT" );
header( 'ETag: ' . $etag );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
// Support for Conditional GET
$client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
// If string is empty, return 0. If not, attempt to parse into a timestamp
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
// Make a timestamp for our most recent modification...
$modified_timestamp = strtotime($last_modified);
if ( ( $client_last_modified && $client_etag )
? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
: ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
) {
status_header( 304 );
exit;
}
// If we made it this far, just serve the file
readfile( $file );
It works and it allows me to access by wordpress user, except that a that I have in the code appears as and I do not know why.
any idea?
Possible dublicate of How to Protect Uploads, if User is not Logged In?
TL;DR:
So what you can do is make a redirect to a php file, and check if a user is logged in or not.
So if you want to protect the upload folder, put this in .htaccess:
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ check-auth.php?file=$1 [QSA,L]
Example of file to use, to check for auth is found here.
I'm facing the following error in my WordPress Site
[03-Sep-2017 10:12:36 UTC] PHP Warning: simplexml_load_file(): in /home/syriacar/public_html/syria-cart.com/wp-content/plugins/polylang/modules/wpml/wpml-config.php on line 53
and here is the file error content
foreach ( $plugins as $plugin ) {
if ( file_exists( $file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/wpml-config.xml' ) && false !== $xml = simplexml_load_file( $file ) ) {
$this->xmls[ dirname( $plugin ) ] = $xml;
}
}
It might be due to malformed wpml-config.xml file.
For example, on this support WordPress forum page, you can find a similar issue and the cause was missing </key> closing tag before </admin-texts>.
UPDATE:
In your comments, you also mention yith-woocommerce-affiliates warning, so another possibility is that the YITH WooCommerce Affiliates plugin doesn't have the wpml-config.xml or is empty.
The polylang documentation about wpml-config.xml mentions the following:
Developpers must place the wpml-config.xml file in the root directory
of the plugin or theme.
I need to check if a folder exist in an other folder. If not, then a new folder will be created. I can´t seem to get it to work. See code below.
Note: I use TCPDF.
// Create filename
$filnamnet = $id.'_'.$datum.'_'.$fornamn.'_'.$efternamn.'.pdf';
// Folder in iup_pdf
$mapparna_dir = 'iup_pdf/'.$id.'_'.$fornamn.'_'.$efternamn.'_'.$personnummer.'';
// Check if folder exist in iup_pdf
if(!is_dir($mapparna_dir) ) {
mkdir('iup_pdf/'.$id.'_'.$fornamn.'_'.$efternamn.'_'.$personnummer);
}
$pdf->Output(__DIR__ . '/iup_pdf/'.$id.'_'.$fornamn.'_'.$efternamn.'_'.$personnummer.'/'.$filnamnet.'', 'F');
The error states: TCPDF ERROR: Unable to create output file
You might find this of use.
function RecursiveMkdir( $path=NULL, $perm=0644 ) {
if( !file_exists( $path ) ) {
RecursiveMkdir( dirname( $path ) );
mkdir( $path, $perm, TRUE );
clearstatcache();
}
}
I tend to find that the fullpath works best - ie:$_SERVER['DOCUMENT_ROOT'].'/path/elements/to/folder' etc rather than the relative path. Also, is_dir() determines if a file is a directory - perhaps use file_exists as in the function.
if( !file_exists( $mapparna_dir ) ) RecursiveMKdir( $mapparna_dir );
Months ago, I have placed a 301 redirect rule in my .htaccess file to redirect all the www request to a non-www request.
The problem is two days ago, when I tried to access my example.net site using www.example.net I get the following warnings in the page and website is not loaded.
http://i.stack.imgur.com/nXBMF.png
Here are the corresponding lines:
1. Plugin.php Line 647 = if ( strpos( $file, $realdir ) === 0 ){
Full function:
/**
* Gets the basename of a plugin.
*
* This method extracts the name of a plugin from its filename.
*
* #since 1.5.0
*
* #param string $file The filename of plugin.
* #return string The name of a plugin.
*/
function plugin_basename( $file ) {
global $wp_plugin_paths;
foreach ( $wp_plugin_paths as $dir => $realdir ) {
if ( strpos( $file, $realdir ) === 0 ) { /** LINE 646 */
$file = $dir . substr( $file, strlen( $realdir ) );
}
}
$file = wp_normalize_path( $file );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
$file = trim($file, '/');
return $file;
}
2. Pluggable.php Line 1178 = header("Location: $location", true, $status);
Full file: http://pastebin.com/0zMJZxV0
I use WordPress only to write some articles. My PHP knowledge is very basic and limited only to locate errors.
Please help me figure out the problem with this. As I have read from the Codex FAQ, they say that empty strings may be a culprit for the pluggable.php error. But I have no idea how to locate it and I have attached the file for your reference.
Please provide your suggestions to avoid this error in the future. Thanks in advance.
3. EDIT - wp setting file: (the error line - include_once( $plugin ); )
// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
wp_register_plugin_realpath( $plugin );
include_once( $plugin );
}
unset( $plugin );
The issue with the header information has been discussed in here: Cannot modify header information error in Wordpress. Could you give this a try and see whether this solves this part of your problem?.
On the other issue:
try var_dump ($file) (for instance -- or echo $file ) to see what they actually contain.
Check your configuration path of plugins :
var_dump($wp_plugin_paths);
You've got an error because $realdir is empty.