Файловый менеджер - Редактировать - /home/beautybuzzbeyond/public_html/wp-content/plugins/co-author/co-author.php.bak
Назад
<?php /** * The plugin bootstrap file * * This file is read by WordPress to generate the plugin information in the plugin * admin area. This file also includes all of the dependencies used by the plugin, * registers the activation and deactivation functions, and defines a function * that starts the plugin. * * @link https://contentfuze.ai * @since 1.0.0 * @package Co_Author * * @wordpress-plugin * Plugin Name: Co-Author * Plugin URI: https://contentfuze.ai * Description: This is for add co author in wordpress posts * Version: 1.0.0 * Author: CWS * Author URI: https://contentfuze.ai/ * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Text Domain: co-author * Domain Path: /languages */ // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } /** * Currently plugin version. * Start at version 1.0.0 and use SemVer - https://semver.org * Rename this for your plugin and update it as you release new versions. */ define( 'CO_AUTHOR_VERSION', '1.0.0' ); /** * The code that runs during plugin activation. * This action is documented in includes/class-co-author-activator.php */ function activate_co_author() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-co-author-activator.php'; Co_Author_Activator::activate(); } /** * The code that runs during plugin deactivation. * This action is documented in includes/class-co-author-deactivator.php */ function deactivate_co_author() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-co-author-deactivator.php'; Co_Author_Deactivator::deactivate(); } register_activation_hook( __FILE__, 'activate_co_author' ); register_deactivation_hook( __FILE__, 'deactivate_co_author' ); /** * The core plugin class that is used to define internationalization, * admin-specific hooks, and public-facing site hooks. */ require plugin_dir_path( __FILE__ ) . 'includes/class-co-author.php'; /** * Begins execution of the plugin. * * Since everything within the plugin is registered via hooks, * then kicking off the plugin from this point in the file does * not affect the page life cycle. * * @since 1.0.0 */ function run_co_author() { $plugin = new Co_Author(); $plugin->run(); } run_co_author(); function custom_author_meta_box() { add_meta_box( 'custom_author_meta_box', 'Authors', 'custom_author_meta_box_callback', 'post', 'normal', 'high' ); } add_action('add_meta_boxes', 'custom_author_meta_box'); function enqueue_select2() { wp_enqueue_script('select2', plugins_url('admin/js/select2.min.js', __FILE__), array('jquery'), '4.0.13', true); wp_enqueue_style('select2', plugins_url('admin/css/select2.min.css', __FILE__), array(), '4.0.13'); } add_action('admin_enqueue_scripts', 'enqueue_select2'); // Meta box callback function function custom_author_meta_box_callback($post) { // Retrieve saved authors or initialize an empty array $authors = get_post_meta($post->ID, '_custom_authors', true) ?: array(); ?> <label for="custom_author_search">Search Authors:</label> <select id="custom_author_select" name="custom_author_ids[]" multiple="multiple"></select> <style> span.remove-author { margin-left: 10px; /* font-size: 15px; */ } </style> <script> jQuery(document).ready(function($) { // Initialize select2 on the dropdown $('#custom_author_select').select2({ placeholder: 'Search for authors...', minimumInputLength: 2, // Minimum number of characters before search ajax: { url: ajaxurl, dataType: 'json', delay: 250, // Delay in milliseconds before making the request data: function(params) { return { action: 'custom_author_search', term: params.term // Search term entered by the user }; }, processResults: function(data) { return { results: data }; }, cache: true // Cache AJAX requests to prevent duplicate requests }, multiple: true // Allow multiple selections }); // Populate select2 with existing values var existingAuthors = <?php echo json_encode(get_post_meta($post->ID, '_custom_author_ids', true)); ?>; if (existingAuthors) { existingAuthors.forEach(function(authorId) { // AJAX request to fetch user display name $.ajax({ url: ajaxurl, type: 'GET', dataType: 'json', data: { action: 'get_author_display_name', author_id: authorId }, success: function(data) { if (data && data.display_name) { var $option = $('<option selected></option>').val(authorId).text(data.display_name); $('#custom_author_select').append($option).trigger('change'); } } }); }); } }); </script> <?php } // AJAX callback for author search function custom_author_search_callback() { $term = isset($_GET['term']) ? sanitize_text_field($_GET['term']) : ''; // Search for users based on the provided term $user_query = new WP_User_Query(array( 'search' => '*' . $term . '*', 'search_columns' => array('user_login', 'user_nicename', 'user_email', 'user_url'), )); $results = array(); foreach ($user_query->get_results() as $user) { $results[] = array( 'id' => $user->ID, 'text' => $user->display_name, ); } wp_send_json($results); } add_action('wp_ajax_custom_author_search', 'custom_author_search_callback'); // Save custom authors when the post is saved function save_custom_authors($post_id) { if (isset($_POST['custom_author_ids'])) { $author_ids = array_map('intval', $_POST['custom_author_ids']); update_post_meta($post_id, '_custom_author_ids', $author_ids); } } add_action('save_post', 'save_custom_authors'); // AJAX callback to get author display name function get_author_display_name() { if (isset($_GET['author_id'])) { $author_id = intval($_GET['author_id']); $user_info = get_userdata($author_id); if ($user_info) { $display_name = $user_info->display_name; wp_send_json(array('display_name' => $display_name)); } } wp_send_json(null); } add_action('wp_ajax_get_author_display_name', 'get_author_display_name'); // In your WordPress PHP code add_action('wp_ajax_your_action_name', 'your_ajax_function'); add_action('wp_ajax_nopriv_your_action_name', 'your_ajax_function'); // If the AJAX request can be made by non-logged-in users function your_ajax_function() { check_ajax_referer('your_action_name_nonce', 'security'); // Verify nonce for security // Process the AJAX request echo $username = $_POST['username']; exit; wp_send_json_success('1'); // Send success response wp_die(); // Always include wp_die() at the end of your AJAX handler } // Register custom REST API endpoint for user creation function create_user_rest_endpoint() { register_rest_route( 'myapi/v1', '/create-user', array( 'methods' => 'POST', 'callback' => 'create_user_callback', ) ); } add_action( 'rest_api_init', 'create_user_rest_endpoint' ); // Callback function to handle user creation /* function create_user_callback( $request ) { $parameters = $request->get_json_params(); // Retrieve user data from request $username = sanitize_text_field( $parameters['username'] ); $password = sanitize_text_field( $parameters['password'] ); $email = sanitize_email( $parameters['email'] ); // Create user $user_id = wp_create_user( $username, $password, $email ); if ( is_wp_error( $user_id ) ) { return new WP_Error( 'user_creation_failed', $user_id->get_error_message(), array( 'status' => 400 ) ); } else { return array( 'user_id' => $user_id ); } } */ function create_user_callback( $request ) { global $wpdb; $parameters = $request->get_json_params(); $response = array(); $post_id = $parameters['post_id']; foreach ($parameters['users'] as $data) { $username = sanitize_text_field( $data['username'] ); $password = sanitize_text_field( $data['password'] ); $email = sanitize_email( $data['email'] ); // Check if username already exists $existing_username_id = username_exists( $username ); if ( $existing_username_id ) { $response[] = $existing_username_id; continue; } // Check if email already exists $existing_email_id = email_exists( $email ); if ( $existing_email_id ) { $response[] = $existing_email_id; continue; } // Create user $user_id = wp_create_user( $username, $password, $email ); if ( is_wp_error( $user_id ) ) { $response[] = $user_id->get_error_message(); } else { $response[] = $user_id; } } $author_ids = array_map('intval', $response); update_post_meta($post_id, '_custom_author_ids', $author_ids); // update_post_meta($post_id, '_custom_authors', implode(',', $response)); return implode(',', $response); // Return response with user IDs and errors separated by commas }
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка