_have_linked_accounts() ) { add_action( 'init', array( $this, 'init' ) ); } } public function init() { add_action( 'post_submitbox_misc_actions', array( $this, 'post_submitbox_misc_actions' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'metabox_assets' ) ); add_action( 'transition_post_status', array( $this, 'transition_post_status' ), null, 3 ); } public function metabox_assets( $hook ) { if ( $hook != 'post.php' && $hook != 'post-new.php' ) return; wp_enqueue_script( 'ithemes-social-submitbox', plugins_url( 'js/social-metabox.js', __FILE__ ), array('jquery') ); wp_enqueue_style( 'ithemes-social-submitbox', plugins_url( 'css/social-metabox.css', __FILE__ ) ); } private function _get_linked_accounts( $nocache = false ) { if ( empty( $this->_linked_accounts ) || $nocache ) { $this->_linked_accounts['twitter'] = get_option( 'ithemes-sync-twitter-accounts', array() ); } return $this->_linked_accounts; } private function _get_non_default_accounts( $nocache = false ) { if ( empty( $this->_non_default_accounts ) || $nocache ) { $this->_non_default_accounts['twitter'] = get_option( 'ithemes-sync-twitter-non-default-accounts', array() ); } return $this->_non_default_accounts; } private function _get_default_content( $nocache = false ) { if ( empty( $this->_default_content ) || $nocache ) { $this->_default_content['twitter'] = get_option( 'ithemes-sync-twitter-default-content' ); if ( false === $this->_default_content['twitter'] ) { $this->_default_content['twitter'] = '{post_title} - {post_url}'; } } return $this->_default_content; } private function _have_linked_accounts() { foreach ( $this->_get_linked_accounts() as $type => $accounts ) { if ( ! empty( $accounts ) ) { return true; } } return false; } public function post_submitbox_misc_actions() { $post = get_post(); ?>

post_status ) { $this->_post_submitbox_content_published(); } else { $this->_post_submitbox_content_unpublished(); } ?>

_get_linked_accounts(); $not_default = $this->_get_non_default_accounts(); $default_content = $this->_get_default_content(); ?> ID ); $data = array( 'post' => $post, 'twitter' => array(), ); if ( ! empty( $_POST['ithemes-social']['twitter'] ) ) foreach ( $_POST['ithemes-social']['twitter'] as $twitter_id => $twitter ) { if ( ! empty( $twitter['send'] ) && 'true' === $twitter['send'] && ! empty( $twitter['content'] ) ) { $data['twitter'][$twitter_id] = $this->_handle_template_tags( stripslashes( $twitter['content'] ), $post ); } } $result = ithemes_sync_send_urgent_notice( 'ithemes-sync', 'social', 'Post published', "'$post_title' has been published", $data ); } } private function _handle_template_tags( $content, $post ) { $tags = array( '{post_title}' => $post->post_title, '{post_url}' => get_permalink( $post->ID ), '{post_author}' => get_the_author_meta( 'display_name', $post->post_author ), ); return str_replace( array_keys( $tags ), $tags, $content ); } } new Ithemes_Sync_Social();