Custom Post Type Object – Undefined Variables

Looks like some minor confusion here and syntax issues. Bad: You’re including the $ sign when setting property values. // Set Variables $this->$post_type_name = strtolower( str_replace( ‘ ‘,’_’, $name) ); $this->$post_type_args = $args; $this->$post_type_lables = $labels; Good: Omit the $ once you’ve declared them. // Set Variables $this->post_type_name = strtolower( str_replace( ‘ ‘,’_’, $name) ); … Read more

Problem with display data from get_option

You inserting the value of the get_option(‘go_to_top_or_bottom’);as a property in the $this->options so when you actual try to print it like this print_r($this->options[‘turn_on’]);you get the index error because this is a property!!! Correct way will be $this->options[‘turn_on’]=get_option(‘go_to_top_or_bottom’); Update I see that the $options is a private meaning you cannot access it outside of the class. … Read more

Hide one specific woocoomerce product

This code is tested and works fine on a fresh WP and WooCommerce installation. if ( !is_user_logged_in()) { function exclude_product_from_users($q){ $current_user = wp_get_current_user(); $prodcuts_ids = array(648); $q->set( ‘post__not_in’, $prodcuts_ids ); } add_action( ‘woocommerce_product_query’, ‘exclude_product_from_users’ ); function return_from_product_page(){ global $post; $prodcuts_ids = array(648); if(in_array( $post->ID , $prodcuts_ids)){ wp_redirect(home_url(“https://wordpress.stackexchange.com/”)); exit(); } } add_action(‘wp’, ‘return_from_product_page’); }

Configure WordPress to Generate Scheme-less Relative URLs

You can use the style_loader_src and script_loader_src filters. namespace WPSE; \add_filter( ‘style_loader_src’ , __NAMESPACE__ . ‘\protocol_relative-url’ ); \add_filter( ‘script_loader_src’, __NAMESPACE__ . ‘\protocol_relative-url’ ); function protocol_relative_url( string $url ) : string { return str_replace( [ ‘http:’, ‘https:’ ], ”, $url ); } /* Notes: * Namespaces require PHP > 5.3 * [] array syntax requires PHP … Read more

Custom Plugin Options Won’t Update

Did you confirm it was the transient values causing the options to not update? Here’s the WordPress function to clear transient values: https://codex.wordpress.org/Function_Reference/delete_transient An example: <?php // Create a simple function to delete our transient function edit_term_delete_transient() { delete_transient( ‘the_transient_name_to_delete’ ); } // Add the function to the edit_term hook so it runs when categories/tags … Read more