Rename plugin name in Wordpress Dashboard Menu - wordpress

I have tried a lot of suggestions on different posts here, but none of them seem to work for me.
I want to rename the name of a plugin on the dashboard menu on my Wordpress site. The name of the plugin is Sensei LMS and the path of the plugin folder is /plugins/sensei-lms.
I'd appreciate if someone helps me with some code that I can use to rename this. Thank you

I've used this tutorial in the past.
In your case, it would be:
function my_renamed_admin_menu_items() {
global $menu;
// Define your changes here
$updates = array(
"Sensei LMS" => array(
'name' => 'New Menu Name'
),
"Another Menu Name" => array(
'name' => 'Another New Name'
)
);
foreach ($menu as $k => $props) {
// Check for new values
$new_values = (isset($updates[$props[0]])) ? $updates[$props[0]] : false;
if (!$new_values) continue;
// Change menu name
$menu[$k][0] = $new_values['name'];
}
}
add_action('admin_init', 'my_renamed_admin_menu_items');

Related

ACF field to create sets of pages when saved

I have an odd request, i'm not sure if this is even possible. But i'll try to work out the process below, and if anyone can help me work this out that would be amazing!
Ideally the process is as follows:
Admin goes to parent options page, within the options page there is a repeater field, called add new company. This will just be a field with a title.
Admin fills in field and presses save. This will generate a sub options page with that name, within the options field, there will be a set of fields like logo, a colour picker and some text fields (these could be a set of fields from within ACF if thats possible).
Also when this original Repeater Field is made/saved a set of pages is generated from a set of templates. Essentially using the name from the repeater field to be the main page title for the top level page and all the sub pages below are just dynamically generated. They don't need to have anything different about them, they just need to generate from a set of page templates. It needs to be able to associate with the newly generated company bits from the sub options field.
This will then essentially give the admin a new set of pages which will use the new options logo / colours etc. It would almost need to generate a new set of templates based off the master templates to dynamically make sure it picked up the correct information from the sub options page.
I'm not sure if this is possible, I have seen it work elsewhere on another job I have worked on (not exactly the same as the above but similar), but I can't work out the process to make it work sadly, as I have a horrid feeling that there is some complex bits within the database going on to do the duplication dynamically.
My other option is to run everything as a WordPress Multisite but I was trying to avoid that if possible on this occasion, but I may have to use Multisite to achieve the above.
If anyone can help me work this out that would be amazing!
Thanks in advance for any help :)
You should be able to plug into the save_post action and create new subpages from there.
add_action( 'save_post', 'create_sub_pages' ); //Plug into save_post action
//Function create sub_pages
function create_sub_pages($post_ID) {
//Repeater field name
$repeater_field_array = get_field('repeater_field_name');
//Loops through all of the items in the repeater field
foreach($repeater_field_array as $key => $value) {
//Check to see if there is already a sub page with that post name
$child_pages = get_pages(array( 'child_of' => $post_ID ));
$child_page_exists = false;
foreach($child_pages as $pages) {
if ($pages->post_title === $key) {
$child_page_exists = true;
}
}
//If not, set up the creation of the new post
if ($child_page_exists === false) {
$new_page_title = esc_html__( $key );
$new_page_content = '';
$new_page = array(
'post_type' => 'page',
'post_date' => esc_attr( date('Y-m-d H:i:s', time()) ),
'post_date_gmt' => esc_attr( date('Y-m-d H:i:s', time()) ),
'post_title' => esc_attr( $new_page_title ),
'post_name' => sanitize_title( $new_page_title ), //This could from the sub_field in the repeater
'post_content' => $new_page_content,
'post_status' => 'publish',
'post_parent' => $post_ID,
'menu_order' => $new_page_order
);
$new_page_id = wp_insert_post( $new_page );
update_post_meta( $new_page_id, '_wp_page_template', $value );
}
}
}
Again, this is just a spitball since there was not much code to review, but it could help you get going in the right direction.

Adding User Profile Fields to Wordpress Buddypress to Include "Favorites"

