Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding CPT names #14

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions inc/class.mspecs-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public static function enqueue_scripts($hook){
if(
$hook === 'settings_page_mspecs'
|| ($hook === 'post.php' && in_array(get_post_type(), array(
'mspecs_deal',
'mspecs_organization',
'mspecs_office',
'mspecs_user',
MSPECS_DEAL_CPT,
MSPECS_ORG_CPT,
MSPECS_OFFICE_CPT,
MSPECS_USER_CPT,
)))
){
// TODO: Minimize resources
Expand All @@ -53,7 +53,7 @@ public static function init_settings(){
'api_password' => '',
'api_access_token' => '',
'api_subscriber' => '',
'api_domain' => 'integration.mspecs.se',
'api_domain' => 'integration.mspecs.se',
)
));

Expand All @@ -80,7 +80,7 @@ public static function settings_page(){
public static function api_settings_section_callback(){
echo '<p>
<h3>Instructions:</h3>
<a href="https://support.mspecs.se/sv-SE/support/solutions/articles/13000098836-wordpress-plugin-ny-" target="_blank">READ ME</a>
<a href="https://support.mspecs.se/sv-SE/support/solutions/articles/13000098836-wordpress-plugin-ny-" target="_blank">READ ME</a>
<ul>
<li>Basic auth is deprectade, use accessToken instead</li>
</ul>
Expand All @@ -89,7 +89,7 @@ public static function api_settings_section_callback(){

private static function getAuthToggleSetting() {
$settings = get_option('mspecs_settings');
return isset($settings['api_auth_toggle']) ? $settings['api_auth_toggle'] || 0 : 0;
return isset($settings['api_auth_toggle']) ? $settings['api_auth_toggle'] || 0 : 0;
}

private static function getHideClassIfEq($val){
Expand Down Expand Up @@ -141,7 +141,7 @@ private static function display_settings_field($key, $class = '', $type = 'text'

if($static == false): ?>
<input class="regular-text <?= $class ?>" type="<?= esc_attr($type) ?>" name="<?= esc_attr($full_key) ?>" value="<?= esc_attr( $value ) ?>">
<?php else: ?>
<?php else: ?>
<input class="regular-text <?= $class ?>" type="<?= esc_attr($type) ?>" value="<?= esc_attr( $value ) ?>" disabled>
<?php endif;
}
Expand Down Expand Up @@ -217,10 +217,10 @@ public static function mspecs_admin_action_request(){
*/
public static function add_meta_boxes(){
add_meta_box( 'mspecs-post-meta', __('Mspecs data', 'mspecs'), array('Mspecs_Admin', 'display_post_meta_box'), array(
'mspecs_deal',
'mspecs_organization',
'mspecs_office',
'mspecs_user',
MSPECS_DEAL_CPT,
MSPECS_ORG_CPT,
MSPECS_OFFICE_CPT,
MSPECS_USER_CPT,
) );
}
public static function display_post_meta_box(){
Expand Down
26 changes: 13 additions & 13 deletions inc/class.mspecs-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Mspecs_Store {
public static function init(){

}

/**
Expand All @@ -14,7 +14,7 @@ public static function init(){
public static function get_organization(){
$args = array(
'orderby' => 'date',
'post_type' => 'mspecs_organization',
'post_type' => MSPECS_ORG_CPT,
);

$organizations = self::get_posts(apply_filters('mspecs_get_organization_args', $args));
Expand Down Expand Up @@ -51,21 +51,21 @@ public static function get_user($mspecs_id){
return false;
}
}

/**
* get_users
*
* @see get_posts
*
* @param array $args
*
*
* @return WP_Post[]|int[] Array of post objects or post IDs.
*/
public static function get_users($args = array()){
$args = wp_parse_args($args, array(
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'mspecs_user',
'post_type' => MSPECS_USER_CPT,
));

$users = self::get_posts(apply_filters('mspecs_get_users_args', $args));
Expand Down Expand Up @@ -100,21 +100,21 @@ public static function get_office($mspecs_id){
return false;
}
}

/**
* get_offices
*
* @see get_posts
*
* @param array $args
*
*
* @return WP_Post[]|int[] Array of post objects or post IDs.
*/
public static function get_offices($args = array()){
$args = wp_parse_args($args, array(
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'mspecs_office',
'post_type' => MSPECS_OFFICE_CPT,
));

$offices = self::get_posts(apply_filters('mspecs_get_offices_args', $args));
Expand All @@ -126,7 +126,7 @@ public static function get_offices($args = array()){
* get_deal
*
* @see mspecs_get_deal
*
*
*/
public static function get_deal($mspecs_id){
if(empty($mspecs_id)){
Expand All @@ -149,18 +149,18 @@ public static function get_deal($mspecs_id){
return false;
}
}

/**
* get_deals
*
* @see gmspecs_get_deals
*
*
*/
public static function get_deals($args = array()){
$args = wp_parse_args($args, array(
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'mspecs_deal',
'post_type' => MSPECS_DEAL_CPT,
));

$deals = self::get_posts(apply_filters('mspecs_get_deals_args', $args));
Expand Down Expand Up @@ -188,7 +188,7 @@ public static function insert_post($args){
public static function get_unique_meta_values($meta_key){
global $wpdb;

$sql = $wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = %s and pm.post_id=p.ID and p.post_type='mspecs_deal'", $meta_key);
$sql = $wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = %s and pm.post_id=p.ID and p.post_type='" . MSPECS_DEAL_CPT . "'", $meta_key);
$values = $wpdb->get_results($sql, ARRAY_A);

$values = array_map(function($value){
Expand Down
20 changes: 10 additions & 10 deletions inc/class.mspecs-syncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Mspecs_Syncer extends Mspecs_WP_Background_Process{
protected $action = 'mspecs_sync';

public $max_retries = 5;
public $cron_interval = 5; // Minutes

Expand Down Expand Up @@ -113,7 +113,7 @@ public function download_organization($mspecs_organization){

// Set WP default fields
$args = array(
'post_type' => 'mspecs_organization',
'post_type' => MSPECS_ORG_CPT,
'post_title' => $get('name', ''),
'post_status' => 'publish',

Expand Down Expand Up @@ -168,13 +168,13 @@ public function download_office($mspecs_office){

// Set WP default fields
$args = array(
'post_type' => 'mspecs_office',
'post_type' => MSPECS_OFFICE_CPT,
'post_title' => $get('name', ''),
'post_status' => 'publish',

// 'post_date' // TODO
);

$old_deal = mspecs_get_office($mspecs_id);
if($old_deal){
$args['ID'] = $old_deal->ID;
Expand Down Expand Up @@ -223,13 +223,13 @@ public function download_user($mspecs_user){

// Set WP default fields
$args = array(
'post_type' => 'mspecs_user',
'post_type' => MSPECS_USER_CPT,
'post_title' => $get('firstName', '') . ' ' . $get('lastName', ''),
'post_status' => 'publish',

// 'post_date' // TODO
);

$old_deal = mspecs_get_user($mspecs_id);
if($old_deal){
$args['ID'] = $old_deal->ID;
Expand Down Expand Up @@ -285,15 +285,15 @@ public function download_deal($mspecs_id){

// Set WP default fields
$args = array(
'post_type' => 'mspecs_deal',
'post_type' => MSPECS_DEAL_CPT,
'post_title' => $get('shortId', ''),
'post_content' => $get('sellingTexts.sellingText', ''),
'post_excerpt' => $get('sellingTexts.sellingTextShort', ''),
'post_status' => 'publish', // TODO

// 'post_date' // TODO
);

$old_deal = mspecs_get_deal($mspecs_id);
if($old_deal){
$args['ID'] = $old_deal->ID;
Expand Down Expand Up @@ -473,7 +473,7 @@ protected function download_file_from_remote($file_path, $remote_url){
$dir = dirname($file_path);

// Save file, based on wp_upload_bits

wp_mkdir_p($dir);

$ifp = @fopen( $file_path, 'wb' );
Expand Down Expand Up @@ -649,7 +649,7 @@ public function set_webhook_secret(){
$api_client = Mspecs::get_api_client();
$response = $api_client->generate_webhook_secret();
$secret = isset($response['secret']) ? $response['secret'] : false;

if($secret){
mspecs_update_setting('api_secret', $secret);
}
Expand Down
20 changes: 10 additions & 10 deletions inc/class.mspecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function init() {
}

public static function register_post_types(){
register_post_type('mspecs_deal', apply_filters('mspecs_deal_post_type', array(
register_post_type(MSPECS_DEAL_CPT, apply_filters('mspecs_deal_post_type', array(
'labels' => array(
'name' => __('Deals - Mspecs', 'mspecs'),
'singular_name' => __('Deal', 'mspecs'),
Expand Down Expand Up @@ -50,10 +50,10 @@ public static function register_post_types(){
'show_ui' => true,
'menu_icon' => 'dashicons-admin-home',
'capability_type' => 'post', // TODO: Change?
'supports' => array('title', 'editor'),
'supports' => array('title', 'editor'),
)));

register_post_type('mspecs_office', apply_filters('mspecs_office_post_type', array(
register_post_type(MSPECS_OFFICE_CPT, apply_filters('mspecs_office_post_type', array(
'labels' => array(
'name' => __('Offices - Mspecs', 'mspecs'),
'singular_name' => __('Office', 'mspecs'),
Expand Down Expand Up @@ -83,11 +83,11 @@ public static function register_post_types(){
'hierarchical' => false,
'show_ui' => true, // TODO: Switch off
'menu_icon' => 'dashicons-location',
'capability_type' => 'post', // TODO: Change?
'supports' => array('title'),
'capability_type' => 'post', // TODO: Change?
'supports' => array('title'),
)));

register_post_type('mspecs_user', apply_filters('mspecs_user_post_type', array(
register_post_type(MSPECS_USER_CPT, apply_filters('mspecs_user_post_type', array(
'labels' => array(
'name' => __('Users - Mspecs', 'mspecs'),
'singular_name' => __('User', 'mspecs'),
Expand Down Expand Up @@ -117,11 +117,11 @@ public static function register_post_types(){
'hierarchical' => false,
'show_ui' => true, // TODO: Switch off
'menu_icon' => 'dashicons-id-alt',
'capability_type' => 'post', // TODO: Change?
'supports' => array('title'),
'capability_type' => 'post', // TODO: Change?
'supports' => array('title'),
)));

register_post_type('mspecs_organization', apply_filters('mspecs_organization_post_type', array(
register_post_type(MSPECS_ORG_CPT, apply_filters('mspecs_organization_post_type', array(
'labels' => array(
'name' => __('Organizations - Mspecs', 'mspecs'),
'singular_name' => __('Organization', 'mspecs'),
Expand Down Expand Up @@ -152,7 +152,7 @@ public static function register_post_types(){
'show_ui' => true, // TODO: Switch off
'menu_icon' => 'dashicons-store',
'capability_type' => 'post', // TODO: Change?
'supports' => array('title'),
'supports' => array('title'),
)));
}

Expand Down
15 changes: 14 additions & 1 deletion mspecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
/*
Plugin Name: Mspecs Mäklarsystem - API
Plugin URI: https://www.mspecs.se/
Description:
Description:
Author: Mspecs
Version: 1.0.0
*/

if (!defined('MSPECS_DEAL_CPT')) {
define('MSPECS_DEAL_CPT', 'mspecs_deal');
}
if (!defined('MSPECS_ORG_CPT')) {
define('MSPECS_ORG_CPT', 'mspecs_organization');
}
if (!defined('MSPECS_USER_CPT')) {
define('MSPECS_USER_CPT', 'mspecs_user');
}
if (!defined('MSPECS_OFFICE_CPT')) {
define('MSPECS_OFFICE_CPT', 'mspecs_office');
}

define( 'MSPECS_PLUGIN_FILE', __FILE__ );
define( 'MSPECS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
//For local development add_filter('https_ssl_verify', '__return_false');
Expand Down
Loading