summaryrefslogtreecommitdiff
path: root/WP
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-19 10:04:14 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-19 10:04:14 +0200
commitac93ed4d29dd85409fb4c0cd9c2af266e90777c1 (patch)
tree6a0b4487439bfe068d4b7d412be70d4f90faa2a5 /WP
initial commitHEADmain
Diffstat (limited to 'WP')
-rw-r--r--WP/plugin-deploy-script-for-wp-org.php44
-rw-r--r--WP/search-by-title-with-wp-query.php11
2 files changed, 55 insertions, 0 deletions
diff --git a/WP/plugin-deploy-script-for-wp-org.php b/WP/plugin-deploy-script-for-wp-org.php
new file mode 100644
index 0000000..3b66d49
--- /dev/null
+++ b/WP/plugin-deploy-script-for-wp-org.php
@@ -0,0 +1,44 @@
+#!/usr/bin/env php
+
+<?php
+
+$pluginSourcePath = $argv[1] ?? die('source path missing');
+$svnDestinationPath = $argv[2] ?? die('desination path missing');
+
+$pluginSourcePath = realpath($pluginSourcePath) ?: die('source path doesn\'t exist');
+$svnDestinationPath = realpath($svnDestinationPath) ?: die('desination path doesn\'t exist');
+
+if (! file_exists("$pluginSourcePath/composer.json")) {
+ die('plugin is missing a composer.json file');
+}
+if (! is_dir("$svnDestinationPath/.svn")) {
+ die('desination is not a svn repository. initialize it with "svn co https://plugins.svn.wordpress.org/your-plugin" first');
+}
+
+// get composer info
+$composer = json_decode(file_get_contents("$pluginSourcePath/composer.json"));
+
+// set files into deployable state
+chdir($pluginSourcePath);
+exec('composer install --no-dev');
+exec('npm run build'); # if wp-scripts is used # TODO: how to use with .nvmrc?
+
+// bundling deployable files
+exec('composer archive -f zip');
+$zipFilenames = glob('*.zip');
+$zipFilename = $zipFilenames[array_key_last($zipFilenames)];
+exec("unzip $pluginSourcePath/$zipFilename -d $svnDestinationPath/$zipFilename");
+
+// copying files to svn trunk folder
+chdir($svnDestinationPath);
+exec("rsync -av $svnDestinationPath/$zipFilename/ $svnDestinationPath/trunk --delete");
+
+// copy new version to tags
+exec('svn cp trunk tags/' . $composer->version);
+
+// commit
+exec("svn commit -m 'updating to v{$composer->version}'");
+
+// clean up files
+unlink("$pluginSourcePath/$zipFilename");
+exec("rm -rf $svnDestinationPath/$zipFilename"); # feeling dangerous
diff --git a/WP/search-by-title-with-wp-query.php b/WP/search-by-title-with-wp-query.php
new file mode 100644
index 0000000..418f057
--- /dev/null
+++ b/WP/search-by-title-with-wp-query.php
@@ -0,0 +1,11 @@
+<?php
+
+// Add posts_where filter for title_like
+add_filter('posts_where', function ($where, \WP_Query $wp_query) {
+ if ($title = $wp_query->get('title_like')) {
+ global $wpdb;
+ $where .= " AND {$wpdb->posts}.post_title LIKE '" . esc_sql($wpdb->esc_like($title)) . "'";
+ }
+
+ return $where;
+}, 10, 2);