I'm trying to figure out a way for members on my Wordpress (Buddypress) site to pick their "favorite movies, books, etc."
It would be nice if, instead of members simply typing a list of these things, they could select from books already in the system, and add more as the please in the future.
I'm hoping that there is an easy answer to this, such as a plugin that I can use, or, at least, modify. Does anyone know of anything that I can look into?
Your title asks how to add a user profile field. Here is the code to add as many fields as you like. Once you add the field, you can easily place additional inputs or options on the custom tab page for users to enter their own favorites.
function my_test_setup_nav() {
global $bp;
$parent_slug = ‘test’;
$child_slug = ‘test_sub’;
//name, slug, screen, position, default subnav
bp_core_new_nav_item( array(‘name’ => __( ‘Test’ ),’slug’ => $parent_slug,’screen_function’ => ‘my_profile_page_function_to_show_screen’,'position’ => 40,’default_subnav_slug’ => $child_slug ) );
/* Add the subnav items to the profile */
// name, slug, parent_url, parent slug, screen function
bp_core_new_subnav_item( array( ‘name’ => __( ‘Home’ ), ‘slug’ => $child_slug, ‘parent_url’ => $bp->loggedin_user->domain . $parent_slug.’/', ‘parent_slug’ => $parent_slug, ‘screen_function’ => ‘my_profile_page_function_to_show_screen’ ) );
bp_core_new_subnav_item( array( ‘name’ => __( ‘Random Page’ ), ‘slug’ => ‘random’, ‘parent_url’ => $bp->loggedin_user->domain . $parent_slug.’/', ‘parent_slug’ => $parent_slug, ‘screen_function’ => ‘my_profile_page_function_to_show_screen234′ ) );
}
function my_profile_page_function_to_show_screen() {
//add title and content here – last is to call the members plugin.php template
add_action( ‘bp_template_title’, ‘my_profile_page_function_to_show_screen_title’ );
add_action( ‘bp_template_content’, ‘my_profile_page_function_to_show_screen_content’ );
bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
}
function my_profile_page_function_to_show_screen_title() {
echo ‘wptaskforce title’;
}
function my_profile_page_function_to_show_screen_content() {
echo ‘wptaskforce content’;
}
//random page content:
function my_profile_page_function_to_show_screen234() {
//add content here – last is to call the members plugin.php template
add_action( ‘bp_template_content’, ‘my_profile_page_function_to_show_screen234_content’ );
bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
}
function my_profile_page_function_to_show_screen234_content() {
echo ‘This is a random page.’;
}
add_action( ‘bp_setup_nav’, ‘my_test_setup_nav’ );

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/

how to populate widgets on sidebar on theme activation

What I am trying to do is pre-populate the sidebar widget area with some default widgets on theme activation.
if ( ! dynamic_sidebar( 'sidebar' ) ) :
does add the widgets but it doesnot show up in the sidebar of widgets section and
if ( is_active_sidebar( 'sidebar' ) ) {
this function doesnot work if the widgets are not loaded in the sidebar widgetized area.
I know it is possible but I am just out of idea. I googled but didnot find any solutions. Thank you for any help in advance.
It isn't clear from your answer if you use the after_switch_theme hook but that the moment you need to set the widgets.
To activate the widgets I suggest writing it directly into the database with get_option('sidebars_widgets') which should give an array, and save it with update_option('sidebars_widgets', $new_activated_widgets).
This should help you get started.
/**
* set new widgets on theme activate
* #param string $old_theme
* #param WP_Theme $WP_theme
*/
function set_default_theme_widgets ($old_theme, $WP_theme = null) {
// check if the new theme is your theme
// figure it out
var_dump($WP_theme);
// the name is (probably) the slug/id
$new_active_widgets = array (
'sidebar-name' => array (
'widget-name-1',
'widget-name-2',
'widget-name-3',
),
'footer-sidebar' => array(
'widget-name-1',
'widget-name-2',
'widget-name-3',
)
);
// save new widgets to DB
update_option('sidebars_widgets', $new_active_widgets);
}
add_action('after_switch_theme', 'set_default_theme_widgets', 10, 2);
Tested, just paste it in functions.php of your theme.
If anyone else needed to know how to add multiple default widgets (different instances) to multiple sidebars at the same time, the following code will add the widgets both to the page and under the admin widget tab. I realize that this may have been obvious to everyone but me.
So based on janw and kcssm's hard work:
function add_theme_widgets($old_theme, $WP_theme = null) {
$activate = array(
'right-sidebar' => array(
'recent-posts-1',
'categories-1',
'archives-1'
),
'footer-sidebar' => array(
'recent-posts-2',
'categories-2',
'archives-2'
)
);
/* the default titles will appear */
update_option('widget_recent-posts', array(
1 => array('title' => ''),
2 => array('title' => '')));
update_option('widget_categories', array(
1 => array('title' => ''),
2 => array('title' => '')));
update_option('widget_archives', array(
1 => array('title' => ''),
2 => array('title' => '')));
update_option('sidebars_widgets', $activate);
}
add_action('after_switch_theme', 'add_theme_widgets', 10, 2);
This will however delete any other settings, so tread carefully!

WP Backend: Create custom menu for specific User Group

I am using Members plugin to manage User Groups (restrict pages/posts for specific user group) now to show the links to that user group in back-end I need a plugin for creating Custom Menu where the allowed pages/posts links will be shown (back-end) for the specific user group.
Sorry, dont know exatly which plugin or code would solve your problem.
But here are some resources:
http://codex.wordpress.org/Roles_and_Capabilities#Resources
http://wordpress.org/extend/plugins/tags/capability
Well what I do is to add this script in my theme's function.php
// Admin bar menu w.r.t role
function wp_admin_bar_new_item() {
global $wp_admin_bar;
if (current_user_can('contractor')){
$wp_admin_bar->add_menu(array(
'id' => 'wp-admin-bar-new-item',
'title' => __('Contractor Menu'),
'href' => 'http://my_site/contractor/'
));
} elseif (current_user_can('consultant')) {
$wp_admin_bar->add_menu(array(
'id' => 'wp-admin-bar-new-item',
'title' => __('Consultant Menu'),
'href' => 'http://my_site/consultant/'
));
}
}
add_action('wp_before_admin_bar_render', 'wp_admin_bar_new_item');
and fix my issue.

Resources