his->escape_function = $escape_function; // replace strings like this: {tagname attr="value"} $string = preg_replace_callback( '/\{(\w+)(\ +(?:(?!\{)[^}\n])+)*\}/', array( $this, 'replace_tag' ), $string ); // call again to take care of nested variables $string = preg_replace_callback( '/\{(\w+)(\ +(?:(?!\{)[^}\n])+)*\}/', array( $this, 'replace_tag' ), $string ); return $string; } /** * @param string $string * * @return string */ protected function replace_in_html( $string ) { return $this->replace( $string, 'esc_html' ); } /** * @param string $string * * @return string */ protected function replace_in_attributes( $string ) { return $this->replace( $string, 'esc_attr' ); } /** * @param string $string * * @return string */ protected function replace_in_url( $string ) { return $this->replace( $string, 'urlencode' ); } /** * Gets data variable from cookie. * * @param array $args * * @return string */ protected function get_cookie( $args = array() ) { if ( empty( $args['name'] ) ) { return ''; } $name = $args['name']; $default = isset( $args['default'] ) ? $args['default'] : ''; if ( isset( $_COOKIE[ $name ] ) ) { return esc_html( stripslashes( $_COOKIE[ $name ] ) ); } return $default; } /* * Get property of currently logged-in user * * @param array $args * * @return string */ protected function get_user_property( $args = array() ) { $property = empty( $args['property'] ) ? 'user_email' : $args['property']; $default = isset( $args['default'] ) ? $args['default'] : ''; $user = wp_get_current_user(); if ( $user instanceof WP_User && isset( $user->{$property} ) ) { return esc_html( $user->{$property} ); } return $default; } /* * Get property of viewed post * * @param array $args * * @return string */ protected function get_post_property( $args = array() ) { global $post; $property = empty( $args['property'] ) ? 'ID' : $args['property']; $default = isset( $args['default'] ) ? $args['default'] : ''; if ( $post instanceof WP_Post && isset( $post->{$property} ) ) { return $post->{$property}; } return $default; } /** * @return string */ protected function get_email() { if ( ! empty( $_REQUEST['EMAIL'] ) ) { return $_REQUEST['EMAIL']; } // then , try logged-in user if ( is_user_logged_in() ) { $user = wp_get_current_user(); return $user->user_email; } // TODO: Read from cookie? Or add $_COOKIE support to {data} tag? return ''; } }