Initial commit

parents
.DS_Store
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Starter_Plugin_Admin Class
*
* @class Starter_Plugin_Admin
* @version 1.0.0
* @since 1.0.0
* @package Starter_Plugin
* @author Jeffikus
*/
final class Starter_Plugin_Admin {
/**
* Starter_Plugin_Admin The single instance of Starter_Plugin_Admin.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The string containing the dynamically generated hook token.
* @var string
* @access private
* @since 1.0.0
*/
private $_hook;
/**
* Constructor function.
* @access public
* @since 1.0.0
*/
public function __construct () {
// Register the settings with WordPress.
add_action( 'admin_init', array( $this, 'register_settings' ) );
// Register the settings screen within WordPress.
add_action( 'admin_menu', array( $this, 'register_settings_screen' ) );
} // End __construct()
/**
* Main Starter_Plugin_Admin Instance
*
* Ensures only one instance of Starter_Plugin_Admin is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @return Main Starter_Plugin_Admin instance
*/
public static function instance () {
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
} // End instance()
/**
* Register the admin screen.
* @access public
* @since 1.0.0
* @return void
*/
public function register_settings_screen () {
$this->_hook = add_submenu_page( 'options-general.php', __( 'Starter Plugin Settings', 'starter-plugin' ), __( 'Starter Plugin', 'starter-plugin' ), 'manage_options', 'starter-plugin', array( $this, 'settings_screen' ) );
} // End register_settings_screen()
/**
* Output the markup for the settings screen.
* @access public
* @since 1.0.0
* @return void
*/
public function settings_screen () {
global $title;
$sections = Starter_Plugin()->settings->get_settings_sections();
$tab = $this->_get_current_tab( $sections );
?>
<div class="wrap starter-plugin-wrap">
<?php
echo $this->get_admin_header_html( $sections, $title );
?>
<form action="options.php" method="post">
<?php
settings_fields( 'starter-plugin-settings-' . $tab );
do_settings_sections( 'starter-plugin-' . $tab );
submit_button( __( 'Save Changes', 'starter-plugin' ) );
?>
</form>
</div><!--/.wrap-->
<?php
} // End settings_screen()
/**
* Register the settings within the Settings API.
* @access public
* @since 1.0.0
* @return void
*/
public function register_settings () {
$sections = Starter_Plugin()->settings->get_settings_sections();
if ( 0 < count( $sections ) ) {
foreach ( $sections as $k => $v ) {
register_setting( 'starter-plugin-settings-' . sanitize_title_with_dashes( $k ), 'starter-plugin-' . $k, array( $this, 'validate_settings' ) );
add_settings_section( sanitize_title_with_dashes( $k ), $v, array( $this, 'render_settings' ), 'starter-plugin-' . $k, $k, $k );
}
}
} // End register_settings()
/**
* Render the settings.
* @access public
* @param array $args arguments.
* @since 1.0.0
* @return void
*/
public function render_settings ( $args ) {
$token = $args['id'];
$fields = Starter_Plugin()->settings->get_settings_fields( $token );
if ( 0 < count( $fields ) ) {
foreach ( $fields as $k => $v ) {
$args = $v;
$args['id'] = $k;
add_settings_field( $k, $v['name'], array( Starter_Plugin()->settings, 'render_field' ), 'starter-plugin-' . $token , $v['section'], $args );
}
}
} // End render_settings()
/**
* Validate the settings.
* @access public
* @since 1.0.0
* @param array $input Inputted data.
* @return array Validated data.
*/
public function validate_settings ( $input ) {
$sections = Starter_Plugin()->settings->get_settings_sections();
$tab = $this->_get_current_tab( $sections );
return Starter_Plugin()->settings->validate_settings( $input, $tab );
} // End validate_settings()
/**
* Return marked up HTML for the header tag on the settings screen.
* @access public
* @since 1.0.0
* @param array $sections Sections to scan through.
* @param string $title Title to use, if only one section is present.
* @return string The current tab key.
*/
public function get_admin_header_html ( $sections, $title ) {
$defaults = array(
'tag' => 'h2',
'atts' => array( 'class' => 'starter-plugin-wrapper' ),
'content' => $title
);
$args = $this->_get_admin_header_data( $sections, $title );
$args = wp_parse_args( $args, $defaults );
$atts = '';
if ( 0 < count ( $args['atts'] ) ) {
foreach ( $args['atts'] as $k => $v ) {
$atts .= ' ' . esc_attr( $k ) . '="' . esc_attr( $v ) . '"';
}
}
$response = '<' . esc_attr( $args['tag'] ) . $atts . '>' . $args['content'] . '</' . esc_attr( $args['tag'] ) . '>' . "\n";
return $response;
} // End get_admin_header_html()
/**
* Return the current tab key.
* @access private
* @since 1.0.0
* @param array $sections Sections to scan through for a section key.
* @return string The current tab key.
*/
private function _get_current_tab ( $sections = array() ) {
if ( isset ( $_GET['tab'] ) ) {
$response = sanitize_title_with_dashes( $_GET['tab'] );
} else {
if ( is_array( $sections ) && ! empty( $sections ) ) {
list( $first_section ) = array_keys( $sections );
$response = $first_section;
} else {
$response = '';
}
}
return $response;
} // End _get_current_tab()
/**
* Return an array of data, used to construct the header tag.
* @access private
* @since 1.0.0
* @param array $sections Sections to scan through.
* @param string $title Title to use, if only one section is present.
* @return array An array of data with which to mark up the header HTML.
*/
private function _get_admin_header_data ( $sections, $title ) {
$response = array( 'tag' => 'h2', 'atts' => array( 'class' => 'starter-plugin-wrapper' ), 'content' => $title );
if ( is_array( $sections ) && 1 < count( $sections ) ) {
$response['content'] = '';
$response['atts']['class'] = 'nav-tab-wrapper';
$tab = $this->_get_current_tab( $sections );
foreach ( $sections as $key => $value ) {
$class = 'nav-tab';
if ( $tab == $key ) {
$class .= ' nav-tab-active';
}
$response['content'] .= '<a href="' . admin_url( 'options-general.php?page=starter-plugin&tab=' . sanitize_title_with_dashes( $key ) ) . '" class="' . esc_attr( $class ) . '">' . esc_html( $value ) . '</a>';
}
}
return (array)apply_filters( 'starter-plugin-get-admin-header-data', $response );
} // End _get_admin_header_data()
} // End Class
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Starter_Plugin_Settings Class
*
* @class Starter_Plugin_Settings
* @version 1.0.0
* @since 1.0.0
* @package Starter_Plugin
* @author Jeffikus
*/
final class Starter_Plugin_Settings {
/**
* Starter_Plugin_Admin The single instance of Starter_Plugin_Admin.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* Whether or not a 'select' field is present.
* @var boolean
* @access private
* @since 1.0.0
*/
private $_has_select;
/**
* Main Starter_Plugin_Settings Instance
*
* Ensures only one instance of Starter_Plugin_Settings is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @return Main Starter_Plugin_Settings instance
*/
public static function instance () {
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
} // End instance()
/**
* Constructor function.
* @access public
* @since 1.0.0
*/
public function __construct () {
} // End __construct()
/**
* Validate the settings.
* @access public
* @since 1.0.0
* @param array $input Inputted data.
* @param string $section field section.
* @return array Validated data.
*/
public function validate_settings ( $input, $section ) {
if ( is_array( $input ) && 0 < count( $input ) ) {
$fields = $this->get_settings_fields( $section );
foreach ( $input as $k => $v ) {
if ( ! isset( $fields[$k] ) ) {
continue;
}
// Determine if a method is available for validating this field.
$method = 'validate_field_' . $fields[$k]['type'];
if ( ! method_exists( $this, $method ) ) {
if ( true === (bool)apply_filters( 'starter-plugin-validate-field-' . $fields[$k]['type'] . '_use_default', true ) ) {
$method = 'validate_field_text';
} else {
$method = '';
}
}
// If we have an internal method for validation, filter and apply it.
if ( '' != $method ) {
add_filter( 'starter-plugin-validate-field-' . $fields[$k]['type'], array( $this, $method ) );
}
$method_output = apply_filters( 'starter-plugin-validate-field-' . $fields[$k]['type'], $v, $fields[$k] );
if ( ! is_wp_error( $method_output ) ) {
$input[$k] = $method_output;
}
}
}
return $input;
} // End validate_settings()
/**
* Validate the given data, assuming it is from a text input field.
* @access public
* @since 6.0.0
* @return void
*/
public function validate_field_text ( $v ) {
return (string)wp_kses_post( $v );
} // End validate_field_text()
/**
* Validate the given data, assuming it is from a textarea field.
* @access public
* @since 6.0.0
* @return void
*/
public function validate_field_textarea ( $v ) {
// Allow iframe, object and embed tags in textarea fields.
$allowed = wp_kses_allowed_html( 'post' );
$allowed['iframe'] = array(
'src' => true,
'width' => true,
'height' => true,
'id' => true,
'class' => true,
'name' => true
);
$allowed['object'] = array(
'src' => true,
'width' => true,
'height' => true,
'id' => true,
'class' => true,
'name' => true
);
$allowed['embed'] = array(
'src' => true,
'width' => true,
'height' => true,
'id' => true,
'class' => true,
'name' => true
);
return wp_kses( $v, $allowed );
} // End validate_field_textarea()
/**
* Validate the given data, assuming it is from a checkbox input field.
* @access public
* @since 6.0.0
* @param string $v
* @return string
*/
public function validate_field_checkbox ( $v ) {
if ( 'true' != $v ) {
return 'false';
} else {
return 'true';
}
} // End validate_field_checkbox()
/**
* Validate the given data, assuming it is from a URL field.
* @access public
* @since 6.0.0
* @param string $v
* @return string
*/
public function validate_field_url ( $v ) {
return trim( esc_url( $v ) );
} // End validate_field_url()
/**
* Render a field of a given type.
* @access public
* @since 1.0.0
* @param array $args The field parameters.
* @return void
*/
public function render_field ( $args ) {
$html = '';
if ( ! in_array( $args['type'], $this->get_supported_fields() ) ) return ''; // Supported field type sanity check.
// Make sure we have some kind of default, if the key isn't set.
if ( ! isset( $args['default'] ) ) {
$args['default'] = '';
}
$method = 'render_field_' . $args['type'];
if ( ! method_exists( $this, $method ) ) {
$method = 'render_field_text';
}
// Construct the key.
$key = Starter_Plugin()->token . '-' . $args['section'] . '[' . $args['id'] . ']';
$method_output = $this->$method( $key, $args );
if ( ! is_wp_error( $method_output ) ) {
$html .= $method_output;
}
// Output the description, if the current field allows it.
if ( isset( $args['type'] ) && ! in_array( $args['type'], (array)apply_filters( 'starter-plugin-no-description-fields', array( 'checkbox' ) ) ) ) {
if ( isset( $args['description'] ) ) {
$description = '<p class="description">' . wp_kses_post( $args['description'] ) . '</p>' . "\n";
if ( in_array( $args['type'], (array)apply_filters( 'starter-plugin-new-line-description-fields', array( 'textarea', 'select' ) ) ) ) {
$description = wpautop( $description );
}
$html .= $description;
}
}
echo $html;
} // End render_field()
/**
* Retrieve the settings fields details
* @access public
* @since 1.0.0
* @return array Settings fields.
*/
public function get_settings_sections () {
$settings_sections = array();
$settings_sections['standard-fields'] = __( 'Standard Fields', 'starter-plugin' );
// Add your new sections below here.
// Admin tabs will be created for each section.
// Don't forget to add fields for the section in the get_settings_fields() function below
return (array)apply_filters( 'starter-plugin-settings-sections', $settings_sections );
} // End get_settings_sections()
/**
* Retrieve the settings fields details
* @access public
* @param string $section field section.
* @since 1.0.0
* @return array Settings fields.
*/
public function get_settings_fields ( $section ) {
$settings_fields = array();
// Declare the default settings fields.
switch ( $section ) {
case 'standard-fields':
$settings_fields['aliases'] = array(
'name' => __( 'Алиасы', 'starter-plugin' ),
'type' => 'text',
'default' => '',
'section' => 'standard-fields',
'descriptions' => 'Коды экшенов, для которых вызывать создание лида (через запятую)'
);
$settings_fields['bx24_domain'] = array(
'name' => __( 'Домен Битрикс24', 'starter-plugin' ),
'type' => 'text',
'default' => '',
'section' => 'standard-fields'
);
$settings_fields['default_params'] = array(
'name' => __( 'Параметры запроса по-умолчанию (JSON)', 'starter-plugin' ),
'type' => 'textarea',
'default' => '',
'section' => 'standard-fields'
);
$settings_fields['name_field'] = array(
'name' => __( 'Ключ имени', 'starter-plugin' ),
'type' => 'text',
'default' => 'name',
'section' => 'standard-fields',
'description' => 'Ключ параметра запроса для поля "Имя". $_REQUEST["your_value"]'
);
$settings_fields['email_field'] = array(
'name' => __( 'Ключ E-mail', 'starter-plugin' ),
'type' => 'text',
'default' => 'email',
'section' => 'standard-fields',
'description' => 'Ключ параметра запроса для поля "E-mail". $_REQUEST["your_value"]'
);
$settings_fields['phone_field'] = array(
'name' => __( 'Ключ телефона', 'starter-plugin' ),
'type' => 'text',
'default' => 'phone',
'section' => 'standard-fields',
'description' => 'Ключ параметра запроса для поля "Телефон". $_REQUEST["your_value"]'
);
break;
default:
# code...
break;
}
return (array)apply_filters( 'starter-plugin-settings-fields', $settings_fields );
} // End get_settings_fields()
/**
* Render HTML markup for the "text" field type.
* @access protected
* @since 6.0.0
* @param string $key The unique ID of this field.
* @param array $args Arguments used to construct this field.
* @return string HTML markup for the field.
*/
protected function render_field_text ( $key, $args ) {
$html = '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="40" type="text" value="' . esc_attr( $this->get_value( $args['id'], $args['default'], $args['section'] ) ) . '" />' . "\n";
return $html;
} // End render_field_text()
/**
* Render HTML markup for the "radio" field type.
* @access protected
* @since 6.0.0
* @param string $key The unique ID of this field.
* @param array $args Arguments used to construct this field.
* @return string HTML markup for the field.
*/
protected function render_field_radio ( $key, $args ) {
$html = '';
if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
$html = '';
foreach ( $args['options'] as $k => $v ) {
$html .= '<input type="radio" name="' . esc_attr( $key ) . '" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $this->get_value( $args['id'], $args['default'], $args['section'] ) ), $k, false ) . ' /> ' . esc_html( $v ) . '<br />' . "\n";
}
}
return $html;
} // End render_field_radio()
/**
* Render HTML markup for the "textarea" field type.
* @access protected
* @since 6.0.0
* @param string $key The unique ID of this field.
* @param array $args Arguments used to construct this field.
* @return string HTML markup for the field.
*/
protected function render_field_textarea ( $key, $args ) {
// Explore how best to escape this data, as esc_textarea() strips HTML tags, it seems.
$html = '<textarea id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" cols="42" rows="5">' . $this->get_value( $args['id'], $args['default'], $args['section'] ) . '</textarea>' . "\n";
return $html;
} // End render_field_textarea()
/**
* Render HTML markup for the "checkbox" field type.
* @access protected
* @since 6.0.0
* @param string $key The unique ID of this field.
* @param array $args Arguments used to construct this field.
* @return string HTML markup for the field.
*/
protected function render_field_checkbox ( $key, $args ) {
$has_description = false;
$html = '';
if ( isset( $args['description'] ) ) {
$has_description = true;
$html .= '<label for="' . esc_attr( $key ) . '">' . "\n";
}
$html .= '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="checkbox" value="true"' . checked( esc_attr( $this->get_value( $args['id'], $args['default'], $args['section'] ) ), 'true', false ) . ' />' . "\n";
if ( $has_description ) {
$html .= wp_kses_post( $args['description'] ) . '</label>' . "\n";
}
return $html;
} // End render_field_checkbox()
/**
* Render HTML markup for the "select2" field type.
* @access protected
* @since 6.0.0
* @param string $key The unique ID of this field.
* @param array $args Arguments used to construct this field.
* @return string HTML markup for the field.
*/
protected function render_field_select ( $key, $args ) {
$this->_has_select = true;
$html = '';
if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
$html .= '<select id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '">' . "\n";
foreach ( $args['options'] as $k => $v ) {
$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $this->get_value( $args['id'], $args['default'], $args['section'] ) ), $k, false ) . '>' . esc_html( $v ) . '</option>' . "\n";
}
$html .= '</select>' . "\n";
}
return $html;
} // End render_field_select()
/**
* Render HTML markup for the "select_taxonomy" field type.
* @access protected
* @since 6.0.0
* @param string $key The unique ID of this field.
* @param array $args Arguments used to construct this field.
* @return string HTML markup for the field.
*/
protected function render_field_select_taxonomy ( $key, $args ) {
$this->_has_select = true;
$defaults = array(
'show_option_all' => '',
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'selected' => $this->get_value( $args['id'], $args['default'], $args['section'] ),
'hierarchical' => 1,
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'category',
'hide_if_empty' => false,
'walker' => ''
);
if ( ! isset( $args['options'] ) ) {
$args['options'] = array();
}
$args['options'] = wp_parse_args( $args['options'], $defaults );
$args['options']['echo'] = false;
$args['options']['name'] = esc_attr( $key );
$args['options']['id'] = esc_attr( $key );
$html = '';
$html .= wp_dropdown_categories( $args['options'] );
return $html;
} // End render_field_select_taxonomy()
/**
* Return an array of field types expecting an array value returned.
* @access public
* @since 1.0.0
* @return array
*/
public function get_array_field_types () {
return array();
} // End get_array_field_types()
/**
* Return an array of field types where no label/header is to be displayed.
* @access protected
* @since 1.0.0
* @return array
*/
protected function get_no_label_field_types () {
return array( 'info' );
} // End get_no_label_field_types()
/**
* Return a filtered array of supported field types.
* @access public
* @since 1.0.0
* @return array Supported field type keys.
*/
public function get_supported_fields () {
return (array)apply_filters( 'starter-plugin-supported-fields', array( 'text', 'checkbox', 'radio', 'textarea', 'select', 'select_taxonomy' ) );
} // End get_supported_fields()
/**
* Return a value, using a desired retrieval method.
* @access public
* @param string $key option key.
* @param string $default default value.
* @param string $section field section.
* @since 1.0.0
* @return mixed Returned value.
*/
public function get_value ( $key, $default, $section ) {
$values = get_option( 'starter-plugin-' . $section, array() );
if ( is_array( $values ) && isset( $values[$key] ) ) {
$response = $values[$key];
} else {
$response = $default;
}
return $response;
} // End get_value()
/**
* Return all settings keys.
* @access public
* @param string $section field section.
* @since 1.0.0
* @return mixed Returned value.
*/
public function get_settings ( $section = '' ) {
$response = false;
$sections = array_keys( (array)$this->get_settings_sections() );
if ( in_array( $section, $sections ) ) {
$sections = array( $section );
}
if ( 0 < count( $sections ) ) {
foreach ( $sections as $k => $v ) {
$fields = $this->get_settings_fields( $v );
$values = get_option( 'starter-plugin-' . $v, array() );
if ( is_array( $fields ) && 0 < count( $fields ) ) {
foreach ( $fields as $i => $j ) {
// If we have a value stored, use it.
if ( isset( $values[$i] ) ) {
$response[$i] = $values[$i];
} else {
// Otherwise, check for a default value. If we have one, use it. Otherwise, return an empty string.
if ( isset( $fields[$i]['default'] ) ) {
$response[$i] = $fields[$i]['default'];
} else {
$response[$i] = '';
}
}
}
}
}
}
return $response;
} // End get_settings()
} // End Class
<?php
class GoldenCodeWpBx24
{
/**
* GoldenCodeWpBx24 The single instance of GoldenCodeWpBx24.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
public function __construct() {
$leadActions = [
'wp_bx24__lead',
'wp_ajax_wp_bx24__lead',
'wp_ajax_nopriv_wp_bx24__lead',
];
foreach ($leadActions as $action)
add_action($action, array($this, 'createLead'), 1);
}
public function registerAlias($alias) {
$aliasActions = explode(',', $alias);
foreach ($aliasActions as $action) {
add_action($action, array($this, 'alias'), 1);
add_action('wp_ajax_' . $action, array($this, 'alias'), 1);
add_action('wp_ajax_nopriv_' . $action, array($this, 'alias'), 1);
}
}
public function alias() {
do_action('wp_bx24__lead');
}
public function getOptions($validate = false) {
$opts = Starter_Plugin()->settings->get_settings();
if ($validate) {
if (empty($opts['bx24_domain'])) throw new Exception('wp_bx24: "bx24_domain" option is empty');
if (empty($opts['name_field']) ) throw new Exception('wp_bx24: "name_field" option is empty');
if (empty($opts['email_field'])) throw new Exception('wp_bx24: "email_field" option is empty');
if (empty($opts['phone_field'])) throw new Exception('wp_bx24: "phone_field" option is empty');
}
return $opts;
}
public function createLead() {
try {
$opts = $this->getOptions(true);
$opts['default_params'] = json_decode($opts['default_params']);
$opts['default_params'] = json_decode(json_encode($opts['default_params']), true);
} catch (Exception $e) {
// TODO: add logging
// ob_get_clean();
// http_response_code(500);
// echo json_encode(['error' => true, 'message' => $e->getMessage()]);
// wp_die();
return;
}
$url = 'http://'.$opts['bx24_domain'].'/crm/configs/import/lead.php';
$params = $opts['default_params'];
$params['NAME'] = $_REQUEST[$opts['name_field']];
$params['EMAIL_WORK'] = $_REQUEST[$opts['email_field']];
$params['PHONE_MOBILE'] = $_REQUEST[$opts['phone_field']];
$result = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)));
// TODO: add logging
// ob_clean();
// echo $result;
// wp_die();
}
/**
* Main GoldenCodeWpBx24 Instance
*
* Ensures only one instance of GoldenCodeWpBx24 is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @return GoldenCodeWpBx24 GoldenCodeWpBx24 instance
*/
public static function instance () {
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
} // End instance()
}
<?php // Silence is golden... ?>
\ No newline at end of file
<?php // Silence is golden... ?>
\ No newline at end of file
=== Starter Plugin ===
Contributors:
Donate link:
Tags:
Requires at least: 4.0.0
Tested up to: 4.0.0
Stable tag: 1.0.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Hey there! I'm your new starter plugin.
== Description ==
Hey there! I'm your new starter plugin.
Looking for a helping hand? [View plugin documentation](http://domain.com/).
== Usage ==
Place some text here, explaining how to use this plugin. Keep it clear and easy to read (short sentences).
== Installation ==
Installing "Starter Plugin" can be done either by searching for "Starter Plugin" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps:
1. Download the plugin via WordPress.org.
1. Upload the ZIP file through the "Plugins > Add New > Upload" screen in your WordPress dashboard.
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Visit the settings screen and configure, as desired.
== Frequently Asked Questions ==
= How do I contribute? =
We encourage everyone to contribute their ideas, thoughts and code snippets. This can be done by forking the [repository over at GitHub](http://github.com/mattyza/starter-plugin/).
== Screenshots ==
1. The settings screen.
== Upgrade Notice ==
= 1.0.0 =
* XXXX-XX-XX
* Initial release. Woo!
== Changelog ==
= 1.0.0 =
* XXXX-XX-XX
* Initial release. Woo!
\ No newline at end of file
<?php
/**
* Plugin Name: Bitrix24 Integration
* Plugin URI: http://git.zolotoykod.ru/zk/wp-bx24
* Description: WordPress plugin for Bitrix24 integration
* Version: 1.0.0
* Author: GoldenCode
* Author URI: http://zolotoykod.ru
* Requires at least: 4.0.0
* Tested up to: 4.0.0
*
* Text Domain: starter-plugin
* Domain Path: /languages/
*
* @package Starter_Plugin
* @category Core
* @author Matty
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Returns the main instance of Starter_Plugin to prevent the need to use globals.
*
* @since 1.0.0
* @return object Starter_Plugin
*/
function Starter_Plugin() {
return Starter_Plugin::instance();
} // End Starter_Plugin()
add_action( 'plugins_loaded', 'Starter_Plugin' );
/**
* Main Starter_Plugin Class
*
* @class Starter_Plugin
* @version 1.0.0
* @since 1.0.0
* @package Starter_Plugin
* @author Matty
*/
final class Starter_Plugin {
/**
* Starter_Plugin The single instance of Starter_Plugin.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The token.
* @var string
* @access public
* @since 1.0.0
*/
public $token;
/**
* The version number.
* @var string
* @access public
* @since 1.0.0
*/
public $version;
/**
* The plugin directory URL.
* @var string
* @access public
* @since 1.0.0
*/
public $plugin_url;
/**
* The plugin directory path.
* @var string
* @access public
* @since 1.0.0
*/
public $plugin_path;
// Admin - Start
/**
* The admin object.
* @var object
* @access public
* @since 1.0.0
*/
public $admin;
/**
* The settings object.
* @var object
* @access public
* @since 1.0.0
*/
public $settings;
// Admin - End
// Post Types - Start
/**
* The post types we're registering.
* @var array
* @access public
* @since 1.0.0
*/
public $post_types = array();
// Post Types - End
/**
* The GoldenCodeWpBx24 object.
* @var GoldenCodeWpBx24
* @access public
* @since 1.0.0
*/
public $wp_bx24;
/**
* Constructor function.
* @access public
* @since 1.0.0
*/
public function __construct () {
$this->token = 'starter-plugin';
$this->plugin_url = plugin_dir_url( __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->version = '1.0.0';
// Admin - Start
require_once( 'classes/class-starter-plugin-settings.php' );
$this->settings = Starter_Plugin_Settings::instance();
if ( is_admin() ) {
require_once( 'classes/class-starter-plugin-admin.php' );
$this->admin = Starter_Plugin_Admin::instance();
}
// Admin - End
require_once __DIR__ . '/classes/golden-code-wp-bx24.php';
$this->wp_bx24 = GoldenCodeWpBx24::instance();
$opts = $this->settings->get_settings();
$this->wp_bx24->registerAlias($opts['aliases']);
register_activation_hook( __FILE__, array( $this, 'install' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
} // End __construct()
/**
* Main Starter_Plugin Instance
*
* Ensures only one instance of Starter_Plugin is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see Starter_Plugin()
* @return Starter_Plugin Starter_Plugin instance
*/
public static function instance () {
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
} // End instance()
/**
* Load the localisation file.
* @access public
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'starter-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
} // End load_plugin_textdomain()
/**
* Cloning is forbidden.
* @access public
* @since 1.0.0
*/
public function __clone () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), '1.0.0' );
} // End __clone()
/**
* Unserializing instances of this class is forbidden.
* @access public
* @since 1.0.0
*/
public function __wakeup () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), '1.0.0' );
} // End __wakeup()
/**
* Installation. Runs on activation.
* @access public
* @since 1.0.0
*/
public function install () {
$this->_log_version_number();
} // End install()
/**
* Log the plugin version number.
* @access private
* @since 1.0.0
*/
private function _log_version_number () {
// Log the version number.
update_option( $this->token . '-version', $this->version );
} // End _log_version_number()
} // End Class
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment