title: Get the post-id in Wordpress plugin
body: <p>I'm trying to get the post id inside of my custom wordpress plugin and I'm using the following code:</p>
  
  <pre><code>global $post;
  $current_page_id = $post-&gt;ID;
  var_dump($current_page_id);
  </code></pre>
  
  <p>But without any success. With <code>var_dump</code> I'm getting on every call <code>null</code>.
  Than, if I add to a template than the output works:</p>
  
  <pre><code>add_action('wp_footer', 'test');
  function test() {
      global $post;
      $current_page_id = $post-&gt;ID;
  }
  </code></pre>
  
  <p>What I would like to achieve inside of my plugin, is to pass the current post id to one of my functions. So something like:</p>
  
  <pre><code>my_function($base_url, array('variable_to_post' =&gt; $post-&gt;ID));
  </code></pre>