Hook In Wordpress - wordpress

I modify wp_hash_password and wp_check_password with my own encryption password, I want to use hook now. This is to make sure when my wordpress update the latest version, my wp_hash_password and wp_check_password in pluggable.php still is my own password encryption, the hook should add at where? Look on Internet, some say put in user.php and some say put in function.php in theme. If who know, please tell me the answer.

Plugins are loaded first, then pluggable.php and then lastly the theme. Subsequently, you need to create a plugin and place your pluggable functions code in there otherwise your custom code won't be loaded. Create a file called custom_wp_password_override.php or whatever you want to label it and place it in your plugin's folder adding in your own custom function code. You should never update core files such as user.php as this will be overwritten when you upgrade WordPress.
<?php
/*
Plugin Name: Custom WordPress Passwords
Plugin URI: http://localhost
Description: Override wordpress pluggable password functions.
Version: 1.0.0
Author: Your Name
Author URI: http://locahost
Text Domain: custom-wp-passwords
*/
if ( !function_exists('wp_check_password') ) :
function wp_check_password($password, $hash, $user_id = '') {
// Your custom code in here
}
endif;
if ( !function_exists('wp_hash_password') ) :
function wp_hash_password($password) {
// Your custom code here
}
endif;
?>

So the first thing I know when into WordPress development is not to edit any files in two folders: wp-include and wp-admin. Or you will lose all your edit when update WordPress to the newer version.
Back to your question, if you think you will not change the theme in the future, put your code in child theme's functions.php. Yeah, child theme will not affect when you update your parent theme.
And I think, the best solution for you is creating a simple WordPress plugin, put your code in, and activate that plugin. So your encryption will not lose when you update WordPress core/theme/other plugins even.
<?php
/*
Plugin Name: WP Custom Plugins
Plugin URI: http://link to your plugin homepage
Description: This plugin changes WordPress hashing password encryption.
Version: 1.0
Author: Someone
Author URI: http://link to your website
License: GPL2 etc
License URI: https://link to your plugin license
/* Your code goes below here */

Related

Can I set wordpress theme via code

I have been working on wordpress for a while. I know that we can manage themes via the admin panel and the selected theme and its configuration details are stored in the database.
Is there any way I can set the theme via my wordpress code?
Have a look at the switch_theme function on the Codex
Description
Switches current theme to new template and stylesheet names.
Accepts one argument: $stylesheet of the theme. ($stylesheet is the name of your folder slug. It's the same value that you'd use for a child theme, something like twentythirteen.) It also accepts an additional function signature of two arguments: $template then $stylesheet. This is for backwards compatibility.
Usage
<?php switch_theme( $stylesheet ) ?>

change frontend language wordpress

I am trying to change my theme language in the frontend from english to german . I have changed also wp-config.php file . But it doesn't work. I am using wordpress 4.0
Can some one what should to do change language?
You can do the following:
Get the the language pack (e.g. de_DE.mo) from wordpress.org. If the language pack isn't available as a standalone download, you could also use the .mo file which is bundled in the WordPress ZIP-file for your language. Located under wp-content/languages.
Move the .mo file to wp-content/languages/ of your default (english) WordPress installation.
Change the WPLANG constant in wp-config.php to the new locale (e.g. de_DE)
In your functions.php add the following filter:
functions.php
add_filter('locale', 'wpse27056_setLocale');
function wpse27056_setLocale($locale) {
if ( is_admin() ) {
return 'en_US';
}
return $locale;
}
Reference - https://wordpress.stackexchange.com/questions/27056/different-language-for-frontend-and-backend
Take a look at WordPress Codex - Translating WordPress
Additionally you can use WP plugins especially for translating your WP website:
Codestyling Localization
User Language Switch
Setup your site in the desired language in the admin settings and then download this plugin. In it you can setup the language for your admin backend side only ;)
http://wordpress.org/extend/plugins/kau-boys-backend-localization/
You can use the google translate plugin for wordpress. For more info see the plugin page.
Google Translate WordPress » WP Translate
I wanted to change the language in the front-end and keep the language in the backend the same. I tried using adding a filter to in function.php but that didn't work for me. What did was using a plugin - Backend localization
Change Language of Woocomerce through Functions Or change language of wodpress
/* ==== Function Start ==== */
add_filter('gettext', 'translate_reply44');
add_filter('ngettext', 'translate_reply44');
function translate_reply44($translated) {
$translated = str_ireplace('Undo?', 'numaları sipariş silindi. Sepete geri almak istiyorsanız tıklayın? ', $translated);
return $translated;
}
/* ==== Function END ==== */
Since 4.7, you should do the following:
function wp_noshor_redefine_locale($locale) {
if( is_admin() ):
switch_to_locale('en_US');
endif;
}
add_filter('init','wp_noshor_redefine_locale');
this changes the dashbaord to English while setting front-end to the language you choose from the setting option.

