Check if User exists in WordPress Multisite

You can check existing user with “username_exists” WordPress function and insert user using “wp_insert_user” function as below for Network site also: if( username_exists( ‘username’ ) ) { _e( ‘Username already exists’, ‘your-text-domain’ ); } else { _e( ‘Username does not exists.’, ‘your-text-domain’ ); $userdata = array( ‘user_login’ => ‘username’, ‘user_url’ => ‘http://example.com’, ‘user_pass’ => wp_generate_password(), … Read more

WordPress with Git deployment issues

I commit all WordPress because I consider it one big ball of code that pertains to one site, this means updates to core WordPress files, plugins and themes are all part of the commit history. I don’t use sub-modules or any other weird nested revision setups. If you have a complicated structure of including multiple … Read more

Is there a way to make a pure vanila page of just HTML/CSS/JS

I’ve done this in the past by using custom page templates. Basically, there are two ways to create a custom page template. You can create a file in your themes directory and name it page-vanilla-html.php. You can create a file and name it whatever you want (for example vanilla-html.php). You just need to include a … Read more

Add get_option to jquery

Anyway, basically Hody_McGee gave the answer in his comment: You could use wp_localize_script(). As it states in the Codex: [wp_localize_script()] can be used to make any data available to your script that you can normally only get from the server side of WordPress. How do we do this? <?php add_action( ‘wp_enqueue_scripts’, ‘register_scripts’ ); function register_scripts(){ … Read more

Plugin not saving values when placed in a folder within /wp-content/plugins

Here is the fixed and modified code which was having the nonce action issue. <?php /* Plugin Name: Test Plugin Plugin URI: Test Description: Test Author: Test Version: 007 Author URI: */ // add all post types $clinical_post_types = array(); $post_types = get_post_types(); foreach ( $post_types as $post_type ) { $clinical_post_types[] = $post_type; } // … Read more

How to add custom link to menu in wordpress programmatically?

You must return the value of a filter instead of echoing it… Example: add_filter(‘wp_nav_menu_items’, function($items, $args) { $link = ‘<li>Login</li>’; return $items . $link; }, 20, 2); The above will effect all menus however, instead use the $args variable to conditionally modify a specific menu only or use “wp_nav_menu_{$menu->slug}_items” which will only operatae on a … Read more

Security issues with WP sites

wordpress configuration file is located in the root.In the event that PHP stops functioning on webserver for any reason.we run the risk of this file being displayed in plaintext,which will give our password and database information to visitor. you can safely move wp-config directory up out of root directory.this will stop if from accidentally served. … Read more

How can I serve a text file at a custom URL

You can utilize add_rewrite_rule to create a new endpoint like http://example.com/api/files/xyz which processes the request and renders the contents from your server. This allows you to mask the origin of the file but still access it’s content. add_rewrite_rule requires you flush_rewrite_rules but you only need to do that once every time you make a change … Read more

Change settings of get_post_type_object

since WP 4.4.0, you can use this filter that allows you to change the arguments used in the original cpt registration. Add this to your functions.php file: add_filter( ‘register_post_type_args’, function( $args, $post_type ) { if( ‘wyde_portfolio’ === $post_type && is_array( $args ) ) $args[‘rewrite’][‘with_front’] = false; return $args; }, 99, 2 ); It’s taken from … Read more