Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #86 from coletivoEITA/develop
Browse files Browse the repository at this point in the history
Include possibility to customize options prefix
  • Loading branch information
jonathanbossenger authored Apr 19, 2020
2 parents 6f8656e + 65f7320 commit 5a5afdd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 56 deletions.
28 changes: 0 additions & 28 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,13 @@ module.exports = function( grunt ){
}
},

// Build a zip file for deployment
compress: {
main: {
options: {
archive: 'wordpress-plugin-template.zip'
},
files: [
{src: ['assets/css/*.css'], dest: 'assets/css/', filter: 'isFile'}, // includes css files in css path
{src: ['assets/js/*.min.js'], dest: 'assets/js/', filter: 'isFile'}, // includes js files in js path
{src: ['assets/**', '!assets/js', '!assets/css'], dest: 'assets/', filter: 'isFile'}, // includes any other assets outside js/css
{src: ['includes/**'], dest: 'includes/', filter: 'isFile'}, //includes files in includes path
{src: ['lang/**'], dest: 'lang/', filter: 'isFile' }, //includes files in lang path
{src: ['vendor/**'], dest: 'vendor/', filter: 'isFile' }, //includes files in lang path
{src: ['*.php', 'LICENSE', '*.txt'], filter: 'isFile' } //includes base directory files
]
}
}

});

grunt.loadTasks('tasks');

// Load NPM tasks to be used here
grunt.loadNpmTasks( 'grunt-contrib-less' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-contrib-compress' );

// Register tasks
grunt.registerTask( 'default', [
Expand All @@ -114,11 +93,4 @@ module.exports = function( grunt ){
'uglify'
]);

grunt.registerTask( 'build', [
'less',
'cssmin',
'uglify',
'compress'
])

};
9 changes: 9 additions & 0 deletions build-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DEFAULT_NAME="WordPress Plugin Template"
DEFAULT_CLASS=${DEFAULT_NAME// /_}
DEFAULT_TOKEN=$( tr '[A-Z]' '[a-z]' <<< $DEFAULT_CLASS)
DEFAULT_SLUG=${DEFAULT_TOKEN//_/-}
DEFAULT_OPT_PREFIX="wpt_"

printf "Plugin name: "
read NAME
Expand All @@ -23,12 +24,16 @@ fi
printf "Include Grunt support (y/n): "
read GRUNT

printf "Options prefix: "
read OPT_PREFIX

printf "Initialise new git repo (y/n): "
read NEWREPO


TOKEN=$( tr '[A-Z]' '[a-z]' <<< $CLASS)
SLUG=${TOKEN//_/-}
OPT_PREFIX=${OPT_PREFIX}_

git clone https://github.com/hlashbrooke/$DEFAULT_SLUG.git $FOLDER/$SLUG

Expand Down Expand Up @@ -126,6 +131,10 @@ cp class-$SLUG-settings.php class-$SLUG-settings.tmp
sed "s/$DEFAULT_SLUG/$SLUG/g" class-$SLUG-settings.tmp > class-$SLUG-settings.php
rm class-$SLUG-settings.tmp

cp class-$SLUG-settings.php class-$SLUG-settings.tmp
sed "s/$DEFAULT_OPT_PREFIX/$OPT_PREFIX/g" class-$SLUG-settings.tmp > class-$SLUG-settings.php
rm class-$SLUG-settings.tmp


cd lib
mv class-$DEFAULT_SLUG-post-type.php class-$SLUG-post-type.php
Expand Down
34 changes: 20 additions & 14 deletions includes/class-wordpress-plugin-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,15 @@ class WordPress_Plugin_Template {
*/
public $script_suffix;

/**
* Plugin Text Domain.
*
* @var string
* @access public
* @since 1.0.0
*/
public $text_domain;

/**
* Constructor funtion.
*
* @param string $file File constructor.
* @param string $version Plugin version.
*/
public function __construct( $file = '', $version = '1.0.0' ) {
$this->_version = $version;
$this->_token = 'wordpress_plugin_template';
$this->text_domain = 'wordpress-plugin-template';
$this->_version = $version;
$this->_token = 'wordpress_plugin_template';

// Load plugin environment variables.
$this->file = $file;
Expand All @@ -147,7 +137,7 @@ public function __construct( $file = '', $version = '1.0.0' ) {

// Handle localisation.
$this->load_plugin_textdomain();
add_action( 'init', array( $this, 'load_plugin_textdomain' ), 0 );
add_action( 'init', array( $this, 'load_localisation' ), 0 );
} // End __construct ()

/**
Expand Down Expand Up @@ -245,6 +235,17 @@ public function admin_enqueue_scripts( $hook = '' ) {
wp_enqueue_script( $this->_token . '-admin' );
} // End admin_enqueue_scripts ()

/**
* Load plugin localisation
*
* @access public
* @return void
* @since 1.0.0
*/
public function load_localisation() {
load_plugin_textdomain( 'wordpress-plugin-template', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
} // End load_localisation ()

/**
* Load plugin textdomain
*
Expand All @@ -253,7 +254,12 @@ public function admin_enqueue_scripts( $hook = '' ) {
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( $this->text_domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
$domain = 'wordpress-plugin-template';

$locale = apply_filters( 'plugin_locale', get_locale(), $domain );

load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
} // End load_plugin_textdomain ()

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/class-wordpress-plugin-template-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function updated_messages( $messages = array() ) {
3 => __( 'Custom field deleted.', 'wordpress-plugin-template' ),
4 => sprintf( __( '%1$s updated.', 'wordpress-plugin-template' ), $this->single ),
5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.', 'wordpress-plugin-template' ), $this->single, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __( '%1$s published. %2$sView %3$s%4$s.', 'wordpress-plugin-template' ), $this->single, '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->single, '</a>' ),
6 => sprintf( __( '%1$s published. %2$sView %3$s%4s.', 'wordpress-plugin-template' ), $this->single, '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->single, '</a>' ),
7 => sprintf( __( '%1$s saved.', 'wordpress-plugin-template' ), $this->single ),
8 => sprintf( __( '%1$s submitted. %2$sPreview post%3$s%4$s.', 'wordpress-plugin-template' ), $this->single, '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', $this->single, '</a>' ),
9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.', 'wordpress-plugin-template' ), $this->single, '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'wordpress-plugin-template' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->single, '</a>' ),
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-less": "^2.0.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-contrib-compress": "^1.4.3"
"grunt-contrib-watch": "^1.1.0"
}
}
11 changes: 0 additions & 11 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,3 @@
}

// Do something here if plugin is being uninstalled.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}

//change your plugin prefix here
delete_options_prefixed( 'test_' );

function delete_options_prefixed( $prefix ) {
global $wpdb;
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '{$prefix}%'" );
}

1 comment on commit 5a5afdd

@cornelRaiu
Copy link

@cornelRaiu cornelRaiu commented on 5a5afdd Apr 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanbossenger It seems that this PR merge overrode the changes in PR #89

Please sign in to comment.