Variable global scope [closed]

Globals are generally discourgaged. You can use define instead. <?php define(“FILM_LABEL”, “Films”); define(“SHOW_LABEL”, “Shows”); function CreatePostTypes() { register_post_type( FILM_LABEL, GenerateFilmType( FILM_LABEL ) ); register_post_type( SHOW_LABEL, GenerateFilmType( SHOW_LABEL ) ); } add_action( ‘init’, ‘CreatePostTypes’ );

WP_Query Variable inside Array

Your array definitions aren’t correct. This… elseif($_REQUEST[“price”] == 20){$price = “array( ’19’, ’20’ )”;} … creates a literal string that reads “array( ’19’, ’20’ )”. Remove the quotes. elseif($_REQUEST[“price”] == 20){$price = array( ’19’, ’20’ );} That should give you PHP arrays.

Shortcodes and a list of IDs?

explode will be your best option. WordPress has a few built in functions to handle arrays of function arguments (wp_parse_args and shortcode_atts for example), but nothing relating to splitting a string and iterating the result. It’s not entierly clear to me what you are trying to achieve, but let’s say you were trying to get … Read more

Putting PHP variables into javascript [duplicate]

Use wp_localize_script: wp_enqueue_script(‘YOUR_SCRIPT_HANDLE’); $object = array( ‘zoom’ => get_option(‘map_zoom’), ‘longitude’ => get_option(‘map_longitude’), ‘latitude’ => get_option(‘map_latitude’), ); wp_localize_script(‘YOUR_SCRIPT_HANDLE’, ‘JSObject’, $object); And then use it in your JS file like JSObject.zoom and the like.

Storing state between hook functions

Uing OOP for your plugin it’s very easy. class MyPlugin { static $flag; static function function_a() { self::$flag = ‘a value’; } static function function_b() { if ( ! is_null(self::$flag) ) echo self::$flag; // echo ‘A Value’; } } add_action(‘plugins_loaded’, array(‘MyPlugin’, ‘function_a’) ); add_action(‘init’, array(‘MyPlugin’, ‘function_b’) ); Not using OOP you can use global variables. … Read more

Validate form in functions.php, send errors back to template

You need a filter not an action. Something like this (notes are commented into the code. You have a few PHP errors that you need to correct): function signup_validate_insert($post){ $errors = false; if (isset($post[‘submit_msg’])) { // validate , insert into database } return $errors; } add_filter(‘signup_insert’, ‘signup_validate_insert’); $errors = apply_filters(‘signup_insert’, $_POST); if((!empty($errors))){ // $errors is … Read more

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