Is it OK to include files using ABSPATH?

get_home_path() only works when WP admin scripts are loaded. ABSPATH is defined in wp-config.php so works anytime after the config file is loaded, so it should be totally fine for your use. It is set to the dirname(__FILE__) + trailing slash of wp-load.php (same location as e.g. wp-config.php). dirname here returns the absolute path where … Read more

Using fwrite() and “a” appends multiple times instead of once

You could try putting your code in a WordPress Action or Filter call: add_action( ‘init’, ‘my_file_function’ ); function my_file_function() { $content = “some text here\n”; $fp = fopen($_SERVER[‘DOCUMENT_ROOT’] . “/wp-content/themes/zerif-lite-child/myText.txt”,”a”); fwrite($fp,$content); fclose($fp); } The flag (‘a’ vs ‘wb’) doesn’t have anything to do with your problem, it just happens to showcase it. For whatever reason, … Read more

How to customize a permalink (URL) structure?

The GUID field is not a URL and should never be used for that purpose. It’s a unique identifier that happens to look like a URL, but it should never be trusted as such. WordPress has a number of functions for retreiving attachment URLs and files: get_children get_attached_media the_attachment_link get_attachment_link wp_get_attachment_link wp_get_attachment_image wp_get_attachment_image_src wp_get_attachment_url wp_get_attachment_thumb_file … Read more

load_plugin_textdomain error

The plugin calling load_plugin_textdomain() the wrong way: load_plugin_textdomain( ‘custom_smilies’, PLUGINDIR . “https://wordpress.stackexchange.com/” . dirname(plugin_basename(__FILE__)) . ‘/lang’ ); You have to change the code to: load_plugin_textdomain( ‘custom_smilies’, false, plugin_dir_path(__FILE__) . ‘/lang’ );

Missing Argument

You didn’t specify how many arguments your function accepts when you used add_filter: add_filter( $tag, $function_to_add, $priority, $accepted_args ); Your code only passes a $tag and a $function_to_add, but it doesn’t tell WordPress what priority it should be, or how many accepted arguments your function takes. You need to fix that. If you don’t provide … Read more

add_action shortcut?

From the WordPress development reference, the add_action function requires two parameters with an optional two. The first parameter, $tag is a string that is the name of the action to which the $function_to_add is hooked. The second parameter, $function_to_add is a callable that the WordPress developer reference states is “the name of the function you … Read more