In WordPress run time display php code direct? - wordpress

*Below code in display my browser directly *
<?php
/**
* Loads the WordPress environment and template.
*
* #package WordPress
*/
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
}
This code is displayed on my screen please give me any solution

It sounds like your server is not executing any PHP and just serving the plain text files.
My recommendation would be to confirm that your server has started correctly and PHP is installed and working. Can you access phpMyAdmin, cPanel or run any php through terminal?
If it's installed locally, this might help: http://reviews.cnet.co.uk/software-and-web-apps/how-to-install-and-test-wordpress-on-a-local-server-50005338/.

Related

Triggering wp_update_plugins cron to automatically update plugins in WordPress

I am trying to force plugin updates with WordPress, but it doesn't seem to be working. I need to force these updates within a custom plugin itself.
I added the following filter into my plugin:
add_filter( 'auto_update_plugin', '__return_true' );
I made sure that nothing in the wp_config file disallows auto-updates. Even though I didn't need to, to be safe I also set:
define( 'FS_METHOD', 'direct' );
and define( 'WP_AUTO_UPDATE_CORE', true );
I then installed the Advanced Cron Manager plugin to trigger the wp_update_plugins event, but this did not update any plugins.
I decided to simply call the wp_maybe_auto_update() function within my plugin on init... and it worked and updated my plugin - but also disabled it!
I am wondering if anyone knows why running the wp_update_plugins cron event wouldn't be updating any plugins? There must be a really simple solution here that I'm missing! Your help would be much appreciated!
You could use the following function to update a plugin programatically:
function upgrade_plugin( $plugin_slug ) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
wp_cache_flush();
$upgrader = new Plugin_Upgrader();
$upgraded = $upgrader->upgrade( $plugin_slug );
return $upgraded;
}
& you could use that in conjunction with get_plugins
// Check if get_plugins() function exists. This is required on the front end of the
// site, since it is in a file that is normally only loaded in the admin.
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();
and then loop over it to update the plugins
foreach ( $all_plugins as $key => $value ) {
upgrade_plugin( $key );
}
I found this article useful when putting together this answer: https://wpreset.com/programmatically-automatically-download-install-activate-wordpress-plugins/
From the answer above I got this to work, you just need to remove the extra / from include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader-skin.php';
to make it: include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
When I am relying on a cron event (Testing with WP Crontrol plugin) to take care of plugin update, following code seems to be working with given required files:
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/misc.php';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->upgrade($plugin_slug);
if (is_wp_error($result) || !$result) {
// Check if error, else updated successfully
}

Wordpress improve REST API - SHORTINIT not work

i'm trying to improve the performance of Wordpress API custom endpoints.
I created a plugin, simple file under plugin/PLUGIN_NAME folder where I call "register_rest_route" function to set the endpoints.
To improve the performance I am trying to load not all the plugins, but only what I need, Wordpress CORE to query users and posts and Ultimate Members.
That's my code:
define('SHORTINIT', true);
require_once dirname(__FILE__) . '/../../../wp-load.php';
require_once dirname(__FILE__) . '/../ultimate-member/ultimate-member.php';
add_action('rest_api_init', function () {
register_rest_route( 'my-api/v1', 'test/me',array(
'methods' => 'POST',
'callback' => 'test'
}
));
...
...
It work, but the problem is that works also if I not load "wp-load.php" script. In my test method I use WP_User_Query, WP_Query and ultimate member method like um_user().
It seems like SHORTINIT didn't work.
What I wrong ?
Reading the source code of wp-settings.php shows a problem:
// lines 144 to 147 of wp-settings.php
// Stop most of WordPress from being loaded if we just want the basics.
if ( SHORTINIT ) {
return false;
}
// lines 359 to 373 of wp-settings.php
// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
wp_register_plugin_realpath( $plugin );
include_once( $plugin );
/**
* Fires once a single activated plugin has loaded.
*
* #since 5.1.0
*
* #param string $plugin Full path to the plugin's main file.
*/
do_action( 'plugin_loaded', $plugin );
}
unset( $plugin );
The check for SHORTINIT is done before plugins are loaded. So your "define('SHORTINIT', true);" is executed after not before SHORTINIT is checked and has no effect.
Further wp-settings.php is included indirectly from wp-load.php so when your plugin code is executed wp-load.php has already been included.
Who have my same problem, I recommend using Plugin Load Filter, a wordpress plugin that let you select which plugins to activate in the REST API.

How to know which website has installed our wordpress plugin?

We are creating a Wordpress plugin and we want to know the urls of the wordpress websites on which our plugin is installed.
What code should we add to the plugin to receive the url of the wordpress website?
We need this information to see what type of websites are installing our plugin.
Note: We will notify users before downloading the plugin and at the time of activation that we will be receiving there website's url.
In a simple way, You can create a get_urls.php in http://example.com/get_urls.php for receiving and storing URLs.
get_urls.php
<?php
if( isset( $_GET['url'] ) ) {
file_put_contents('urls.log', date('[r] ') . $_GET['url'] . "\n", FILE_APPEND );
}
And add below code to your plugin.
add_action( 'activated_plugin', 'send_url_in_activate', 10, 1 );
function send_url_in_activate( $plugin ) {
if( $plugin !== "PLUGIN_DIR" ) { // e.g: woocommerce/woocommerce.php
return;
}
$response = wp_remote_get( 'http://example.com/get_urls.php?url=' . get_site_url() );
}
Don't forget set your plugin dir.

