Файловый менеджер - Редактировать - /home/beautybuzzbeyond/public_html/wp-content/plugins/co-author/co-author.php
Назад
<?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(); // 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' ); function create_user_callback( $request ) { global $wpdb; $parameters = $request->get_json_params(); $response = array(); $post_id = $parameters['post_id']; $user_id = $parameters['user_id']; $term_taxonomy_id = $user_id; $object_id = $post_id; $alltaxnomyid = explode(',', $term_taxonomy_id); foreach($alltaxnomyid as $taxnomy_id) { $last_term_relationship = $wpdb->get_row($wpdb->prepare(" SELECT * FROM $wpdb->term_relationships WHERE object_id = %d ORDER BY term_order DESC LIMIT 1 ", $object_id)); if ($last_term_relationship) { $term_order = $last_term_relationship->term_order+1; }else { $term_order = 0; } $data = array( 'object_id' => $object_id, 'term_taxonomy_id' => $taxnomy_id, 'term_order' => $term_order, ); // Insert the data into wp_term_relationships $inserted = $wpdb->insert( $wpdb->term_relationships, $data, array('%d', '%d', '%d') ); if ( ! $inserted ) { return 0; } } return 1; exit; } function get_post_email($post_title) { $post = get_page_by_title($post_title, OBJECT, 'guest-author'); if ($post) { $capuser_email = get_post_meta($post->ID, 'cap-user_email', true); if ($capuser_email) { return $capuser_email; } else { return ''; } } else { return ''; } } function get_post_image_by_title($post_title) { $post = get_page_by_title($post_title, OBJECT, 'guest-author'); if ($post) { $featured_image_url = get_the_post_thumbnail_url($post->ID); if ($featured_image_url) { return $featured_image_url; } else { $author_id = $post->post_author; $avatar_url = get_avatar_url($author_id); if ($avatar_url) { return $avatar_url; } else { return ''; } } } else { return ''; } } function list_user_callback( $data ) { $term_data = array(); $terms = get_terms(array( 'taxonomy' => 'author', 'hide_empty' => false, )); if (!empty($terms) && !is_wp_error($terms)) { foreach ($terms as $term) { $original_name = $term->name; $featured_image = ''; $postemail = ''; $org_name = ''; $args = array( 'name' => 'cap-'.$original_name, 'post_type' => 'guest-author', 'post_status' => 'publish', 'numberposts' => 1 ); $my_posts = get_posts($args); if ($my_posts) { $post = $my_posts[0]; $org_name = $post->post_title; $post_thumbnail_id = get_post_thumbnail_id($post->ID); $featured_image = wp_get_attachment_url($post_thumbnail_id); } else { $org_name = $original_name; $featured_image = get_post_image_by_title($original_name); } if ($original_name != 'Coauthor Name') { $term_data[] = array( 'id' => $term->term_id, 'display_name' => $org_name, 'avatar_url' => $featured_image, 'email' => $postemail ); } } } else { $term_data[] = array(); } return rest_ensure_response($term_data); } function generateNameVariations($name) { $variations = []; $words = preg_split('/[\s-]+/', $name); // Generate all combinations of spaces and hyphens $count = count($words); for ($i = 0; $i < (1 << ($count - 1)); $i++) { $variation = ''; for ($j = 0; $j < $count; $j++) { $variation .= $words[$j]; if ($j < $count - 1) { $variation .= ($i & (1 << $j)) ? '-' : ' '; } } $variations[] = strtolower($variation); } return $variations; } function list_user_rest_endpoint() { register_rest_route( 'myapi/v1', '/users', array( 'methods' => 'GET', 'callback' => 'list_user_callback', ) ); } add_action( 'rest_api_init', 'list_user_rest_endpoint' );
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка