configs = $configs;
$this->options = get_option( $this->configs['options'] );
$this->plugin_slug = $this->configs['plugin_slug'];
$this->plugin_name = $this->configs['plugin_name'];
}
$this->developer_mode = false;
add_action( 'admin_menu', array( $this, 'create_menu_page' ) );
add_action( 'admin_init', array( $this, 'initialize_plugin_options' ) );
// add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
}
/**
* Load Scripts
*/
public function scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
echo "
";
}
/**
* Register Menu items
*/
public function create_menu_page() {
add_options_page(
__( 'Telegram Submission', 'aus-basic' ),
__( 'AUS Telegram Bot' , 'aus-basic' ),
'manage_options',
$this->plugin_slug . '_plugin_options',
array( $this, 'menu_page_display' )
);
}
/**
* Main menu page display
*/
public function menu_page_display() {
$this->scripts();
?>
developer_mode ) : ?>
options ); ?>
plugin_name ); ?>
plugin_slug . '_plugin_settings_section',
'',
'',
$this->plugin_slug . '_plugin_options'
);
add_settings_field(
'bot_token',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'bot_token',
'type' => 'text',
'description' => __( 'Insert bot token', 'aus-basic' ),
)
);
add_settings_field(
'channelname',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'channelname',
'type' => 'text',
'description' => __( 'Insert @channelusername', 'aus-basic' ),
)
);
add_settings_field(
'start_date',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'start_date',
'type' => 'text',
'atts' => array( 'class' => 'aus-datepicker' ),
'description' => __( 'Insert from which date posts must be send. Format: 2015-01-02', 'aus-basic' ),
)
);
add_settings_field(
'categories',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'categories',
'type' => 'categories',
'atts' => array( 'multiple' => true ),
'description' => __( 'Select categories. If none is selected all categories will be used', 'aus-basic' ),
)
);
add_settings_field(
'recurrence',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'recurrence',
'type' => 'select',
'options' => array(
'hourly' =>'Once Hourly',
'twicedaily' => 'Twice Daily',
'daily' => 'Once Daily',
),
'description' => __( 'Select recurrence duration', 'aus-basic' ),
)
);
add_settings_field(
'text_limit',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'text_limit',
'type' => 'number',
'description' => __( 'Here you change the default (100 words) text limit.', 'aus-basic' ),
)
);
add_settings_field(
'before_text',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'before_text',
'type' => 'textarea',
'description' => __( 'Custom text before message.', 'aus-basic' ),
'editor' => array( 'visual' => false ),
)
);
add_settings_field(
'after_text',
'',
array( $this, 'input'),
$this->plugin_slug . '_plugin_options',
$this->plugin_slug . '_plugin_settings_section',
array(
'id' => 'after_text',
'type' => 'textarea',
'description' => __( 'Custom text after message.', 'aus-basic' ),
'editor' => array( 'visual' => false ),
)
);
register_setting(
$this->plugin_slug . '_plugin_options_group',
$this->plugin_slug . '_plugin_options',
array( $this, 'senitize')
);
}
public function senitize( $input ) {
$output = array();
foreach ($input as $key => $value) {
if ( isset( $input[ $key ] ) ) {
if ( is_array( $input[ $key ] ) ) {
foreach ( $input[ $key ] as $sub_key => $sub_value ) {
$output[ $key ][ $sub_key ] = strip_tags( stripslashes( $sub_value ) );
}
} else {
$output[ $key ] = strip_tags( stripslashes( $input[ $key ] ) );
}
}
}
return apply_filters( array( $this, 'senitize' ), $output, $input);
}
public function _esc_attr( $option ) {
if( isset( $this->options[ $option ] ) )
return $this->options[ $option ];
else
return false;
}
/**
* Initialize plugin options callbacks
*/
public function plugin_general_options_ballback() {
$html = '' . __( 'General Options', 'aus-basic' ) . '
';
//echo $html;
}
public function input( $args, $name_type = 'option', $post_id = false ) {
$defaults = array(
'id' => '',
'type' => '',
'title' => '',
'description' => '',
'options' => array(),
'editor' => array(
'visual' => true,
'teeny'=>true,
'textarea_rows'=>4,
),
'atts' => array(),
);
$configs = array_replace_recursive( $defaults, $args );
extract( $configs, EXTR_OVERWRITE );
if ( ( $type == 'select' || $type == 'cats' || $type == 'categories' ) && ! empty( $atts ) && array_key_exists( 'multiple', $atts ) ) {
$multiple = true;
} else {
$multiple = false;
}
if ( $name_type == 'option' ) {
$field_name = $this->plugin_slug . '_plugin_options' . '[' . $id . ']';
$value = $this->_esc_attr( $id, $type );
} elseif ( $name_type == 'metabox' && $post_id ) {
$field_name = $id;
$value = get_post_meta( $post_id, $id, true );
}
$editor['textarea_name'] = $field_name;
$attributes = '';
if( isset( $atts ) and ! empty( $atts ) ) {
foreach ($atts as $attribute => $attr_value) {
$attributes .= $attribute . '="' . $attr_value . '"';
}
}
switch ( $type ) {
case 'radio':
$input = '';
break;
case 'radioimage':
$input = '';
break;
case 'textarea':
if ( $editor['visual'] === true ) {
ob_start();
wp_editor($value, $id, $editor);
$input = ob_get_contents();
ob_end_clean();
} else {
$input = '';
}
break;
case 'select':
$input = '';
break;
case 'categories':
case 'cats':
$input = '';
break;
case 'thumbnails':
$input = '';
break;
case 'image':
$input = '';
$input .= '';
break;
case 'checkbox':
$input = '';
break;
default:
case 'email':
case 'text':
$input = '';
break;
}
$html = '';
$html .= $input;
if( ! empty( $description ) )
$html .= '' . $description . '
';
echo $html;
}
public function get_image_sizes( $size = '' ) {
global $_wp_additional_image_sizes;
$sizes = array();
$get_intermediate_image_sizes = get_intermediate_image_sizes();
// Create the full array with sizes and crop info
foreach( $get_intermediate_image_sizes as $_size ) {
if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
$sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
$sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
$sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
$sizes[ $_size ] = array(
'width' => $_wp_additional_image_sizes[ $_size ]['width'],
'height' => $_wp_additional_image_sizes[ $_size ]['height'],
'crop' => $_wp_additional_image_sizes[ $_size ]['crop']
);
}
}
// Get only 1 size if found
if ( $size ) {
if( isset( $sizes[ $size ] ) ) {
return $sizes[ $size ];
} else {
return false;
}
}
return $sizes;
}
}