I have created a wordpress plugin which converts shortcodes to content based on the entry saved on the dataase:
global $wpdb;
$post_id = get_the_ID();
$post_content = get_the_content();
$pattern = '/[zam_tweets page=([0-9])]/';
preg_match($pattern, $post_content, $matches);
if(!empty($matches)){
$tweets_table = $wpdb->prefix . 'zam_tweets';
$result = $wpdb->get_var("SELECT tweet FROM $tweets_table WHERE post_id = '$post_id'");
$content = $result;
}
return $content;
My problem is how do I set the context to be that of a specific post so that I will get an actual post id when using the get_the_ID()
method. Is this how I’m supposed to go with this or do I just have to specify them as arguments?
If you have phpUnit configured for testing a WP plugin, you can use a test case like this:
In your
plugin-directory/tests/Some_Test_Case.php
:}
Command line in your plugin’s directory:
phpunit ./tests/Some_Test_Case.php