Use .php file as page instead of wordpress page & template file?

Yes you can do this but creating template like usercp.php . (1) First create usercp.php template and then this one line at first of template. update_post_meta(get_the_ID(), ‘usercp’, 111); (2) Then create page and assign template. (2) Then go to your functions.php file and add this code add_action(‘template_redirect’, ‘setPrivateTemplate’); function setPrivateTemplate() { if (get_post_meta(get_the_ID(), ‘usercp’, true) … Read more

Echo a function inside a function

echo is a PHP language construct which pushes values to the output buffer. It does not have a return value, so concatenating it with a string would cause everything after the echo to immediately be sent to the output buffer, and everything prior to echo to compose the concatenated string. This is such a misuse … Read more

How can I make an object available through the entire site?

Do not use globals. Ever. You don’t need your object everywhere. You need it only where your code is running. Globals are hard to debug, everyone can write to them or just delete them. Unit tests with globals are possible, but awkward. You have to change the global state for each test, ie. something outside … Read more

a:0:{} is replaced into database as s:6:”a:0:{}”;

API calls are API calls, not database writes. What and how information is stored in the DB is usually best left as an unknown since, unless explicitly defined in the API, it might change. Specifically in this case, wordpress will serialize the value being passed, and since you are passing a string it is serialized … Read more

Fatal Error in wp_get_current_user() Function

You call this function too early, before pluggable function is_user_logged_in() is defined. Try this: function wpse_get_current_user() { $current_user = wp_get_current_user(); // do other stuff here } add_action( ‘init’, ‘wpse_get_current_user’, 10 );

Sanitizing text fields in array

The best way to sanitize text fields within WordPress is to use sanitize_text_field() function: $data = sanitize_text_field( $_POST[‘key’] ); Additionally, if you register the meta field properly width register_meta() function, you can define the sanitize callback and the expected data type as well. For example: add_action( ‘init’, ‘cyb_register_meta_fields’ ); function cyb_register_meta_fields() { $args = array( … Read more

get the correct url for an folder in wp-includes wordpress

You sad you put the json in wp-includes, but in the url you wrote wp-content. So I give you the code for getting the server path for both folders: // wp-includes $file = ABSPATH . WPINC . ‘/json/users.json’; // wp-content $file = WP_CONTENT_DIR . ‘/json/users.json’; You can find many WordPress constants (like ABSPATH, WPINCand WP_CONTENT_DIR … Read more