Conditional check for front-end which includes ajax

DOING_AJAX and WP_ADMIN (this constant is checked within is_admin() ) are defined in admin-ajax.php and set tro true. Both are not very helpfull in this situation. Add a parameter to your ajax request if the request come from the front-end: <?php function my_action_javascript() { ?> <script type=”text/javascript” > jQuery(document).ready(function($) { var data = { action: … Read more

front end post with multiple upload images?

the multiple=”multiple” or multiple=”” attribute of input file tag is fairly new and not widely supported cross browser but if that is the way you want to go, try this: <form … <input type=”file” id=”image” name=”image[]” onchange=”updateList();” multiple=”multiple” > <ul id=”file_list”></ul> </form> <script> function updateList(){ //get the input and UL list var input = document.getElementById(‘image’); … Read more

Edit a post from frontend. post_tags get saved, but not separated

Ok, found a solution by myself. In the past i saved post_tags with wp_set_post_terms($pid, array($_POST[‘post_tags’]),’post_tag’,false); Now i save the post_tags with wp_set_post_tags($pid, $_POST[‘post_tags’]); and it works. This way is the same method, i use to publish a new post from the frontend. Changed only this, nothing else.

How to restrict Front-End Editor on a page?

From the GitHub-Wiki The ‘front_end_editor_disable’-filter Use this filter if you want to completely disable the plugin for certain URLs. Callback arguments: bool $disable: The current state. Default: false You can use conditional tags: Conditionals tags return bool true/false, which means, if you want to disable it on a page, simply use is_page(), as it returns … Read more

Listing registered scripts

There’s a global variable called $wp_scripts which is an instance of the WP_Scripts class. It doesn’t have a public API for looking at registered or enqueued scripts, but you can look inside the object and see what’s going on. You can see all the registered scripts with: global $wp_scripts; var_dump( $wp_scripts->registered ); To see the … Read more

How to add media from front-end to an existing post?

@AboSami actually answered this question in an older post that was not showing up in my search diligence. While he was actually looking for something else his example code worked great. Here’s the script: <?php $post_id = $post->ID; if ( isset( $_POST[‘html-upload’] ) && !empty( $_FILES ) ) { require_once(ABSPATH . ‘wp-admin/includes/admin.php’); $id = media_handle_upload(‘async-upload’, … Read more

Prevent empty Post Title on form submit via front end post (wp_insert_post_)

Simply put the wp_insert_post call inside your conditional check so its only called if the post title is not empty, something like this: if (empty($_POST[‘my_title’])){ echo ‘error: please insert a title’; } else { $title = $_POST[‘my_title’]; $new_post = array( ‘post_title’ => $title, ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’); $pid = wp_insert_post($new_post); }

Get names of authors who have edited a post

The WordPress function get_the_modified_author() will give you the author who last edited the current post. But if you want to list all the users that have edit the current post, you could try: function get_the_modified_authors_wpse_99226(){ global $wpdb; $authors = array(); $results = $wpdb->get_results( $wpdb->prepare(“SELECT post_author FROM $wpdb->posts WHERE (post_type=”%s” AND ID = %d) OR (post_type=”revision” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)