Show price with Geo IP location

Here is a simple approach to achieve what you are trying. Put these functions in your theme’s functions.php or plugin file. This will let you capture 2-letter country code with API request. You have to test it remotely (if you test on localhost you’ll get no country code as your IP reads as 127.0.0.1, so … Read more

How to add class in plugin only for network site?

How are you invoking ngob_sitelist_slug? I’m gonna guess that you are doing something like $my_class = new ngob_sitelist_slug;. Doing it this way would require that your class have a constructor. if it doesn’t, you’ll get an error. You could still call your class methods statically: $my_thing = ngob_sitelist_slug::my_method(); Though technically you should add the static … Read more

Theme or Plugin: Where should I write my code?

How Sharma just mentioned, both approaches are working well, but depending on the site type and scope and also it depends on the feature that needs to be implemented in your WordPress. If in the future you will change the theme of your WordPress site and you just implemented a feature in your current theme, … Read more

Plugin to restrict access to pages in wp-admin

if( is_admin() ) { add_filter( ‘init’, ‘custom_restrict_pages_from_admin’ ); } function custom_restrict_pages_from_admin() { global $pagenow; $arr = array( ‘update-core.php’, ‘edit.php’ ); if( custom_check_user_roles() && in_array( $pagenow , $arr ) ) { //echo some custom messages or call the functions } else { echo ‘This page has restricted access to specific roles’; wp_die(); } } function custom_check_user_roles() … Read more

Redeclare theme’s function in a plugin

You can only declare a function once. My reccomendation is that you put the functions in the plugin, then use filters to override in the theme, e.g. In the plugins: function my_awesome_function() { return apply_filters( ‘my_awesome_function’, “plugin” ); } In your theme: add_filter( ‘my_awesome_function’, function( $value ) { return “theme”; } ); Now every call … Read more

Is it dangerous to install unupdated plugins?

It depends on the plugin. The rule of thumb is that it is a bad sign when a plugin is not being updated, but is it “dangerous” depends on the complexity of the plugin. For example I have a small plugin which is probably 10 lines of code and will never become “dangerous” because of … Read more

WordPress URL redirect

This is quite possible. First off, Making pagename/{customString} resolve as the page itself instead of 404, then, you’re free to decide whether to keep the URI as is and serve the page content, or redirect back somewhere e.g page permalink ( get_the_permalink() ): add_action( “init”, function(){ $pagename = “pagename”; // page slug add_rewrite_rule( sprintf(‘^%s/([^/]*)/?’, $pagename), … Read more

Plugin not appearing after uploading it via FTP

Does the Plugin work on localhost? Was it corrected created? The main PHP file of the plugin must have the same name of the folder and the main PHP file must have the following before everything: <?php /* Plugin Name: WordPress.org Plugin Plugin URI: https://developer.wordpress.org/plugins/the-basics/ Description: Basic WordPress Plugin Header Comment Version: 20160911 Author: WordPress.org … Read more