Changeset 3233035
- Timestamp:
- 02/01/2025 11:22:50 AM (14 months ago)
- Location:
- add-pingbacks
- Files:
-
- 7 added
- 4 edited
- 1 copied
-
assets/assets.md (added)
-
tags/1.2pre (copied) (copied from add-pingbacks/trunk)
-
tags/1.2pre/LICENSE (added)
-
tags/1.2pre/README.md (added)
-
tags/1.2pre/add-pingbacks.js (added)
-
tags/1.2pre/add-pingbacks.php (modified) (1 diff)
-
tags/1.2pre/readme.txt (modified) (1 diff)
-
trunk/LICENSE (added)
-
trunk/README.md (added)
-
trunk/add-pingbacks.js (added)
-
trunk/add-pingbacks.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
add-pingbacks/tags/1.2pre/add-pingbacks.php
r861760 r3233035 1 1 <?php 2 2 /* 3 Plugin Name: Add Pingbacks 4 Plugin URI: http://simonquasar.net/add-pingbacks 5 Description: Manually add Pingbacks to a Post or a Page 6 Version: 1.1 7 Author: simonquasar 8 Author URI: http://simonquasar.net 9 License: GPLv2 10 Copyright 2014 Simon Pilati (http://simonquasar.net) 3 * Plugin Name: Add Pingbacks 4 * Plugin URI: https://simonquasar.net/add-pingbacks 5 * Description: Manually add a Pingback to any post. 6 * Version: 1.2 7 * Requires at least: 5.0 8 * Requires PHP: 7.4 9 * Author: simonquasar 10 * Author URI: https://simonquasar.net/ 11 * License: GPL v2 or later 12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 13 * Update URI: https://github.com/simonquasar/add-pingbacks 14 * Text Domain: add-pingbacks 11 15 */ 12 16 13 function addPingbacks_set_plugin_meta( $links, $file ) { 14 $plugin_base = plugin_basename(__FILE__); 15 if ( $file == $plugin_base ) { 16 $newlinks = array( '<a href="options-general.php?page=addPingbacks">Add Pingback</a>' ); 17 return array_merge( $links, $newlinks ); 18 } 19 return $links; 17 defined('ABSPATH') || exit; 18 19 function add_pingbacks_set_plugin_meta($links, $file) { 20 $plugin_base = plugin_basename(__FILE__); 21 if ($file === $plugin_base) { 22 $new_links = [ 23 '<a href="options-general.php?page=addPingbacks">' . esc_html__('Add Pingback', 'addPingbacks') . '</a>' 24 ]; 25 return array_merge($links, $new_links); 26 } 27 return $links; 20 28 } 21 29 22 function add Pingbacks_options_init() {23 register_setting( 'addPingbacks-group', 'addPingbacks-options', 'addPingbacks_validate_input');30 function add_pingbacks_options_init() { 31 register_setting('addPingbacks-group', 'addPingbacks-options', 'add_pingbacks_validate_input'); 24 32 } 25 33 26 function add Pingbacks_validate_input( $input) {27 return $input;34 function add_pingbacks_validate_input($input) { 35 return sanitize_text_field($input); 28 36 } 29 37 30 function addPingbacks_options_link() { 31 add_comments_page( 'Add Pingbacks', 'Add Pingbacks', 'manage_options', 'addPingbacks', 'addPingbacks_options_page' ); 32 } 33 34 function addPingback_select_box( $posttype ) { 35 36 if( $posttype == 'page' ) 37 $args = array( 38 'numberposts' => '9000', 39 'post_type' => 'page', 40 'post_status' => 'all' ); 41 42 else 43 $args = array( 44 'numberposts' => '9000', 45 'post_type' => 'post', 46 'post_status' => 'all' ); 47 48 $items = get_posts( $args ); 49 50 echo '<select name="' . $posttype . 's_list" id="' . $posttype . '">'; 51 52 foreach( $items as $item ) 53 echo '<option value="' . $item->ID . '">' . apply_filters('the_title',$item->post_title) . '</option>'; 54 38 function add_pingbacks_options_link() { 39 add_submenu_page('edit-comments.php', 'Add Pingbacks', 'Add Pingbacks', 'manage_options', 'addPingbacks', 'add_pingbacks_options_page', 'dashicons-admin-comments'); 55 40 } 56 41 57 function addPingback_text_box( $label, $name, $default=NULL ) { ?> 58 <tr> 59 <td><label for="<?php echo $name ?>"><?php echo $label ?></label></th> 60 <td colspan="2"><input type="text" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $default; ?>"/></td> 61 </tr> 62 <?php 42 function add_pingbacks_enqueue_scripts($hook) { 43 if ('comments_page_addPingbacks' !== $hook) { 44 return; 45 } 46 47 wp_enqueue_script( 48 'add-pingbacks-js', 49 plugins_url('add-pingbacks.js', __FILE__), 50 array('jquery'), 51 '1.0.0', 52 true 53 ); 54 55 wp_localize_script( 56 'add-pingbacks-js', 57 'wpApiSettings', 58 array('ajaxUrl' => admin_url('admin-ajax.php')) 59 ); 63 60 } 64 61 65 function addPingbacks_add_comments( $id, $author, $email, $url, $ip, $comment ) { 66 67 if( empty( $comment ) ) { return false;} 68 else { 69 wp_insert_comment( array( 70 'comment_post_ID' => $id, 71 'comment_author' => $author, 72 'comment_author_email' => $email, 73 'comment_author_url' => $url, 74 'comment_content' => $comment, 75 'comment_type' => 'pingback', 76 'comment_parent' => 0, 77 'user_id' => '', 78 'comment_author_IP' => $ip, 79 'comment_agent' => 'Add Pingbacks Plugin', 80 'comment_date' => current_time( 'mysql' ), 81 'comment_approved' => 1 ) ); 82 return true; 62 function get_post_types_dropdown() { 63 $post_types = get_post_types(array('public' => true), 'objects'); 64 $options = ''; 65 foreach ($post_types as $post_type) { 66 $options .= '<option value="' . esc_attr($post_type->name) . '">' . esc_html($post_type->label) . '</option>'; 83 67 } 68 return $options; 84 69 } 85 70 86 function addPingbacks_options_page() { 87 88 if( $_POST['action'] == 'addpingback' ) { 89 echo '<div class="updated settings-error">'; 90 $id = ( $_POST['post_or_page'] == 'page' ? $_POST['pages_list'] : $_POST['posts_list'] ); 91 $author = ( isset( $_POST['author_name'] ) ? $_POST['author_name'] : 'anonymous' ); 92 $email = ( isset( $_POST['author_email'] ) ? $_POST['author_email'] : get_bloginfo('admin_email' ) ); 93 $url = ( isset( $_POST['author_url'] ) ? $_POST['author_url'] : '' ); 94 $ip = ( isset( $_POST['author_ip'] ) ? $_POST['author_ip'] : '127.0.0.1' ); 95 echo addPingbacks_add_comments( $id, $author, $email, $url, $ip, $_POST['comment'] ) 96 . ' Pingback added to ' . get_the_title( $id ) . '</div>'; 97 } ?> 71 function add_post_select_box() { 72 echo '<select name="post_type" id="post_type" onchange="fetchPosts(this.value)">'; 73 echo '<option value="">- select Post type -</option>'; 74 echo get_post_types_dropdown(); 75 echo '</select>'; 98 76 99 <div class="wrap"> 100 <div class="icon32" id="icon-options-general"><br /></div> 101 <h2>Add Pingback URLs</h2> 102 <span class="description">Select a Post or a Page, then add the referral URL which points to your content. Play fair. ;)<br/> 103 Plugin by <a href="http://simonquasar.net" target="_blank" title="simonquasar">simonquasar</a></span> 104 <form method="post" action=""> 105 106 <table class="form-table"> 107 <tbody> 108 <tr> 109 <th colspan="3" style="font-size:1.3em">Where to add?</th></tr> 77 echo '<select name="post_list" id="post_list" style="display:none;"></select>'; 78 } 79 80 function add_pingback_text_box($label, $name, $default = '') { 81 ?> 82 <tr> 83 <td><label for="<?php echo esc_attr($name); ?>"><?php echo esc_html($label); ?></label></td> 84 <td colspan="2"><input type="text" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($name); ?>" value="<?php echo esc_attr($default); ?>"/></td> 85 </tr> 86 <?php 87 } 88 89 function add_pingbacks_add_comment($post_id, $author, $email, $url, $ip, $comment) { 90 if (empty($comment)) { 91 return new WP_Error('empty_comment', __('Comment cannot be empty', 'addPingbacks')); 92 } 93 94 return wp_insert_comment([ 95 'comment_post_ID' => $post_id, 96 'comment_author' => $author, 97 'comment_author_email' => $email, 98 'comment_author_url' => $url, 99 'comment_content' => $comment, 100 'comment_type' => 'pingback', 101 'comment_parent' => 0, 102 'comment_author_IP' => $ip, 103 'comment_agent' => 'Add Pingbacks Plugin', 104 'comment_date' => current_time('mysql'), 105 'comment_approved' => 1 106 ]); 107 } 108 109 function add_pingbacks_options_page() { 110 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'addpingback') { 111 $post_id = intval($_POST['post_list']); 112 $author = !empty($_POST['author_name']) ? sanitize_text_field($_POST['author_name']) : __('anonymous', 'addPingbacks'); 113 $email = !empty($_POST['author_email']) ? sanitize_email($_POST['author_email']) : get_bloginfo('admin_email'); 114 $url = !empty($_POST['author_url']) ? esc_url($_POST['author_url']) : ''; 115 $ip = !empty($_POST['author_ip']) ? sanitize_text_field($_POST['author_ip']) : '127.0.0.1'; 116 117 $result = add_pingbacks_add_comment($post_id, $author, $email, $url, $ip, sanitize_textarea_field($_POST['comment'])); 118 $message = is_wp_error($result) ? $result->get_error_message() : sprintf(__('Pingback added to %s', 'addPingbacks'), esc_html(get_the_title($post_id))); 119 120 echo '<div class="updated settings-error"><p>' . esc_html($message) . '</p></div>'; 121 } 122 ?> 123 124 <div class="wrap"> 125 <h2><?php esc_html_e('Add Pingback URLs', 'addPingbacks'); ?></h2> 126 <span class="description"> 127 <?php esc_html_e('Select a Post Type and a corresponding Post, then add the referral URL which points to your content. Play fair. ;)', 'addPingbacks'); ?><br/> 128 <?php printf(__('Plugin by <a href="%s" target="_blank" title="%s">%s</a>', 'addPingbacks'), esc_url('http://simonquasar.net'), esc_attr__('simonquasar', 'addPingbacks'), esc_html__('simonquasar', 'addPingbacks')); ?> 129 </span> 130 131 <form method="post" action=""> 132 <table class="form-table"> 133 <tbody> 134 <tr> 135 <th colspan="3" style="font-size:1.3em"><?php esc_html_e('Select Post Type', 'addPingbacks'); ?></th> 136 </tr> 110 137 111 <tr> 112 <td style="width: 150px;"><strong>Post</strong></td> 113 <td><input type="radio" name="post_or_page" value="post" id="post" checked="checked" /><?php addPingback_select_box( 'post' ); ?></td> 114 </tr> 138 <tr> 139 <td><strong><?php esc_html_e('Post Type', 'addPingbacks'); ?></strong><br/><?php esc_html_e('Post Title:', 'addPingbacks'); ?></td> 140 <td><?php add_post_select_box(); ?></td> 141 </tr> 142 143 <tr> 144 <th colspan="3" style="font-size:1.3em"><?php esc_html_e('Referrer link', 'addPingbacks'); ?></th> 145 </tr> 115 146 116 <tr> 117 <td><strong>Page</strong></td> 118 <td><input type="radio" name="post_or_page" value="page" id="page" /><?php addPingback_select_box( 'page' ); ?></td> 119 </tr> 120 121 <tr> 122 <th colspan="3" style="font-size:1.3em">Referrer link</th></tr> 123 124 <?php 125 $authors = array( 126 array( 'name' => 'author_name', 'label' => 'Site Title / Page Name', 'default' => '' ), 127 array( 'name' => 'author_url', 'label' => 'Link', 'default' => 'http://' ) ); 128 129 foreach( $authors as $author ) 130 addPingback_text_box( $author['label'], $author['name'], $author['default'] ); 131 ?> 132 133 <tr> 134 <th colspan="2" style="font-size:1.3em">Excerpt / Content</th> 135 </tr> 136 <tr> 137 <td colspan="3"><textarea name="comment" id="comment" cols="120" rows="5">[...] cit. [...]</textarea></td> 138 </tr> 139 140 </tbody> 141 </table> 142 143 <p class="submit"> 144 <input type="hidden" name="action" value="addpingback" /> 145 <input type="submit" class="button-primary" value="Add Link Reference" /> 146 </p> 147 148 </form> 149 </div> 150 <?php } 147 <?php 148 $authors = [ 149 ['name' => 'author_name', 'label' => __('Site Title / Page Name', 'addPingbacks'), 'default' => ''], 150 ['name' => 'author_url', 'label' => __('Link', 'addPingbacks'), 'default' => 'http://'] 151 ]; 151 152 152 add_filter( 'plugin_row_meta', 'addPingbacks_set_plugin_meta', 10, 2 ); 153 add_action( 'admin_init', 'addPingbacks_options_init' ); 154 add_action( 'admin_menu', 'addPingbacks_options_link' ); 153 foreach ($authors as $author) { 154 add_pingback_text_box($author['label'], $author['name'], $author['default']); 155 } 156 ?> 157 158 <tr> 159 <th colspan="2" style="font-size:1.3em"><?php esc_html_e('Excerpt / Content', 'addPingbacks'); ?></th> 160 </tr> 161 <tr> 162 <td colspan="3"><textarea name="comment" id="comment" cols="120" rows="5">[...] cit. [...]</textarea></td> 163 </tr> 164 </tbody> 165 </table> 166 167 <p class="submit"> 168 <input type="hidden" name="action" value="addpingback" /> 169 <input type="submit" class="button-primary" value="<?php esc_attr_e('Add Link Reference', 'addPingbacks'); ?>" /> 170 </p> 171 </form> 172 </div> 173 <?php 174 } 175 176 add_action('wp_ajax_fetch_posts', function() { 177 $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; 178 $posts = get_posts([ 179 'post_type' => $post_type, 180 'numberposts' => -1, 181 'post_status' => 'publish', 182 ]); 183 184 $response = []; 185 foreach ($posts as $post) { 186 $response[] = [ 187 'ID' => $post->ID, 188 'title' => get_the_title($post->ID), 189 ]; 190 } 191 192 wp_send_json($response); 193 }); 194 195 add_filter('plugin_row_meta', 'add_pingbacks_set_plugin_meta', 10, 2); 196 add_action('admin_init', 'add_pingbacks_options_init'); 197 add_action('admin_menu', 'add_pingbacks_options_link'); 198 add_action('admin_enqueue_scripts', 'add_pingbacks_enqueue_scripts'); 155 199 ?> -
add-pingbacks/tags/1.2pre/readme.txt
r985122 r3233035 1 === Plugin Name===1 === Add Pingbacks === 2 2 Contributors: simonquasar 3 Tags: add pingbacks, pingback, manual pingbacks, comments, manual, add comments 4 Requires at least: 2.8 5 Tested up to: 4.0 6 Stable tag: 1.0 3 Tags: pingbacks, manual pingbacks, comments, linkbacks, custom post types, referrals 4 Requires at least: 5.0 5 Tested up to: 6.6.2 6 Requires PHP: 7.4 7 Stable tag: 1.2 7 8 License: GPLv2 or later 8 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 10 10 Manually add a Pingback to a post or page.11 Manually add pingbacks to any post, page, or custom post type in WordPress with a simple interface. 11 12 12 == Description == 13 Add Pingbacks is a WordPress plugin that allows you to manually create pingbacks for your posts, pages, and custom post types. This is particularly useful when you want to: 13 14 14 Adds an options page in the Comments menu. 15 You select on which Post/Page the referring Link should appear, add the Site name and URL, then paste the referring part. 15 * Add missing pingbacks that weren't automatically detected 16 * Manually create references between content 17 * Manage content relationships through pingbacks 18 * Add pingbacks for legacy content 19 20 = How It Works = 21 22 1. Select your post type from the dropdown menu 23 2. Choose the specific post you want to add the pingback to 24 3. Enter the referrer's site title and URL 25 4. Add the excerpt or content of the pingback 26 5. Click "Add Link Reference" to create the pingback 16 27 17 28 == Installation == 18 29 19 1. Download the zip file and extract the `add-pingbacks` directory. 20 2. Upload this directory inside your `/wp-content/plugins/` directory. 21 3. Browse to the `Add Comments` page on the Options menu. 30 1. Upload the `add-pingbacks` directory to your `/wp-content/plugins/` directory 31 2. Activate the plugin through the 'Plugins' menu in WordPress 32 3. Navigate to Comments > Add Pingbacks to start adding pingbacks 33 34 == Usage == 35 36 1. Go to Comments > Add Pingbacks in your WordPress admin 37 2. Select the post type and specific post you want to add a pingback to 38 3. Enter the referring site's details: 39 * Site Title / Page Name 40 * Link URL 41 4. Add the excerpt or content for the pingback 42 5. Click "Add Link Reference" to create the pingback 43 44 == Changelog == 45 46 = 1.2 = 47 * Added support for all public post types 48 * Dynamic post loading 49 * Dta sanitization 50 51 = 1.1 = 52 * Initial public release 22 53 23 54 == Support == 24 55 25 [[email protected]](mailto:[email protected]) 56 For support inquiries: 57 [github.com/simonquasar/add-pingbacks](https://github.com/simonquasar/add-pingbacks/) 58 59 == Credits == 60 61 Developed by [simonquasar](https://simonquasar.net/) -
add-pingbacks/trunk/add-pingbacks.php
r861760 r3233035 1 1 <?php 2 2 /* 3 Plugin Name: Add Pingbacks 4 Plugin URI: http://simonquasar.net/add-pingbacks 5 Description: Manually add Pingbacks to a Post or a Page 6 Version: 1.1 7 Author: simonquasar 8 Author URI: http://simonquasar.net 9 License: GPLv2 10 Copyright 2014 Simon Pilati (http://simonquasar.net) 3 * Plugin Name: Add Pingbacks 4 * Plugin URI: https://simonquasar.net/add-pingbacks 5 * Description: Manually add a Pingback to any post. 6 * Version: 1.2 7 * Requires at least: 5.0 8 * Requires PHP: 7.4 9 * Author: simonquasar 10 * Author URI: https://simonquasar.net/ 11 * License: GPL v2 or later 12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 13 * Update URI: https://github.com/simonquasar/add-pingbacks 14 * Text Domain: add-pingbacks 11 15 */ 12 16 13 function addPingbacks_set_plugin_meta( $links, $file ) { 14 $plugin_base = plugin_basename(__FILE__); 15 if ( $file == $plugin_base ) { 16 $newlinks = array( '<a href="options-general.php?page=addPingbacks">Add Pingback</a>' ); 17 return array_merge( $links, $newlinks ); 18 } 19 return $links; 17 defined('ABSPATH') || exit; 18 19 function add_pingbacks_set_plugin_meta($links, $file) { 20 $plugin_base = plugin_basename(__FILE__); 21 if ($file === $plugin_base) { 22 $new_links = [ 23 '<a href="options-general.php?page=addPingbacks">' . esc_html__('Add Pingback', 'addPingbacks') . '</a>' 24 ]; 25 return array_merge($links, $new_links); 26 } 27 return $links; 20 28 } 21 29 22 function add Pingbacks_options_init() {23 register_setting( 'addPingbacks-group', 'addPingbacks-options', 'addPingbacks_validate_input');30 function add_pingbacks_options_init() { 31 register_setting('addPingbacks-group', 'addPingbacks-options', 'add_pingbacks_validate_input'); 24 32 } 25 33 26 function add Pingbacks_validate_input( $input) {27 return $input;34 function add_pingbacks_validate_input($input) { 35 return sanitize_text_field($input); 28 36 } 29 37 30 function addPingbacks_options_link() { 31 add_comments_page( 'Add Pingbacks', 'Add Pingbacks', 'manage_options', 'addPingbacks', 'addPingbacks_options_page' ); 32 } 33 34 function addPingback_select_box( $posttype ) { 35 36 if( $posttype == 'page' ) 37 $args = array( 38 'numberposts' => '9000', 39 'post_type' => 'page', 40 'post_status' => 'all' ); 41 42 else 43 $args = array( 44 'numberposts' => '9000', 45 'post_type' => 'post', 46 'post_status' => 'all' ); 47 48 $items = get_posts( $args ); 49 50 echo '<select name="' . $posttype . 's_list" id="' . $posttype . '">'; 51 52 foreach( $items as $item ) 53 echo '<option value="' . $item->ID . '">' . apply_filters('the_title',$item->post_title) . '</option>'; 54 38 function add_pingbacks_options_link() { 39 add_submenu_page('edit-comments.php', 'Add Pingbacks', 'Add Pingbacks', 'manage_options', 'addPingbacks', 'add_pingbacks_options_page', 'dashicons-admin-comments'); 55 40 } 56 41 57 function addPingback_text_box( $label, $name, $default=NULL ) { ?> 58 <tr> 59 <td><label for="<?php echo $name ?>"><?php echo $label ?></label></th> 60 <td colspan="2"><input type="text" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $default; ?>"/></td> 61 </tr> 62 <?php 42 function add_pingbacks_enqueue_scripts($hook) { 43 if ('comments_page_addPingbacks' !== $hook) { 44 return; 45 } 46 47 wp_enqueue_script( 48 'add-pingbacks-js', 49 plugins_url('add-pingbacks.js', __FILE__), 50 array('jquery'), 51 '1.0.0', 52 true 53 ); 54 55 wp_localize_script( 56 'add-pingbacks-js', 57 'wpApiSettings', 58 array('ajaxUrl' => admin_url('admin-ajax.php')) 59 ); 63 60 } 64 61 65 function addPingbacks_add_comments( $id, $author, $email, $url, $ip, $comment ) { 66 67 if( empty( $comment ) ) { return false;} 68 else { 69 wp_insert_comment( array( 70 'comment_post_ID' => $id, 71 'comment_author' => $author, 72 'comment_author_email' => $email, 73 'comment_author_url' => $url, 74 'comment_content' => $comment, 75 'comment_type' => 'pingback', 76 'comment_parent' => 0, 77 'user_id' => '', 78 'comment_author_IP' => $ip, 79 'comment_agent' => 'Add Pingbacks Plugin', 80 'comment_date' => current_time( 'mysql' ), 81 'comment_approved' => 1 ) ); 82 return true; 62 function get_post_types_dropdown() { 63 $post_types = get_post_types(array('public' => true), 'objects'); 64 $options = ''; 65 foreach ($post_types as $post_type) { 66 $options .= '<option value="' . esc_attr($post_type->name) . '">' . esc_html($post_type->label) . '</option>'; 83 67 } 68 return $options; 84 69 } 85 70 86 function addPingbacks_options_page() { 87 88 if( $_POST['action'] == 'addpingback' ) { 89 echo '<div class="updated settings-error">'; 90 $id = ( $_POST['post_or_page'] == 'page' ? $_POST['pages_list'] : $_POST['posts_list'] ); 91 $author = ( isset( $_POST['author_name'] ) ? $_POST['author_name'] : 'anonymous' ); 92 $email = ( isset( $_POST['author_email'] ) ? $_POST['author_email'] : get_bloginfo('admin_email' ) ); 93 $url = ( isset( $_POST['author_url'] ) ? $_POST['author_url'] : '' ); 94 $ip = ( isset( $_POST['author_ip'] ) ? $_POST['author_ip'] : '127.0.0.1' ); 95 echo addPingbacks_add_comments( $id, $author, $email, $url, $ip, $_POST['comment'] ) 96 . ' Pingback added to ' . get_the_title( $id ) . '</div>'; 97 } ?> 71 function add_post_select_box() { 72 echo '<select name="post_type" id="post_type" onchange="fetchPosts(this.value)">'; 73 echo '<option value="">- select Post type -</option>'; 74 echo get_post_types_dropdown(); 75 echo '</select>'; 98 76 99 <div class="wrap"> 100 <div class="icon32" id="icon-options-general"><br /></div> 101 <h2>Add Pingback URLs</h2> 102 <span class="description">Select a Post or a Page, then add the referral URL which points to your content. Play fair. ;)<br/> 103 Plugin by <a href="http://simonquasar.net" target="_blank" title="simonquasar">simonquasar</a></span> 104 <form method="post" action=""> 105 106 <table class="form-table"> 107 <tbody> 108 <tr> 109 <th colspan="3" style="font-size:1.3em">Where to add?</th></tr> 77 echo '<select name="post_list" id="post_list" style="display:none;"></select>'; 78 } 79 80 function add_pingback_text_box($label, $name, $default = '') { 81 ?> 82 <tr> 83 <td><label for="<?php echo esc_attr($name); ?>"><?php echo esc_html($label); ?></label></td> 84 <td colspan="2"><input type="text" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($name); ?>" value="<?php echo esc_attr($default); ?>"/></td> 85 </tr> 86 <?php 87 } 88 89 function add_pingbacks_add_comment($post_id, $author, $email, $url, $ip, $comment) { 90 if (empty($comment)) { 91 return new WP_Error('empty_comment', __('Comment cannot be empty', 'addPingbacks')); 92 } 93 94 return wp_insert_comment([ 95 'comment_post_ID' => $post_id, 96 'comment_author' => $author, 97 'comment_author_email' => $email, 98 'comment_author_url' => $url, 99 'comment_content' => $comment, 100 'comment_type' => 'pingback', 101 'comment_parent' => 0, 102 'comment_author_IP' => $ip, 103 'comment_agent' => 'Add Pingbacks Plugin', 104 'comment_date' => current_time('mysql'), 105 'comment_approved' => 1 106 ]); 107 } 108 109 function add_pingbacks_options_page() { 110 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'addpingback') { 111 $post_id = intval($_POST['post_list']); 112 $author = !empty($_POST['author_name']) ? sanitize_text_field($_POST['author_name']) : __('anonymous', 'addPingbacks'); 113 $email = !empty($_POST['author_email']) ? sanitize_email($_POST['author_email']) : get_bloginfo('admin_email'); 114 $url = !empty($_POST['author_url']) ? esc_url($_POST['author_url']) : ''; 115 $ip = !empty($_POST['author_ip']) ? sanitize_text_field($_POST['author_ip']) : '127.0.0.1'; 116 117 $result = add_pingbacks_add_comment($post_id, $author, $email, $url, $ip, sanitize_textarea_field($_POST['comment'])); 118 $message = is_wp_error($result) ? $result->get_error_message() : sprintf(__('Pingback added to %s', 'addPingbacks'), esc_html(get_the_title($post_id))); 119 120 echo '<div class="updated settings-error"><p>' . esc_html($message) . '</p></div>'; 121 } 122 ?> 123 124 <div class="wrap"> 125 <h2><?php esc_html_e('Add Pingback URLs', 'addPingbacks'); ?></h2> 126 <span class="description"> 127 <?php esc_html_e('Select a Post Type and a corresponding Post, then add the referral URL which points to your content. Play fair. ;)', 'addPingbacks'); ?><br/> 128 <?php printf(__('Plugin by <a href="%s" target="_blank" title="%s">%s</a>', 'addPingbacks'), esc_url('http://simonquasar.net'), esc_attr__('simonquasar', 'addPingbacks'), esc_html__('simonquasar', 'addPingbacks')); ?> 129 </span> 130 131 <form method="post" action=""> 132 <table class="form-table"> 133 <tbody> 134 <tr> 135 <th colspan="3" style="font-size:1.3em"><?php esc_html_e('Select Post Type', 'addPingbacks'); ?></th> 136 </tr> 110 137 111 <tr> 112 <td style="width: 150px;"><strong>Post</strong></td> 113 <td><input type="radio" name="post_or_page" value="post" id="post" checked="checked" /><?php addPingback_select_box( 'post' ); ?></td> 114 </tr> 138 <tr> 139 <td><strong><?php esc_html_e('Post Type', 'addPingbacks'); ?></strong><br/><?php esc_html_e('Post Title:', 'addPingbacks'); ?></td> 140 <td><?php add_post_select_box(); ?></td> 141 </tr> 142 143 <tr> 144 <th colspan="3" style="font-size:1.3em"><?php esc_html_e('Referrer link', 'addPingbacks'); ?></th> 145 </tr> 115 146 116 <tr> 117 <td><strong>Page</strong></td> 118 <td><input type="radio" name="post_or_page" value="page" id="page" /><?php addPingback_select_box( 'page' ); ?></td> 119 </tr> 120 121 <tr> 122 <th colspan="3" style="font-size:1.3em">Referrer link</th></tr> 123 124 <?php 125 $authors = array( 126 array( 'name' => 'author_name', 'label' => 'Site Title / Page Name', 'default' => '' ), 127 array( 'name' => 'author_url', 'label' => 'Link', 'default' => 'http://' ) ); 128 129 foreach( $authors as $author ) 130 addPingback_text_box( $author['label'], $author['name'], $author['default'] ); 131 ?> 132 133 <tr> 134 <th colspan="2" style="font-size:1.3em">Excerpt / Content</th> 135 </tr> 136 <tr> 137 <td colspan="3"><textarea name="comment" id="comment" cols="120" rows="5">[...] cit. [...]</textarea></td> 138 </tr> 139 140 </tbody> 141 </table> 142 143 <p class="submit"> 144 <input type="hidden" name="action" value="addpingback" /> 145 <input type="submit" class="button-primary" value="Add Link Reference" /> 146 </p> 147 148 </form> 149 </div> 150 <?php } 147 <?php 148 $authors = [ 149 ['name' => 'author_name', 'label' => __('Site Title / Page Name', 'addPingbacks'), 'default' => ''], 150 ['name' => 'author_url', 'label' => __('Link', 'addPingbacks'), 'default' => 'http://'] 151 ]; 151 152 152 add_filter( 'plugin_row_meta', 'addPingbacks_set_plugin_meta', 10, 2 ); 153 add_action( 'admin_init', 'addPingbacks_options_init' ); 154 add_action( 'admin_menu', 'addPingbacks_options_link' ); 153 foreach ($authors as $author) { 154 add_pingback_text_box($author['label'], $author['name'], $author['default']); 155 } 156 ?> 157 158 <tr> 159 <th colspan="2" style="font-size:1.3em"><?php esc_html_e('Excerpt / Content', 'addPingbacks'); ?></th> 160 </tr> 161 <tr> 162 <td colspan="3"><textarea name="comment" id="comment" cols="120" rows="5">[...] cit. [...]</textarea></td> 163 </tr> 164 </tbody> 165 </table> 166 167 <p class="submit"> 168 <input type="hidden" name="action" value="addpingback" /> 169 <input type="submit" class="button-primary" value="<?php esc_attr_e('Add Link Reference', 'addPingbacks'); ?>" /> 170 </p> 171 </form> 172 </div> 173 <?php 174 } 175 176 add_action('wp_ajax_fetch_posts', function() { 177 $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; 178 $posts = get_posts([ 179 'post_type' => $post_type, 180 'numberposts' => -1, 181 'post_status' => 'publish', 182 ]); 183 184 $response = []; 185 foreach ($posts as $post) { 186 $response[] = [ 187 'ID' => $post->ID, 188 'title' => get_the_title($post->ID), 189 ]; 190 } 191 192 wp_send_json($response); 193 }); 194 195 add_filter('plugin_row_meta', 'add_pingbacks_set_plugin_meta', 10, 2); 196 add_action('admin_init', 'add_pingbacks_options_init'); 197 add_action('admin_menu', 'add_pingbacks_options_link'); 198 add_action('admin_enqueue_scripts', 'add_pingbacks_enqueue_scripts'); 155 199 ?> -
add-pingbacks/trunk/readme.txt
r985122 r3233035 1 === Plugin Name===1 === Add Pingbacks === 2 2 Contributors: simonquasar 3 Tags: add pingbacks, pingback, manual pingbacks, comments, manual, add comments 4 Requires at least: 2.8 5 Tested up to: 4.0 6 Stable tag: 1.0 3 Tags: pingbacks, manual pingbacks, comments, linkbacks, custom post types, referrals 4 Requires at least: 5.0 5 Tested up to: 6.6.2 6 Requires PHP: 7.4 7 Stable tag: 1.2 7 8 License: GPLv2 or later 8 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 10 10 Manually add a Pingback to a post or page.11 Manually add pingbacks to any post, page, or custom post type in WordPress with a simple interface. 11 12 12 == Description == 13 Add Pingbacks is a WordPress plugin that allows you to manually create pingbacks for your posts, pages, and custom post types. This is particularly useful when you want to: 13 14 14 Adds an options page in the Comments menu. 15 You select on which Post/Page the referring Link should appear, add the Site name and URL, then paste the referring part. 15 * Add missing pingbacks that weren't automatically detected 16 * Manually create references between content 17 * Manage content relationships through pingbacks 18 * Add pingbacks for legacy content 19 20 = How It Works = 21 22 1. Select your post type from the dropdown menu 23 2. Choose the specific post you want to add the pingback to 24 3. Enter the referrer's site title and URL 25 4. Add the excerpt or content of the pingback 26 5. Click "Add Link Reference" to create the pingback 16 27 17 28 == Installation == 18 29 19 1. Download the zip file and extract the `add-pingbacks` directory. 20 2. Upload this directory inside your `/wp-content/plugins/` directory. 21 3. Browse to the `Add Comments` page on the Options menu. 30 1. Upload the `add-pingbacks` directory to your `/wp-content/plugins/` directory 31 2. Activate the plugin through the 'Plugins' menu in WordPress 32 3. Navigate to Comments > Add Pingbacks to start adding pingbacks 33 34 == Usage == 35 36 1. Go to Comments > Add Pingbacks in your WordPress admin 37 2. Select the post type and specific post you want to add a pingback to 38 3. Enter the referring site's details: 39 * Site Title / Page Name 40 * Link URL 41 4. Add the excerpt or content for the pingback 42 5. Click "Add Link Reference" to create the pingback 43 44 == Changelog == 45 46 = 1.2 = 47 * Added support for all public post types 48 * Dynamic post loading 49 * Dta sanitization 50 51 = 1.1 = 52 * Initial public release 22 53 23 54 == Support == 24 55 25 [[email protected]](mailto:[email protected]) 56 For support inquiries: 57 [github.com/simonquasar/add-pingbacks](https://github.com/simonquasar/add-pingbacks/) 58 59 == Credits == 60 61 Developed by [simonquasar](https://simonquasar.net/)
Note: See TracChangeset
for help on using the changeset viewer.