Changing the word 'post' to 'project' in WordPress - wordpress

For my users, the word 'post' does not reflect what they are actually adding when submitting a 'post'. For them, it's a project.
I'd like to change the word 'post' everywhere it appears in the admin area to be 'project', is there a function I can add to do this?
Thanks

add this to your functions.php
add_filter('gettext', 'change_post_to_project');
add_filter('ngettext', 'change_post_to_project');
function change_post_to_project($translated) {
$translated = str_ireplace('Post', 'Project', $translated);
return $translated;
}

Related

wp_link_query: Classic editor link popup adds custom CPT links again and again

When I integrate my CPT into the link search of the Classic Editor, it is at first displayed correctly.
But if there are more links in the list than can be displayed at the same time (overflow) and I then scroll up and down again, the list is updated by Wordpress via Ajax and my CPT links are appended again, so that the link list becomes longer and longer.
The default Wordpress links (post, page) on the other hand do not, even though my ID and the permalink in the $results array are unique.
There is nothing more than ID, title, permalink and info in the original $results array.
How can I prevent the appending?
add_filter('wp_link_query', array($this, 'wp_link_query'), 10, 2);
[...]
public function wp_link_query($results, $query) {
[...]
$results[] = array(
'ID' => $id,
'title' => $title,
'permalink' => $permalink,
'info' => $info
);
return $results;
}
The solution was to add the custom post type to the link query args first:
add_filter('wp_link_query_args', array($this, 'wp_link_query_args'), 10, 1);
[...]
public function wp_link_query_args($query) {
$query['post_type'][] = 'my_cpt';
return $query;
}
ยดยดยดยด
But you have to still use the 'wp_link_query' filter to add the "info" of the link popup table. Otherwise Wordpress outputs "Null" for the custom post type.

Wordpress replace all ocurrances of the string in admin

I am trying to change the words for various places in Wordpress Admin, for example, change the name of "Dashboard" to something else, but I want it to change across the entire Admin - all the occurances. I tried searching through admin files and replacing words, but this is just too much time consuming.
I don't need the words to be translatable, is there any way to do this? Thanks!
Put this code to the function.php file of your child theme:
add_filter( 'gettext', 'dirty_translate' );
add_filter( 'ngettext', 'dirty_translate' );
function dirty_translate( $translated ) {
$words = array(
// 'word to translate' => 'translation'
'Dashboard' => 'Foo',
'Add new' => 'Bar'
);
$translated = str_ireplace( array_keys($words), $words, $translated );
return $translated;
}
Just replace the translations with your own. You can add as many translations as you need. I'm using this myself - Tested and works.

Wordpress Profile File / Page

