get the current page id inside wordpress plugin page

Solution:

get_the_ID(); or $post->ID; returns the current page or post id in WordPress.

But you need to ensure that your post is saved in wordpress post table. Other wise you can’t get the id , simply because of it is not an entry in wordpress database.

If it is a static page and it’s not an entry in wordpress post then, get_the_ID() didn’t return anything.

For example : get_the_ID() didn’t go to work in post archive pages , administration pages in wordpress backend etc.

So as per this question you are trying to get the id of the page that is a backend plugin setting page or any archive page .

UPDATE

Method to get the current post id in wordpress

(1) global $post; $post->ID();

(2) global $wp_query; $post_id = $wp_query->get_queried_object_id();

(3) global $wp_query; $post_id = $wp_query->post->ID;

(4) get_the_ID();

[ It is recommended that this tag must be within The Loop. ]

see this

function get_the_ID() {
$post = get_post();
return ! empty( $post ) ? $post->ID : false;
}
ie get_the_ID() return the id of current $post .

(5) get_query_var(‘page_id’)

[ it will not going to work if we use pretty permalink ]
https://codex.wordpress.org/Function_Reference/get_query_var