wordpress ajax for a plugin only works when defined in the active theme

I'm testing with very simple code to try and get ajax working from within a plugin I'm writing. However I always get the dreaded 0 returned from the admin-ajax.php file.
The basic code defined in my plugins main php file is:
// Init custom actions
add_action( 'wp_ajax_import_run', 'import_run' );
function import_run() {
echo "testing 123";
die();
}
And then import_run is the action parameter parsed via the jquery ajax call.
Now the funny thing is, this works fine when I place the above php code in the themes main function.php file, but whenever I place the code in the actual plugin where it's needed it won't work. The issue is it needs to be in the plugin, not the theme.
So it seems I'm missing some small vital step about where to put my add action and function within the plugin. Any ideas?
you haven't provided your complete code in your plugin.
You can't invoke plugin function using wp ajax call.
Here's a simple WP plugin code to display some text everywhere.
<?php
/**
* #package Testplugin
*/
/*
Plugin Name: Testplugin
Plugin URI: someuri
Description: To demo a simple plugin
Version: 2.5.8
Author: Automattic
Author URI: http://automattic.com/wordpress-plugins/
License: GPLv2 or later
*/
function pluginnamehere() {
echo "This gets displayed everywhere";
}
add_action( 'plugins_loaded', 'pluginnamehere' );
I've worked out what was going on. I was adding the add_action hook everywhere but in the core root plugin page. Previously I had been adding it to a secondary php file that I thought was the root plugin file but wasn't.
The confusion occurred because I'm using a boilerplate empty plugin template to work with, so even though the plugin does very little so far its actually full of code and remarks already.

Wordpress plugin get version. Am I doing this correctly?

I want to make a plugin for all of my own wordpress-based websites.
The idea is simple, I want to get the version (and probably another info) of those sites by using CURL.
Right now, I have such a code:
<?php
/*
Plugin Name: Manage Site
Plugin URI: http://not-available-yet.com/
Description: A manage site plugin
Author: Go Frendi Gunawan
Version: 0.0
Author URI: http://not-available-yet.com/
*/
// this file is located on wp-content/plugins/manage_site
require_once '../../../wp-includes/version.php'; // do I need to include everything manually like this?
if(isset($_GET['key']))
{
$key = $_GET['key'];
if($key=='1234'){
echo $wp_version;
}
}
And I can access it by using CURL with this address:
http://my_domain.com/wordpress/wp-content/plugins/manage_site/manage_site.php?key=1234
And I'll get the wordpress version as a response:
3.5.1
It is work for now.
But, since this is my first time writing a wordpress plugin, I might do things wrongly. So, Am I doing it right? Or is there any better way to write this?
I've found the answer.
Both, #kjetilh and #brasofilo was right in case of accessing wordpress plugin "the normal way".
Since I access the plugin directly, the wordpress bootstrap is not loaded. Therefore, my first approach was partially right.
But load the wp-load.php is more elegant (and simple and usable) since it load everything, not only the version, and it gonna be useful to access 'more information':
<?php
/*
Plugin Name: Manage Site
Plugin URI: http://not-available-yet.com/
Description: A manage site plugin
Author: Go Frendi Gunawan
Version: 0.0
Author URI: http://not-available-yet.com/
*/
// this file is located on wp-content/plugins/manage_site
require_once '../../../wp-load.php';
if(isset($_GET['key']))
{
$key = $_GET['key'];
if($key=='1234'){
echo $wp_version;
}
}

Where do I save widget code for wordpress?

I've googled around quite a lot, but can't seem to find where I should be saving the code for the widget I've created. It's a bit baffling.
So, can anyone tell me where I should save my widget?
Thanks,
John.
You need to put your widget code in either the functions.php file of your current theme, or within a plugin. In order to put it in a plugin, create a new folder in the plugins folder and create a .php file with the name of the folder you created within that folder. In that file, use this code to start your plugin:
<?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
*/
?>
Obviously, change the values to something useful for your plugin. You can then paste your widget code into this file and it should be ready to use.
Sources:
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Plugin_API
As far as I know, widget (ie plugins) go in your wp-content/plugins folder eg. wp-content/plugins/YOUR WIDGET/
Is that what you need?
You can save your code in the file of wp-content\themes\YOUR-THEME-NAME\functions.php.

Resources