PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] How to determine a Wordpress version remotely?

 October 24, 2022     database, wordpress     No comments   

Issue

I have numerous sites and its becoming a nuisance keeping them all up to date, so I would ideally like to compile a list where I can display the version of each website automatically. So I can see at the drop of a hat which ones needs updated and so on.

I have remote access to all off their databases, I had thought about querying the wp_options table for the DB Version but that isn't specific enough when it comes to smaller version updates as far as I am aware.

Any thoughts?


Solution

Here's a demo plugin

<?php

/** Plugin Name: My JSON data **/ 

add_filter( 'query_vars', function( $qv ){
    $qv[] = 'mydata';
    return $qv;
});

add_action( 'template_redirect', function(){

    $input = get_query_var( 'mydata' );
    $secret = 'abcdefg'; // Edit this

    if( ! empty( $input ) )
    {
        if( $secret === $input )
        {
            $data = array( 
                        'version'   => $GLOBALS['wp_version'],
                        'foo'       => 'bar', 
                    );

            wp_send_json_success( $data );
        }
        else
        {       
            wp_send_json_error();
        }   
    }

} );

where example.com/?mydata=abcdefg gives

{"success":true,"data":{"version":"3.8.1","foo":"bar"}}

and example.com/?mydata=wrong shows:

{"success":false}


Answered By - birgire
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing