I have a fresh WordPress and bbPress installed on an internal server.
While I was setting up bbPress I wanted to test the functionalities like creating a forum, topic, etc. When doing these stuff in the back-end (dashboard) there didn't seem to be any problems but when I did it from the front-end I kept getting
ERROR: Are you sure you wanted to do that?
I searched for a solution and found this.
add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 );
function my_bbp_verify_nonce_request_url( $requested_url )
{
return 'http://localhost:8888' . $_SERVER['REQUEST_URI'];
}
I simply changed the hard-coded URL to what our internal server is set up to and it fixed the problem.
Now my question: is it possible for me to add this solution to a functions.php that is independent of the theme being used? I asked this because I have 2 concerns:
The current theme might get updated and will overwrite the file
I'm aware that the solution to this is simply create a child theme but my second concern prevents me from doing this.
The WordPress administrator might change themes and so both the functions.php file on the main theme and the child theme will stop working
How could I add the solution above so that I don't have to worry about the theme being updated and/or replaced with a new theme in the future? I don't want to keep adding this solution every time the administrator decides to change themes.
If you can't put it in a theme, put it in a Plugin. If you're worried that the plugin will get de-activated make it a Must Use Plugin.
It's dead simple to create a plugin. Create a file plugin-name.php and place it in a directory wp-content/plugins/plugin-name/. That file should contain the following code:
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 );
function my_bbp_verify_nonce_request_url( $requested_url )
{
return 'http://localhost:8888' . $_SERVER['REQUEST_URI'];
}
If you want it to be a must use plugin, put it in wp-content/mu-plugins/ instead of wp-content/plugins.
Related
I don't know how to manually add a text-domain to my child theme.
I installed LocoTranslate to find out what the text-domain was, and it shows the same as the main theme.
This is a problem, but I need to add a file that has been made custom and it must call this child theme in various parts of the code, now it calls the main theme and this is the problem.
Searching I found [WordPress documentation on child themes,][1] but I must say that I don't know how to interpret it, my experience is not enough to know how to read this documentation.
I don't even keep looking and I can't find a site that describes how to do this by someone inexperienced.
Is there a document outlining the steps to create a child theme text-domain for beginners?
Go into the style.css file in your child theme. In the comment header, add a text domain field under the theme name field.
/*
Theme Name: My Child Theme
Text Domain: mychildtheme
*/
Then, go to your functions.php file in your child theme and add the following code.
function mychildtheme_load_textdomain() {
load_child_theme_textdomain( 'mychildtheme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'mychildtheme_load_textdomain' );
Change 'mychildtheme' to the text domain you gave in your style.css file.
I want to create a subpage, e.g. /test/ and everything that I enter after /test/ should have one specific template and indexing, no 404 error.
I wanted to make this with virtual pages, but it's too many url's to add. (tried here - Wordpress fake/virtual folder)
I've got my template page-pagename.php which works. Now I need to add that every child of test does not return 404.
I think I have already searched the entire internet and cannot find a solution to this task
What you could fiddle with is with grabbing the main query on 'template_include'. You add an action like this. You can add it to your child theme in functions or in your custom plugin.
add_action( 'template_include', 'custom_router' );
Then in the custom router function, you can check the parameters that you are requesting ('test') and redirect to a template of your choice. Also add in functions.php or in custom plugin. Place a template file in the relevant path.
function custom_router( $query ) {
global $wp_query;
if($wp_query->query['name'] == 'test') :
var_dump($wp_query->query['name']);
var_dump($wp_query->query['page']);
return dirname( __FILE__ ) . '/some-template.php';
endif;
}
I tested the code in the latest wordpress version with a custom plugin and the default theme btw.
I have this in my index.php file. It adds the home banner image in WordPress. I know that it is mostly generated in WordPress customizer, but I need to add an anchor tag in this section. I can't find it anywhere in the file structure.
<?php do_action('cleanblog_index_top'); ?>
I'm not able to find where cleanblog_index_top leads to. Any help would be great. Thank you!
I stumbled on this old one while looking up the docs for do_action(). The answers are brutal so I decided to provide a better answer in case anyone else stumbles here.
If a WordPress theme has something like do_action( 'example_action_hook_tag' ) somewhere in one of the template files (such as index.php, page.php or whatever) the purpose is to provide theme or plugin authors with a way to write their own custom function that they can then "hook" onto the action with the function add_action().
WordPress would then call this function any time and anywhere do_action( 'example_action_hook_tag' ) is called.
The creators of commercial themes will often litter their template files with hooks declared with do_action() to make it easier for their customers to customize their themes via functions.php or by writing a site-specific plugin.
It looks to me that this is the likely scenario that is impacting the OP. This also explains why the OP was unsuccessful in finding where this "leads to".
It would only "lead somewhere" if the OP wrote a function in the theme/child-theme functions.php or in a plugin and added the line do_action( 'cleanblog_index_top', 'name_of_ops_function' ) to hook their function onto the cleanblog_index_top. WordPress would then call their function when do_action( 'cleanblog_index_top' ) was called in index.php.
From the name of the OP's hook, cleanblog_index_top, it sounds like the theme author intended to provide a way for others to inject output at the top of the index page template.
Suppose the OP wanted <h1>Hello World</h1> to appear there.
In functions.php of a theme/child-theme the OP could add a function that echo's this out:
function op_customization() {
echo '<h1>Hello World</h1>';
}
And hook their function onto cleanblog_index_top:
add_action( 'cleanblog_index_top', 'op_customization' );
Cheers!
You should never edit the index.php file directly, for the same reason you should never edit core Wordpress files directly - the next time WP pushes an update, your changes will be overwritten (and that assumes you don't break anything). Never edit plugin files directly, same reason.
You need to look in your theme, you should only make changes to the functions.php and style.css files in your theme - unless you create a child theme and that is a topic you should Google.
I can't work on any specific theme file like header.php, footer.php OR function.php within theme directory.
Reason is project always need new theme and theme is get changes in each week.
So I want something like that will work on each theme, no matter which theme admin applied.
I tried wp_enqueue_script() but again I need work on theme's function.php file.
The only way to do this is to run wp_enqueue_script() from outside of the theme (i.e. NOT in functions.php). The only way you can do that is to use a plugin.
See: http://codex.wordpress.org/Must_Use_Plugins
Or: http://codex.wordpress.org/Writing_a_Plugin
Create a plugin by adding a .php file in the /wp-content/plugins/ directory, or possibly even better for this situation create a 'must use' plugin by creating a .php file in the /wp-content/mu-plugins/ directory.
The structure of this .php file should be something like the following:
<?php
/*
Plugin Name: Example Plugin
Description: Any functions that should persist even if the theme changes.
Author: Your Name
Version: 1.0
Author URI: http://yoururl.com
*/
function my_scripts() {
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
}
add_action('wp_enqueue_scripts', 'my_scripts' );
?>
You need to write a plugin that rewrites theme's sections. A good start for creating a plugin is here. If your themes shares the same Javascript you could try to add your things to those Js.
1. Shortcode (working)
I have made a Shortcode which display the current weatherinformations from yahoo. There was 3 Files (simple-pie.inc, simple-pie-yahoo.inc and yahooweather.php) and I grabed the content of these files and pasted it inside my function.php – works good!
This looks so and got more then 16.000 Lines of Code:
// Add Shortcode for weather
function get_rohrau_wetter() {
content of simple-pie.inc
content of simple-pie-yahoo.inc
content of yahooweather.php -> return "weather-html"
}
add_shortcode( 'rohrauwetter', 'get_rohrau_wetter' );
2. Plugin (no clue where to start)
All I want to do is making a Plugin out of my working shortcode to get that "wall-of-code" out of my function.php and of course for better reuseability. Also I think so it will be possible to turn the simple-pie cache to "on" for faster processing…
My Question is: How do I convert my Shortcode into an Plugin?
A good place to start would the plugin handbook: https://developer.wordpress.org/plugins/the-basics/header-requirements/
But the cheap and nasty way to place it into a plugin, create a directory for your plugin, create a index.php (realistically it can be any name) file. Add this in
<?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
Author URI: https://developer.wordpress.org/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wporg
Domain Path: /languages
*/
Then underneath it add in your above functions. Obviously Change out the text to suit yourself so that you can identify the plugin. Then upload it too your plugins directory.
As I said, this is the cheap and nasty way to set it up. I would advise to have a look at the plugin handbook I linked to above. Also Using OOP plugin development is advised, a good starting point is Tom McFarlin tutorial on tutsplus: https://code.tutsplus.com/series/object-oriented-programming-in-wordpress--cms-699 .. and after that well worth looking at https://github.com/DevinVinson/WordPress-Plugin-Boilerplate and https://wppb.me/ hope that all helps.