golden hour
/home/godaofbq/hardchambers.com/wp-content/plugins/wp-scheduled-posts-pro/includes/API
⬆️ Go Up
Upload
File/Folder
Size
Actions
Settings.php
4.58 KB
Del
OK
Edit: Settings.php
<?php namespace WPSP_PRO\API; use WPSP_PRO; use WPSP_PRO\Helper as WPSP_PROHelper; class Settings { /** * Main Setting Option Name * * @since 1.0.0 * * @var string */ private $settings_name = null; /** * Instance of this class. * * @since 1.0.0 * * @var object */ protected static $instance = null; /** * Initialize hooks and option name */ private function __construct() { $this->settings_name = WPSP_PRO_SETTINGS_NAME; $this->do_hooks(); } /** * Set up WordPress hooks and filters * * @return void */ public function do_hooks() { add_action('rest_api_init', array($this, 'meta_rest_api')); add_action('rest_api_init', array($this, 'update_post_content')); } public function update_post_content() { $namespace = WPSP_PRO_SL_ITEM_SLUG . '/v1'; // Get option data register_rest_route($namespace, 'update-post-content', array( 'methods' => 'POST', 'callback' => array($this, 'wpsp_pro_update_content'), 'permission_callback' => function() { return current_user_can( 'edit_posts' ); } )); } /** * Update previous content when disabling advanced schedule */ public function wpsp_pro_update_content( $data ) { $params = $data->get_params(); if( !empty( $params['id'] ) ) { $get_advanced_scheduled_data = !empty( get_post_field('post_content', $params['id']) ) ? get_post_field('post_content', $params['id']) : ''; $get_advanced_scheduled_title = !empty( get_post_field('post_title', $params['id']) ) ? get_post_field('post_title', $params['id']) : ''; $get_advanced_scheduled_image = !empty( get_post_meta($params['id'], '_thumbnail_id', true) ) ? get_post_meta($params['id'], '_thumbnail_id', true) : ''; return rest_ensure_response( [ 'success' => true, 'content' => $get_advanced_scheduled_data, 'title' => $get_advanced_scheduled_title, 'image' => $get_advanced_scheduled_image ] ); } return rest_ensure_response( [ 'success' => false, 'data' => __('Something went wrong!!', 'wp-scheduled-posts') ] ); } public function meta_rest_api() { $allow_post_types = WPSP_PROHelper::get_all_allowed_post_type(); $allow_post_types = (!empty($allow_post_types) ? $allow_post_types : array('post')); foreach ($allow_post_types as $type) { register_post_meta( $type, '_wpscp_schedule_draft_date', [ 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'auth_callback' => function() { return current_user_can( 'edit_posts' ); } ] ); register_post_meta( $type, '_wpscp_schedule_republish_date', [ 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'auth_callback' => function() { return current_user_can( 'edit_posts' ); } ] ); register_post_meta( $type, '_wpscppro_advance_schedule', [ 'show_in_rest' => true, 'single' => true, 'type' => 'boolean', 'auth_callback' => function() { return current_user_can( 'edit_posts' ); } ] ); register_post_meta( $type, '_wpscppro_advance_schedule_date', [ 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'auth_callback' => function() { return current_user_can( 'edit_posts' ); } ] ); } } /** * Return an instance of this class. * * @since 0.8.1 * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if (null == self::$instance) { self::$instance = new self; } return self::$instance; } }
Save