1. Home
  2. WordPress
  3. APi Development
  4. Get Website Info

Get Website Info

//    ____                 _                           _                             
//   / ___|  _   _   ___  | |_    ___    _ __ ___     | |       ___     __ _    ___  
//  | |     | | | | / __| | __|  / _ \  | '_ ` _ \    | |      / _ \   / _` |  / _ \ 
//  | |___  | |_| | \__ \ | |_  | (_) | | | | | | |   | |___  | (_) | | (_| | | (_) |
//   \____|  \__,_| |___/  \__|  \___/  |_| |_| |_|   |_____|  \___/   \__, |  \___/ 
//                                                                     |___/         

function register_custom_api_endpoints() {
    // Register a REST route for getting settings
    register_rest_route( 'wp/v2/', '/settings', array(
        'methods'  => 'GET',
        'callback' => 'get_custom_settings',
        'permission_callback' => '__return_true', // Make it publicly accessible
    ));
}

add_action( 'rest_api_init', 'register_custom_api_endpoints' );



function get_custom_settings() {
    // Fetch settings data
    $settings = array(
        'title'             => get_bloginfo( 'name' ),
        'description'       => get_bloginfo( 'description' ),
        'logo'              => get_custom_logo_url(), // Ensure this function exists or implement it
        'url'               => home_url(),
        'admin_email'       => get_option( 'admin_email' ),
        'posts_per_page'    => get_option( 'posts_per_page', 10 ),
        'timezone'          => get_option( 'timezone_string', 'UTC' ),
        'date_format'       => get_option( 'date_format', 'F j, Y' ),
        'time_format'       => get_option( 'time_format', 'g:i a' ),
        'start_of_week'     => get_option( 'start_of_week', 0 ), // 0 (Sunday) to 6 (Saturday)
        'default_category'  => get_option( 'default_category', 0 ),
        'uploads_use_yearmonth_folders' => get_option( 'uploads_use_yearmonth_folders', 1 ) ? 'yes' : 'no',
        'permalink_structure' => get_option( 'permalink_structure', '' ),
        'comments_per_page' => get_option( 'comments_per_page', 10 ),
        'comment_registration' => get_option( 'comment_registration', 0 ) ? 'enabled' : 'disabled',
        'users_can_register' => get_option( 'users_can_register', 0 ) ? 'yes' : 'no',
        'blog_public' => get_option( 'blog_public', 1 ) ? 'public' : 'private',
        // Add more settings as needed
    );

    return new WP_REST_Response( $settings, 200 );
}

How can we help?