Which to use to execute code during the saving of a plugin settings page?

If you’re using Settings API, then you should use a sanitize callback: register_setting( $option_group, $option_name, $sanitize_callback ); The myth is that the $sanitize_callback actually is a filter for your options when it’s saved in the database. This is the place where you can do something with your custom code. This is the sample code: register_setting( … Read more

Hyphens vs. periods in the script slug in wp_register_script?

Use hyphens only. Take a look at wp-includes/script-loader.php: $scripts->add( ‘scriptaculous-sound’, ‘/wp-in $scripts->add( ‘scriptaculous-controls’, ‘/wp $scripts->add( ‘scriptaculous’, ”, array(‘sc // not used in core, replaced by Jcrop.js $scripts->add( ‘cropper’, ‘/wp-includes/js/cr $scripts->add( ‘jquery’, ‘/wp-includes/js/jqu // full jQuery UI $scripts->add( ‘jquery-ui-core’, ‘/wp-include $scripts->add( ‘jquery-effects-core’, ‘/wp-in $scripts->add( ‘jquery-effects-blind’, ‘/wp-i $scripts->add( ‘jquery-effects-bounce’, ‘/wp- $scripts->add( ‘jquery-effects-clip’, ‘/wp-in $scripts->add( ‘jquery-effects-drop’, ‘/wp-in $scripts->add( … Read more

Redirect old permalinks to new permalinks

WordPress should handle the 301 redirects for you automatically in this case. It doesn’t always, but it should here. Long story short, WordPress has a function, redirect_guess_404_permalink which tries to find the correct post when it encounters a 404 by using the end of the 404 url to query against the wp_posts.post_name. If it finds … Read more

What are the current recommended best-practices for comments.php?

You really don’t need much. A headline with id=comments <h2 id=”comments”><?php comments_number(); ?></h2> This will be the target for comments_link() in the article loop. Links for paginated comments. Usually, I put these links into a function and call the function above and below the comments list: class TTT_Template { function comment_pager() { if ( get_comment_pages_count() … Read more

delete post also attachments

Maybe this works function remove_post() { if(isset($_POST[‘post_id’]) && is_numeric($_POST[‘post_id’])) { $post = get_post($_POST[‘post_id’]); if(get_current_user_id() == $post->post_author) { $args = array( ‘post_parent’ => $_POST[‘post_id’] ); $post_attachments = get_children($args); if($post_attachments) { foreach ($post_attachments as $attachment) { wp_delete_attachment($attachment->ID, true); } } wp_delete_post($_POST[‘post_id’], true); } } exit; } The code added function get_attachment_id_from_src ($image_src) { global $wpdb; $query = … Read more

Fallback when Transient API fails

Mark Jaquith made a “TLC Transients” method that you might find useful. Essentially, it implements a transient interface that does soft expiration and background updating. https://github.com/markjaquith/WP-TLC-Transients The idea is that you define a function to do the call that gets the data, then define the transient and pass it that function as a callback. When … Read more

How to make custom bulk actions work on the media/upload page?

If you want to use your code, try this: If you want to check if the medias are attachments, you can try to use $_REQUEST[‘detached’] add_action( ‘load-upload.php’, ‘export_media_test’ ); function export_media_test() { if ( ! isset( $_REQUEST[‘action’] ) ) return; echo ‘Export Media’; if ( isset( $_REQUEST[‘detached’] ) ) { die( ‘No attachments’ ); } … Read more

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