How to customize the add media button, popup with my custom html in the popup window after clicking the button in wordpress - wordpress

I have the below code. I need a button like add media in the edit page of admin, in which on click shows a popup and displays my custom html with a form in it.
I tried with below but I am getting the unnecessary things like Upload files tab, Media library tab etc., I don't need all these but I just need my custom form on button clicked.
index.php
function add_cp_media_button() {
echo 'cp Forms';
}
function include_cp_media_button_js_file() {
wp_enqueue_script('media_button', plugins_url( '/js/cp.js', __FILE__ ), array('jquery'), '1.0', true);
}
add_action('wp_enqueue_media', 'include_cp_media_button_js_file');
cp.js
jQuery(function($) {
$(document).ready(function(){
$('#cp-forms-btn').click(open_media_window);
});
function open_media_window() {
//I want to display the form with select drop down with my names populated in the dropdown, after selecting the item, I need to insert the text to the editor.
}
});
Could someone help me on this

Related

Add class to the UPDATE button in wordpress admin, only if an input fields has changed

I want to make it more obvious for a the editor that they need to click the UPDATE button after they made any changes to a wordpress page.
If a class can be added to the UPDATE button once any field, be it title, description or a custom field, has changed, then I can change the colour or make it pulsate.
Thank you
This goes into the functions.php of your child theme. To make your own animation you have to insert the CSS inside the Tag in the code snippet.
add_action('admin_head', 'orders_list_preview_css');
function orders_list_preview_css() {
echo "<script>
jQuery(document).ready(function($) {
$('body').on('keydown', '*[contenteditable=\"true\"]', function() {
if ($('.editor-post-publish-button.clicktoupdate').length < 1) {
$('.editor-post-publish-button').addClass('clicktoupdate')}
})
$('body').on('keydown', 'input', function() {
if ($('.editor-post-publish-button.clicktoupdate').length < 1) {
$('.editor-post-publish-button').addClass('clicktoupdate')}
})
})</script>";
echo "<style>/*cssgoeshere*/</style>";

Remove button added by a tinymce plugin

I want to hide the link options button shown in tinymce plugin (wpload), the one that shows up when clicking "Link" button..
Is there any call like
tinymce.PluginManager.get('pluginName').removeButton(...) ?
More specifically I want to remove Link Options from wplink plugin tinymce version 4.5.6. I saw this call in the plugin code, wonder how I can remove it from my custom WP plugin (dont want to hack the wplink plugin itself)?
editor.addButton( 'wp_link_advanced', {
tooltip: 'Link options',
icon: 'dashicon dashicons-admin-generic',
onclick: function() {
if ( typeof window.wpLink !== 'undefined' ) {
....
You need to create a WP plugin and use the mce_buttons hook to change the list of toolbar buttons that the editor will load.
It would look something like this:
add_filter('mce_buttons', 'remove_link_button', 2000);
function remove_link_button( $buttons ) {
// Remove the toolbar button for the link plugin
$remove = array('link');
return array_diff( $buttons, $remove );
}
I would note that this would note fully remove the link plugin's functionality - it would just remove that toolbar button. The plugin also has right click functionality on links so if you want all the functionality gone you also need to use the tiny_mce_before_init hook to remove the plugin from the list of plugins to be loaded.
Note: There are lots of examples of how to create a WP plugin so I am not going to repeat them here ... the code above would need to go into a WordPress plugin to function properly in WordPress.

How to go on next page in gravity form without click on "next" button

i have created a Multi-pages survey form in "gravity form". By default its go on next page when i click on "Next" button. Is there any way to open next page with out click on "Next Button"
My form - http://dev23.cashframework.com/
For example if i choose "Purchase" option (radio Button) then automatically open next page of form.
I have tried to do that all through "Condition Logic" but no success
You can use jQuery trigger to trigger the next button once the radio input has been changed:
$(function(){
jQuery('#input_1_2 input:radio').change(function() {
jQuery('#gform_next_button_1_4').trigger('click');
});
});
You can then use CSS to hide the next button.
just to add to the first answer:
add this to your functions.php file
add_action( 'wp_enqueue_scripts', 'autoprogress' );
function autoprogress() {
wp_enqueue_script(
'autoprogress',
get_template_directory_uri() . '/js/autoprogress.js',
array('jquery') /
);
}
then create a JS file called autoprogress.js and create individual jquery functions for each radio section and next button (inspect the element). so #input_1_1, #input_1_2 etc
$(function(){
jQuery('#input_#_# input:radio').change(function() {
jQuery('#gform_next_button_#_#').trigger('click');
});
});
I wouldn't recommend hiding the next button as if the user goes back they cannot progress without selecting a new answer.
use this snippet to auto advance on already selected radio buttons
$(function(){
jQuery('#input_#_# input:radio').click(function() {
jQuery('#gform_next_button_#_#').trigger('click');
});
});
You can use "Multi page auto advance for gravity forms" plugin. You can download it for free in wordpress.

add a button to execute a custom function in wordpress admin edit page area

In my website when I publish a page I want to write a file representing that page's itself (content, title, url, etc).
In my function.php I've create a function to generate the file called on event:
add_action ( 'publish_page', 'generateFile' );
function generateFile($pageId){
.....
}
The above code works well.
Now I want to call the function "generateFile" when the user press an apposite button in the admin edit page area, so I want to add a new button beside the "publish" button to call my function on click.
Is it possible? How can I accomplish this?
You can hook into post_submitbox_start action,
// To add button
add_action( 'post_submitbox_start', function() {
print '<a href="path-to-plugin/generate.php">Generate file</button>';
});
This will add button right next to publish, or a better way of doing this would be to hook into the save_post action and grab all the details of a post through it.
http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

To remove the mediaLibrary Tab from wp.media

I have use a custom button for uploading images to wordpress media. But I dont want the "mediaLibraryTitle" in the popup. I have done this by using this code snippet.
function remove_medialibrary_tab($tabs) {
if ( current_user_can( 'administrator' ) ) {
unset($tabs["mediaLibraryTitle"]);
}
return $tabs;
}
add_filter('media_view_strings', 'remove_medialibrary_tab');
But when i test it is only removing the tab title, But i want remove the tab completely. Also i want to select the "Upload Files" tab by default. Is there any custom function to remove the tab or it can be possible by wp.media function in JS. If yes can you give any idea.
Thank you.

Resources