I would like to create a file in the Wordpress theme, where i will add my own code, edit profile, show profile information, and perhaps an ability to insert posts / meta data programmatically.
So it needs to be www.mysite.com/profile.php or www.mysite.com/profile/
I do not want to use Buddy Press or any other plugin.
I know how the template system works, i do not want a page template.
It will probably be a class, later on, i do not want to change .htaccess file, and if i must i would appreciated filter function how to do this from functions.php
Basically just a simple .php file i can link to, located in theme root.
include('../../../wp-load.php');
and write any code i would like to.
Any creative solution that is not too "hacky" would be appreciated.
Spent around 2 days googling bashing my head on this, before i decided to ask question.
Thank you very much.
Ok, I managed to do this, took me 2 days to figure it out. Here is how I managed to do it:
Make a plugin folder.
In that plugin folder make 1x php file. so index.php
Ok so first thing we need to register plugin I did it like this, in your index.php paste
this code.
function activate_profile_plugin() {
add_option( 'Activated_Plugin', 'Plugin-Slug' );
/* activation code here */
}
register_activation_hook( __FILE__, 'activate_profile_plugin' );
Then we need a function when you register a plugin only once register profile pages.
function create_profile_page( $title, $slug, $post_type, $shortcode, $template = null ) {
//Check if the page with this name exists.
if(!get_page_by_title($title)) {
// if not :
$page_id = -1;
$page_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'open',
'post_content' => $shortcode,
'post_author' => 1, // Administrator is creating the page
'post_title' => $title,
'post_name' => strtolower( $slug ),
'post_status' => 'publish',
'post_type' => strtolower( $post_type )
)
);
// If a template is specified in the function arguments, let's apply it
if( null != $template ) {
update_post_meta( get_the_ID(), '_wp_page_template', $template );
} // end if
return $page_id;
}
}
Ok so we created function which programatically register pages. It has 5 paramethers.
is Title
Slug
Post type
Shortcode.
Template
For the shortcode template you need to make a shortcode with the complete page output
and add it as a parameter to this function, so for registration page it will be a shortcode with the registration forms etc.
For example :
function registration_shortcode(){
echo 'Wellcome to Registration page';
}
add_shortcode('registration_output', 'registration_shortcode');
Next thing we need to call it once only when plugin loads.
so we do this :
function load_plugin() {
if ( is_admin() && get_option( 'Activated_Plugin' ) == 'Plugin-Slug' ) {
delete_option( 'Activated_Plugin' );
/* do stuff once right after activation */
// example: add_action( 'init', 'my_init_function' );
create_profile_page('Registration', 'registration', 'page', '[registration_output]');
create_profile_page('Profile', 'profile', 'page', '[profile_shortcode]');
create_profile_page('Profil Edit', 'profile-edit', 'page', '[edit_shortcode]');
}
}
add_action( 'admin_init', 'load_plugin' );
Ok so this will execute only once when plugin loads and it will create 3 Pages, which are Profile, Registration and Profile Edit.
And that's it, you have your front-end user profile blank pages, and you can write page output in shortcodes ,create more pages, put any forms or elements you like and create decent profile (which doesn't have any stuff you don't need in it like plugins. )
Hope this helps, it was painful for me to figure this out. Cheers!

How to edit page heading in wordpress admin panel?

I am making a plugin for custom wordpress admin panel theme, I have changed most of the things as per my requirement using hooks but I am unable to change Page Heading in Admin Panel in wordpress.
I am trying this, this is working fine for me, anyone having better solution
add_filter( 'gettext', 'change_post_to_article1' );
add_filter( 'ngettext', 'change_post_to_article1' );
function change_post_to_article1( $translated )
{
$translated = str_replace( 'Users', 'Customers', $translated );
$translated = str_replace( 'Add New User', 'Add New Customer', $translated );
return $translated;
}
I'm not sure how is your Admin Panel, but you can try this
array( "name" => "Heading",
"desc" => "Select heading style",
"id" => $shortname."_style",
"type" => "select",
"options" => array("heading.css", "heading2.css"),
"std" => ""),
Where heading.css is your setting file. In this case you have a special css file ore more, where you can setup your heading.
Tell me if is ok!
Like i said, creating a Wordpres Theme Admin Panel it's not so easy, but they are a lot of tutorials on internet. After a few days of searching i finally created the theme admin panel.
I will share this:
http://5wpthemes.com/blog/how-to-create-a-wordpress-theme-admin-panel/

Posts from category not displaying when searching for category name

I'm having trouble with my search results page in that it is not displaying posts that are a part of a category when searching for the category name. For Instance, If I search for "doors" (which is a cat) all Partners that are in the "doors" category should be displayed in the search results. Right now, only partners that have the word "doors" in their title or content is displayed.
I'm running a searchAll function so the the standard wp search will search everything.
// Define what post types to search
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
}
return $query;
}
// The hook needed to search ALL content
add_filter( 'the_search_query', 'searchAll' );
What am I missing?
your query is seraching for post_type, not category_name.
post_type is used for custom post types or taxonomies ..
your query should contain $query->set( 'category_name', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
however, in some cases (and I do not know the reason) that would not work for sub-categories.
in that case, you should use category-slug (slug) insted.
Ive changed my string to this:
<?php
// Define what post types to search
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'category_name', array( 'post', 'page', 'feed', 'partner','project', 'press', 'review' ));
}
return $query;
}
// The hook needed to search ALL content
add_filter( 'pre_get_posts', 'searchAll' );
I do have custom taxonomies though. Basically I'm trying to create a "Search everything" function.

Resources