WordPress plugin how to run function when button is clicked

Create form or link with action=”my_media_update” <form action=”<?php echo admin_url(‘admin-post.php’); ?>” method=”post”> <input type=”hidden” name=”action” value=”my_media_update”> <input type=”submit” value=”Update Media Titles and ALT Text”> </form> Add this function and hook in your plugin file: public function kh_update_media_seo() { //update media files title and alt tags here // // at the end redirect to target page … Read more

Integrating colorpicker into array field

Real quick this should point you in the right direction, you need to define your colorpicker and then reference it, so like: switch( $arguments[‘type’] ){ case ‘text’: case ‘password’: case ‘number’: printf( ‘<input name=”%1$s” id=”%1$s” type=”%2$s” placeholder=”%3$s” value=”%4$s” />’, $arguments[‘uid’], $arguments[‘type’], $arguments[‘placeholder’], $value ); break; case ‘colorpicker’: printf( ‘<input name=”%1$s” id=”%1$s” type=”%2$s” placeholder=”%3$s” value=”%4$s” />’, … Read more

The Events Calendar featured image as body background?

<?php $id = get_the_ID(); if (has_post_thumbnail( $id ) ): $thumb = get_the_post_thumbnail_url($id, ‘full’); elseif (tribe_event_featured_image( $id)): $thumb = tribe_event_featured_image( $event_id, ‘large’, false, false ); else: $thumb = get_template_directory_uri().’/images/background.jpg’; endif;?> <body <?php body_class(); ?> style=”background-image: url(‘<?php echo $thumb;?>’); background-size: cover;”> ?> Also you don’t actually need the elseif statement, tribe_event_featured_image is a wrapper for the post … Read more

Allow user to add the php code in wp_mail()

I would just use str_replace() to handle a “pseudo” shortcode. Something like this: $body = sprintf(‘Hey {{username}}, your awesome post has been published! See <%s>’, get_permalink($post) ); // Add replacement values to the array as necessary. $old = array( ‘{{username}}’ ); $new = array( esc_html($user->display_name) ); $body = str_replace( $old, $new, $body ); // Now … Read more