/** * Validate that a certain WPEM page contains a shortcode * * @param $page * @param $shortcode */ public function canSeePageWithShortcode($page, $shortcode) { if (!function_exists('wpem_get_page_id_by_meta_name')) { require_once WPEM_INC_DIR . 'functions.php'; } $post = get_post(absint(wpem_get_page_id_by_meta_name($page))); $post_content = !empty($post->post_content) ? $post->post_content : ''; $message = sprintf('The "%s" page does not contain "%s"', $page, $shortcode); $string_contains_shortcode = strpos($post_content, $shortcode); $this->assertNotEquals(false, is_numeric($string_contains_shortcode), $message); }
/** * Append a Ninja Form shortcode to WPEM page content * * @param string $page * @param int $form_id */ private function add_ninja_form_to_page($page, $form_id) { $post_id = wpem_get_page_id_by_meta_name($page); if (!$post_id) { return; } $post = get_post($post_id); if (!$post) { return; } $post->post_content .= sprintf("\n[ninja_forms id=%d]", $form_id); wp_update_post(array('ID' => $post_id, 'post_content' => $post->post_content)); }