Add php user input controller to wordpress customizer - wordpress

Trying to customize the Wordpress Theme Customizer to allow users to input either a shortcode or a custom php string. Currently, I have many user input fields for text input, but I can't figure out how to sanitize the text correctly to allow for php.
Any suggestions on where to start?

Thank you user5552351 for your response.
After looking at the codex you referenced in your comment, I realized I was way over thinking the solution.
Turns out all I needed was to give the user a text input that allows for basic brackets [] and apostrophes '' while inside a do_shortcode function.
<?php echo do_shortcode(get_theme_mod( 'THEME_MOD_ID', 'THEME_MOD_DEFAULT_VALUE' ));?>
where THEME_MOD_ID is the identifier for the Theme Customizer Control. So Basically there's a section in my theme customizer called 'Contact' that holds a text input setting/control called 'custom_contact_form', where a user can input a shortcode (ex: [simple_contact_form] ) and it will replace everything between do_shortcode( + ). So my code might look something like this:
<?php echo do_shortcode(get_theme_mod( 'custom_contact_form', '' ));?>

Related

Show WordPress Editor in Plugin Settings

I want to show the user a WordPress Editor to be able to use media and text and etc like post editor and save it in the options table. Of course, I can't use textarea or input but how can I do it?
Needed to just use this simple code:
<?php wp_editor( $content , 'editor-id' ); ?>
Thanks for your votes by the way!

advanced-custom-fields the_field function not work in wordpress

I'm trying to use the the_field(); function in wordpress but did't work
also I tried to use the get_field(); function and same problem what I can do
<?php the_field('contact_form_short_code'); ?>
I am using advanced-custom-fields plugin the free version
the_field('contact_form_short_code') will try to get the field info from the current post in the loop. If you're not currently in a loop it will look to the current page/post.
If you want to reference a post from outside the loop you must specify the post ID, eg: the_field('contact_form_short_code', $post_id)
Hope that helps
Check if your field group location points to your template, taxonomy or custom post type, after that try to use echo to call your field.
Check this link www.advancedcustomfields.com
If you want to display the shortcode (contact_form_short_code) specified in the admin panel via a custom field (ACF), you need to use the do_shortcode(); function.
In your case, the code looks like this:
<?php
//In the admin panel we fill the shortcode of the contact form, for example CF7.
//[contact-form-7 id="1" title="Form"]
$cform = get_field('contact_form_short_code', $post_id);
//Output of shortcode
echo do_shortcode($cform);?>

ACF get the value of an options field in a plugin

I am using the Advanced Custom Fields plugin with the options add on.How can I use the value of a field from options in a plugin?I have a simple php file in the plugins folder that needs to get this value. Is that possible?
For anyone searching for the solution:
Suppose your options field is a text field named "my_option_field_01".
In your php, if you wanted to display the value of that option field inside of a paragraph tag, you would put this:
<p><?php echo get_field('my_option_field_01', 'option'); ?></p>

How to include a Wordpress Shortcode in your Code, not in the Posts Section

I want to insert a hardcoded short code in my code, and not from the usual Text Editor we usually use.
Basically I want this to add a gallery, and the user doesn't need to change the shortcode from the CMS so I will be hardcoding this.
How would I need to do this, I tried to just post it in my .php file but it doesn't work.
This is the code I want to add:
[jj-ngg-jquery-slider gallery="1" width="866" height="341" ]
This will do the trick to include in .php files:
<?php echo do_shortcode('[jj-ngg-jquery-slider gallery="1" width="866" height="341"]'); ?>
shortcodes were created to include in post or pages. I could be wrong but wordpress checks the input of a post and if it finds a shortcode it will replace it with the html. I don't think it will work if you add shortcodes in your .php file because wordpress doesn't look for shortcodes in your php files
You could just create a function in functions.php to generate the html you need. Then you just call that function within your theme .php file. That's how most plugins are made. Shortcode for post & pages and function in the php files.
example:
<?php echo myGallery(array('gallery'=>1, 'width'=>866, 'height' => 341); ?>
Did you try this method ? do_shortcode($content)
I've seen it on http://codex.wordpress.org/Shortcode_API

WordPress ShortTag Custom Variable

I like to have a whole website build in wordpress. All through the site there will be telephone number, address, some link here and there...
I like to be able to defin variable shorttag in the admin panel somewhere, and be able to insert it in the WYSIWYG like that :
you can contact us anytime [phone] or visit us here : [address]
so changing addres or number is a snap !
any idea, i got http://wordpress.org/extend/plugins/custom-configs/screenshots/ but need to insert in php not shorttag...
You can use the do_shortcode() function to output the shortcode values using php. Assuming that
Example:
<? echo do_shortcode('[phone]'); ?>
Using your plugin is easy to define shortcodes that are outputting the content of a custom setting
function get_phone($atts, $content = null) {
return get_config('phone-settings');
}
add_shortcode('phone', 'get_phone');
Assuming that in your plugins, you have defined a custom settings with the key phone-settings

Resources