Using a page-template to restrict access based on IP (Frontend)

Now I have it working! In the meanwhile Jeff Cohan also gave the right advice on how to do it (see his comment on the question). Here’s my full code, working the way he suggested: function getUserIP() { $client = @$_SERVER[‘HTTP_CLIENT_IP’]; $forward = @$_SERVER[‘HTTP_X_FORWARDED_FOR’]; $remote = $_SERVER[‘REMOTE_ADDR’]; if (filter_var($client, FILTER_VALIDATE_IP)) {$ip=$client;} elseif (filter_var($forward, FILTER_VALIDATE_IP)) {$ip=$forward;} … Read more

require happens out of order

Must be something with your setup. Following works for me (inside child theme – should work for any theme though): single.php: global $post; $bla = $post->post_title; error_log(‘post title is: ‘ . $bla); include(‘included.php’); included.php: error_log(‘i am included file: ‘ . $bla); Output in debug.log: post title is: Hello test i am included file: Hello test … Read more

How to get template link?

If you’re using that template for only one page, you can try this function: /** * @param string $template Base name of the template. */ function wpse_233924_get_page_link($template) { $query = new \WP_Query; // Get page which is using the $template. $page = $query->query([ ‘post_type’ => ‘page’, ‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => $template, ‘no_found_rows’ => 1, … Read more

Target pages using Woo Commerce single product page template

You can use is_product() WooCommerce conditional tag to identify if its single product page. Below is example code which enqueues test.js if its a single product page. You may use and tweak this code snippet further. function mytheme_scripts() { if ( is_product() ) { wp_enqueue_script( ‘test-js’, get_template_directory_uri() . ‘/js/test.js’, array() ); } } add_action( ‘wp_enqueue_scripts’, … Read more

page_template filter without a plugin

After some digging I found a better function which allows you to directly modify the template listing function page_templates( $templates ) { $templates[‘temp/template1.php’] = ‘Full Width Template’; return $templates; } add_filter( ‘theme_page_templates’, ‘page_templates’ );

Restrict Access to Logged-In Users Page Template

This could be done in a number of ways. Please refer to the codex for further info on template hierarchy, the wordpress loop and the ‘get_template_part()’ function. The page.php is for dispalying every page. You should copy and rename it to page-restricted.php. From the original page.php, remove this part – /* Template Name: Restrict Access*/. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)