How can I get current version of custom plugin in wordpress

I want to compare the current version of my custom plug-in with update version of plug-in.
I get updated version of plug-in in response from server.
How can I get current version of my plug-in?
You can use get_file_data() function which is available on frontend and backend. For example:
get_file_data('/some/real/path/to/your/plugin', array('Version'), 'plugin');
if you use get_plugin_data() on the frontend it will throw an error Call to undefined function get_plugin_data(). Here is the correct way to get plugin header data.
if ( is_admin() ) {
if( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_data = get_plugin_data( __FILE__ );
echo "<pre>";
print_r( $plugin_data );
echo "</pre>";
}
You could save you version in the options table for easy retrieval. But you can also use get_plugin_data for more details about a given plugin.
<?php
$data = get_plugin_data( "akismet/akismet.php", false, false );
?>
Please note that get_plugin_data is only available in the WordPress admin, it's not a front-end available function.
For users who land on this question to find out the current version of WordPress itself use this function.
// it will show only numeric value i.e 5.8.2
echo get_bloginfo( 'version' );

How can I disable WordPress plugin updates?

I've found a great plugin for WordPress under GPLv2 license and made a lot of changes in source code, plugin does something else now.
I modified author (with original plugin author's credits), URL, version number (from xxx 1.5 to YYY 1.0).
Everything works great, but when WordPress checks for plugin updates it treats my plugin YYY 1.0 as xxx 1.0 and displays notification about available update.
My changed plugin YYY 1.0 was installed by copying files from my computer, not from WP repository.
What else do I have to change?
Disable plugin update
Add this code in your plugin root file.
add_filter('site_transient_update_plugins', 'remove_update_notification');
function remove_update_notification($value) {
unset($value->response[ plugin_basename(__FILE__) ]);
return $value;
}
Put this code in the theme functions.php file. This is working for me and I'm using it. Also this is for specific plugin. Here you need to change plugin main file url to match to that of your plugin.
function my_filter_plugin_updates( $value ) {
if( isset( $value->response['facebook-comments-plugin/facebook-comments.php'] ) ) {
unset( $value->response['facebook-comments-plugin/facebook-comments.php'] );
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'my_filter_plugin_updates' );
Here:
"facebook-comments-plugin" => facebook comments plugin folder name
"facebook-comments.php" => plugin main file.this may be different like index.php
Hope this would be help.
The simplest and effective way is to change the version of the plugin which you don't want to get update.
For an example
if I don't want wptouch to get updated, I open it's defination file, which is like:
/*
Plugin Name: WPtouch Mobile Plugin
Plugin URI: http://www.wptouch.com/
Version: 4.0.4
*/
Here in the Version change 4.0.4 to 9999
like:
/*
Plugin Name: WPtouch Mobile Plugin
Plugin URI: http://www.wptouch.com/
Version: 9999
*/
In the plugin file, there will be a function that will check for updates. The original author could have named this anything, so you will have to go through the code and check each function and what it does. I would imagine the function will be quite obvious as to what it does.
Alternatively you can add this to your plugin file:
add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[$my_plugin] );
unset( $plugins->active[array_search( $my_plugin, $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
}
return $r;
}
Credits: http://developersmind.com/2010/06/12/preventing-wordpress-from-checking-for-updates-for-a-plugin/
add_filter('site_transient_update_plugins', '__return_false');
in function.php add above code and disable all plugins updates
Add this line to wp-config.php to disable plugin updates:
define('DISALLOW_FILE_MODS',true);
One easy solution was to change the version of plugin in plugin file.
For example if plugin version is 1.2.1. You can make it like below (100.9.5 something that plugin author will never reach to )
<?php
/*
* Plugin Name: Your Plugin Name
* Description: Plugin description.
* Version: 100.9.5
*/
Here's an updated version of Mark Jaquith's script:
WP Updates have switched to HTTPS
Unserialize was blocked on my shared hosting
This uses json_decode and json_encode instead
Credit: Block Plugin Update
.
add_filter( 'http_request_args', 'widget_disable_update', 10, 2 );
function widget_disable_update( $r, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = json_decode( $r['body']['plugins'], true );
unset( $plugins['plugins'][$my_plugin] );
unset( $plugins['active'][array_search( $my_plugin, $plugins['active'] )] );
$r['body']['plugins'] = json_encode( $plugins );
}
return $r;
}
Disable plugin updates manually:
Open functions.php file (go to your activated themes folder)
Copy and paste the following code:
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
Save changes, and you’re done
Just for completeness, here is one more plugin meant to block updates of selected other plugins:
https://github.com/daggerhart/lock-plugins
Some information about its background and mode of function can be found here (in German).

Resources