I've been trying to create a custom tab for my website and am using UltimateMember plugin.
After bit of google I found some code snippet that can help me do it:
First we need to extend main profile tabs
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
);
return $tabs;
}
Then we just have to add content to that tab using this action
add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
function um_profile_content_mycustomtab_default( $args ) {
echo 'Hello world!';
}
But my question, to what file should I add this code to achieve what I need. It sounds very numb of me to ask this, but I'm seriously confused.
Thanks for any help.
Let me share my similar experience. First of all in this code :
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
);
You should use always
mycustomtab
as key which I see you've already used. So that's true.
Generally it works out when you put this code in your active theme's functions.php
But if it doesn't work out, consider adding this to core file um-filters-misc.php in the plugin core file folder for ultimate-member. Let me know if it works for you.
Not sure if anyone still needs help on this, but make sure to add a 'custom' key/value like this:
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
'custom' => true // <- needs to be added so it shows up on the profile page
);
The code example in the UltimateMember documentation -specifically for extending the Profile Menu using hooks- doesn't work because the sample code doesn't have that line.
Hi guys thanks for your help... im using this codes and works "good"... if a want to put shotcode the website print "blue screen" error... [ultimatemember form_id="15817"] (if i use "hello word" works perfect..
function um_mycustomtab_add_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'Seguimiento',
'icon' => 'um-faicon-pencil',
);
return $tabs;
}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );
// Action
function um_profile_content_mycustomtab_default( $args ) {
echo do_shortcode('[ultimatemember form_id="15817"]'); //this not work
}
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
here some screenshots tests
Related
I'm starting to develop it and I realise it's kind of tricky.
I need to convert the shortcode
[helloworld] into <h1>"Hello World"</h1>
and be able to change
"Hello World" from admin
Can someone point me on the right way?
You need create hellowrold as a shortcode.
function hellowrold_func( $atts ) {
$a = shortcode_atts( array(
'content' => 'Default content',
), $atts );
return "<h1>{$a['content']}</h1>";
}
add_shortcode( 'hellowrold', 'hellowrold_func' );
Then you can use it like this and change text as you like from the content attribute.
[hellowrold content="Hello World"]
See Shortcode API for more details.
If you need to add this to a plugin, simply create a file with a header content like this:
/**
* Plugin Name: YOUR PLUGIN NAME
*/
Add the code above below this header and put the file inside a folder in your plugins directory.
See Plugins Basics for more details.
For such kind of purpose, you need to use shortcode_atts (https://developer.wordpress.org/reference/functions/shortcode_atts/).
Simply define the below function
function torque_hello_world_shortcode( $atts ) {
$a = shortcode_atts( array(
'title' => 'Heading'
), $atts );
return '<h1>"' . $a["title"] . '"</h1> from admin';
}
To use the above function, simply add the below shortcode .....
1. [helloworld title="Hello World"]
returns
"Hello World" from admin
2. [helloworld title="Hi"]
returns
"Hi" from admin
I have made my first plugin and it all works on the front end but I am having some weird backend conflict with the gutenberg. I have done two things, made my plugin automatically add the pages / overwrite them when they've checked off, and made the plugin shortcode.
Here is the problem on my gutenberg:
As you can see there are random red diamonds on the page. When I use the inspector I can see it has code from my plugin I created...
Here is how I created my plugin
First inside my functions page I registered a new short code.
add_shortcode('parts_listing_portal', 'portal_parts_list');
function portal_parts_list(){
include "shortcodes/parts_listing_shortcode.php";
return ;
}
Then I made content for inside the shortcode using JS, PHP, and HTML.(this is a big file with includes and API calls)
After the page looked the way I would like, I created a new function to work on my option submit. This function creates the page with the shortcode inside.
//Add parts
if ( get_option( 'parts' ) === "checked") {
$parts_list = array(
'post_title' => 'Parts',
'post_type' => 'page',
'post_name' => 'Parts',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_content' => '[parts_listing_portal]',
'post_status' => 'publish',
'post_author' => get_user_by( 'id', 1 )->user_id,
'menu_order' => 0
);
// PARTS LIST
if(get_page_by_title('Parts') == null) {
wp_insert_post($parts_list);
}else{
$post_exists = get_page_by_title("Parts" );
$update_post = array('ID' => $post_exists->ID);
$post_update = wp_parse_args($parts_list, $update_post);
wp_update_post($post_update);
}
When my function adds to the page & you go to the gutenberg editor it shows the full page for a split second then goes away. I feel I missed a statement somewhere to only show on "page" but I have no idea where to look. I've spent a lot of time researching it but couldn't find it.
Thank you
Whenever adding a shortcode make sure to check iif in admin area. If in admin area return nothing
function portal_parts_list(){
if ( is_admin()){
return;
}else {
include "shortcodes/parts_listing_shortcode.php";
return ;
}
}
add_shortcode('part_description_portal', 'portal_parts_list');
My Wordpress site uses custom template pages like this one:
<php
/*
Template Name : project_costs
/*
get_header ();
// set default vars or user received
require("my_forms.php");
// pull data from db and calculate
require("project_calculation. php");
// create page
require("content. php");
...
My custom page project_costs.php performing the steps :
Receive and set user entered vars from page forms (POST/GET).
Pull data from database.
Do some calculations and changes.
Creates page for user.
I want to integrate angular.js with the WP-API plugin. The plugin just pulls raw data from database (step 2) and sends it to front end (step 4). So pages and templates not in use as page didn't reload.
I want to pass data to my php class first (step 3), then pass changed data to WP-API.
Is there any function in WP-API to call my PHP file or function?
Any advice, samples or links would be highly appreciated.
Thanks.
So I'm working on a huge project which includes several API/Angular replacement parts for #WordPress. One file is a custom endpoint-boilerplate.php. It works like a charm so far but any input would be appreciated.
Just follow the structure and use the my_awesome_function to return do anything you'd like. Then the namespace and route from the hook will be available, using data from my_awesome_func.
<?php
/* ------------------------------------------------------------------------ *
A great example of custom endpoints is the PHP in wp-api-menus plugin
* ------------------------------------------------------------------------ */
// hook into rest_api_init and register a new api route
add_action( 'rest_api_init', function () {
register_rest_route(
'custom-endpoint/v2', // namespace
'/author/(?P<id>\d+)', // route
array( // options
'methods' => 'GET',
'callback' => 'my_awesome_func',
// 'args' => array(
// 'context' => array(
// 'default' => 'view',
// ),
// )
)
);
});
function my_awesome_func( $data ) {
$posts = get_posts( array(
'author' => $data['id'],
) );
if ( empty( $posts ) ) {
return null;
}
return $posts[0]->post_title;
}
So your call will then be a get to http://yourproject.com/wp-json/custom-endpoint/v2/author/1
I've created a short code that I'm trying to pass an attribute into, but I don't seem to be receiving the value on the other end.
Here's what I've got below;
function list_display($atts) {
extract( shortcode_atts(
array(
'pageName' => 'No Page Received',
), $atts )
);
echo $pageName;
add_shortcode('list-briefings-display', 'list_display');
}
and the shortcode being used is
[list-display pageName="My Page Name"]
and I'm running a require_once from functions.php
require_once ( TEMPLATEPATH. '/includes/list-display.php' );
But what I'm seeing on the screen is 'No Page Received', can anyone think of something I might've missed?
There is more content being generated by the shortcode, which I have't included, that's rendering fine. So it just seems to be something to do with how I've passed the attribute.
Any help is appreciated.
function list_display($atts) {
$atts = shortcode_atts( array(
'pagename' => 'No Page Received'
), $atts );
extract($atts);
echo $pagename;
}
add_shortcode('list-display', 'list_display');
You'll probably want to use "return" instead of "echo" if you're using the shortcode within pages and posts.. Echo could cause it to send output to the screen a little too early and won't end up exactly where you may be expecting it to be.
There was also a little formatting issue in your code that I've corrected, mainly trying to use add_shortcode() from within the very same function you're trying to reference. I also changed the first parameter of add_shortcode() to the shortcode you were trying to use in your example.
I am using an options framework (NHP Theme Options) for my wordpress theme, I don't have a problem with things like adding things like 'if' statements, ex if option is selected 'echo' this information.
That alone allows for a lot of dynamic options. I added a wordpress editor box in my admin panel and I am a little lost on how I would output the information that is inside the box.
It's inside my theme options page inside an array,
array(
'id' => 'header-area',
'type' => 'editor',
'title' => __('Editor Option', 'my-opts'),
'sub_desc' => __('Can also use the validation methods if required', 'my-opts'),
'desc' => __('This is the description field, again good for additional info.', 'my-opts'),
'std' => 'headarea'
),
typically I use if statements, here is an example of how I output my options.
<?php if( my_opts_get('header-area') ) {
$fixed_header_css = 'top: 0;';
} else {
$fixed_header_css = 'top: 51px;';
} ?>
This is just an example, but I am a PHP novice and don't know how to output the editor array.
I know its not by using an if statement, I tried things like
<?php echo my_opts_get('header-area') ?>
I think that may be close, but I am obviously missing something
The answer was right under my nose, using this simple line of code was all I needed to output the data..
<?php echo moon_opts_get('header-present-area', 'home-area'); ?>