File manager - Edit - /home/proidvn/me.proid.vn/wp-content/plugins/demo card update plugin/demo card plugin.php
Back
// Add a new menu item to the WordPress admin dashboard function my_plugin_menu() { add_menu_page( 'Update Post Metadata', // Page title 'Update Post Metadata', // Menu title 'manage_options', // Capability 'update-post-metadata', // Menu slug 'my_plugin_update_post_metadata' // Function to call ); } add_action( 'admin_menu', 'my_plugin_menu' ); // Callback function to display the form function my_plugin_update_post_metadata() { ?> <div class="wrap"> <h1>Update Post Metadata</h1> <form method="post" action=""> <?php wp_nonce_field( 'update-post-metadata' ); ?> <label for="post-links">Enter post links (one per line):</label><br> <textarea id="post-links" name="post_links" rows="10" cols="50"></textarea><br> <label for="meta-key">Enter meta key:</label><br> <input type="text" id="meta-key" name="meta_key"><br> <label for="meta-value">Enter meta value:</label><br> <textarea id="meta-value" name="meta_value" rows="5" cols="50"></textarea><br> <<input type="submit" name="submit" value="Update Metadata"> </form> </div> <?php } // Update the metadata of the selected posts function my_plugin_update_metadata() { if ( ! current_user_can( 'manage_options' ) ) { return; } // Get the post links and meta data from the form submission $post_links = $_POST['post_links']; $meta_key = $_POST['meta_key']; $meta_value = $_POST['meta_value']; // Split the post links into an array $post_links_array = explode( "\n", str_replace( "\r", "", $post_links ) ); // Loop through each post link and update the metadata foreach ( $post_links_array as $post_link ) { $post_id = url_to_postid( $post_link ); if ( $post_id ) { update_post_meta( $post_id, $meta_key, $meta_value ); } } // Redirect back to the form after updating the metadata wp_redirect( add_query_arg( 'updated', 'true', $_SERVER['HTTP_REFERER'] ) ); exit; } add_action( 'admin_post_update_metadata', 'my_plugin_update_metadata' ); // Handle form submission if ( isset( $_POST['submit'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'update-post-metadata' ) ) { my_plugin_update_metadata(); }
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Generation time: 0.12 |
proxy
|
phpinfo
|
Settings