Articles of php

'global' not working in wordpress?

My wordpress theme consists of the file loop.php which just does this: <?php include(“AAAA.php”); ?>. Now AAAA.php looks like this: <?php $test = 1; function f() { global $test; echo “inside f: test=’$test'”; } echo “outside f: test=’$test’ “; f(); ?> Since I referred to $test inside f, I would suspect that f knows thereafter […]

Disable Checkbox depending on state of another checkbox

I’m trying to disable a checkbox depending on the state of another checkbox. <form action=”options.php” method=”post” id=”form_submission”> <table> <tr> <td width=”200px”> <label for=”first_option”><?php _e(‘First Option:’, ‘my_plugin’); ?></label> </td> <td> <input type=”checkbox” name=”first_option_show” value=”show” <?php echo (get_option(‘first_option_show’)==”show” ? ‘checked’ : ”);?>> </td> <td> <input type=”checkbox” name=”first_option_required” value=”required” <?php echo (get_option(‘first_option_required’)==”required” ? ‘checked’ : ”);?>> </td> </tr> […]

Custom Taxonomy Select Menu: Setting default option value?

I’m creating a series of select drop down menus that pull data from various taxonomies. I got this PHP script working for a WooCommerce attribute of color: function get_color_dropdown($taxonomies, $args){ $myterms = get_terms($taxonomies, $args); $output =”<select onChange=’window.location.href=this.value’>”; foreach($myterms as $term){ $root_url = get_bloginfo(‘url’); $term_taxonomy=$term->taxonomy; $term_slug=$term->slug; $term_name =$term->name; $link = $root_url.’/’.$term_taxonomy.’/’.$term_slug; $output .=”<option value='”.$link.”‘>”.$term_name.”</option>”; } $output […]

Extract and display user infromation on an automatically created page

Is there a way to get the block of code below to extract a list of given user information as it creates the page for the new user. It creates new page for new user as supposed but I’d like it to alos extract and display some information from the user profile. function my_create_page($user_id){ $the_user […]

Applying CSS on PHP variable

I have PHP code as $message = str_replace(“{eventlinkURL}”,$eventlinkURL,$message); I want to set color to the $eventlinkURL variable. I tried using <font> echo “<font style=’background:red’> <font color =’red’> $message = str_replace(‘{eventlinkURL}’,$eventlinkURL,$message); />”; but no success. How do I set color to the variable?

Creating WordPress Shortcode with Variable

please forgive me I’m relatively new to PHP… I would like to create a shortcode called [city-name] and have tried placing the following code in my functions.php file: function get_city_name() { return $current_cityinfo[‘cityname’]; } add_shortcode( ‘city-name’, ‘get_city_name’ ); Then entered the [city-name] shortcode into a page to test and there is no luck… Is there […]

Get the id of the row from database on click of a button

I am using wordpress and I am fetching images from the mysql database with below code. And I display the image and there is a button just with every image and what I want is that when that button is pressed the id of that row of database that is fetched is printed on the […]

“Notice: Undefined variable: content” is showing

I am using this code if for showing related content form custom taxonomy. But it is showing “Notice: Undefined variable: content” Here is my code: <?php /* Plugin Name: Related Post */ function pippin_related_posts($taxonomy = ”) { global $post; if($taxonomy == ”) { $taxonomy = ‘post_tag’; } $tags = wp_get_post_terms($post->ID, $taxonomy); if ($tags) { $first_tag […]

Plugin not working locally, but works on server

This is a hail Mary throw, but I appreciate any ideas that could point me in the right direction. I had a “plugin” created for my wordpress site. I have a live site that is on a server and one that is installed locally on Xampp. This plugin works great on the live server site, […]

custom plugin with upload files does not work

I an creating a custom plugin that used shortcodes.. then it will have a feature that will upload files and stores it in wp-content/uploads/ directory.. but it seems I got an error.. Warning: move_uploaded_file(http://mysitecom/wp-content/uploads/myfiles/1991117- DriverLiscence.jpg): failed to open stream: HTTP wrapper does not support writeable connections in /home/user/public_html/mysite/wp-content/plugins/myplugin/functions.php on line 1266 Warning: move_uploaded_file(): Unable to […]