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

Set object terms not working on plugin activation

register_activation_hook is one-time only activation hook. It can be used for database structure creation, as example, that needs to fire only on plugin activation trigger. In order to set a custom taxonomy you need a hook that will fire not just once, but per every WordPress load. Such as init. Use add_action( ‘init’, ‘YOUR_CALLBACK’ ); … 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

How to make first_name and last_name required fields in user profile?

You could check the $_POST variable when updating the user profile page. I would hook into user_profile_update_errors and do something along those lines. This filter will not save to DB if errors are found. add_filter(‘user_profile_update_errors’, ‘wpse_236014_check_fields’, 10, 3); function wpse_236014_check_fields($errors, $update, $user) { // Use the $_POST variable to check required fields if( empty($_POST[‘first_name’]) ) … Read more