Skip to content

Instantly share code, notes, and snippets.

View nash-ye's full-sized avatar
🎯
Focusing

Nashwan Doaqan nash-ye

🎯
Focusing
View GitHub Profile
@nash-ye
nash-ye / wp-fix-attachment-capabilities.php
Created November 3, 2020 11:00
Fixing WordPress Attachment Capabilities
<?php
add_filter(
'register_post_type_args',
function ($args, $postType) {
if ('attachment' === $postType) {
$args['capabilities']['edit_posts']   = 'upload_files';
$args['capabilities']['upload_files'] = 'upload_files';
}
@nash-ye
nash-ye / command-loop-wp-cli-search-replace.bash.sh
Last active July 18, 2023 12:12
A Linux command to loop through CSV file records and do WP search-replace.
while IFS=, read orig new; do wp --skip-themes --skip-plugins search-replace "$orig" "$new" wp_posts --include-columns=post_content --verbose; done < example.csv
@nash-ye
nash-ye / gitattributes-export-ignore-sample.txt
Last active May 22, 2020 16:54
gitattributes Sample for PHP apps
/dist export-ignore
/test export-ignore
/docs export-ignore
.gitignore export-ignore
.gitattributes export-ignore
@nash-ye
nash-ye / wp-include-cpt-in-dashboard-activity-widget.php
Created July 23, 2019 19:40
Include Custom Post Types In WordPress "Activity" Dashboard Widget
<?php
add_filter('dashboard_recent_posts_query_args', function(array $queryArgs) {
$postTypes = get_post_types([
'public' => true,
'capability_type' => 'post',
]);
if (is_array($postTypes)) {
$queryArgs['post_type'] = $postTypes;
@nash-ye
nash-ye / wp-disallow-authors-assigning-post-tags.php
Last active July 22, 2019 21:00
Disallow authors in WordPress from assigning post tags.
<?php
add_action('registered_taxonomy', function($taxonomy) {
global $wp_taxonomies;
if ('post_tag' === $taxonomy) {
$wp_taxonomies[$taxonomy]->cap->assign_terms = 'edit_others_posts';
}
});
(function($) {
'use strict';
$(function() {
$(document.body).one('click.add-media-button', '.insert-media', function(event) {
var orginalInsertCallback = wp.media.editor.insert;
wp.media.editor.insert = function(html) {
var image = $('img', $("<div>" + html + "</div>"));
if (! image.attr('alt')) {
var confirmed = confirm("An image without alternative text had been inserted!");
if (confirmed) {
@nash-ye
nash-ye / criteria-to-query-builder.php
Created May 24, 2016 01:59 — forked from jgornick/criteria-to-query-builder.php
Doctrine: Criteria Array to Doctrine QueryBuilder
<?php
/**
* Recursively takes the specified criteria and adds too the expression.
*
* The criteria is defined in an array notation where each item in the list
* represents a comparison <fieldName, operator, value>. The operator maps to
* comparison methods located in ExpressionBuilder. The key in the array can
* be used to identify grouping of comparisons.
*
<?php
$hosts = [];
$doc = new DOMDocument();
$doc->loadHTMLFile("report-2015.html");
$historyTable = $doc->getElementById('history');
$historyTableRows = $historyTable->getElementsByTagName('tr');
@nash-ye
nash-ye / hacks.php
Last active June 25, 2020 13:58
bbPress (Topics and Repiles) Numeric Permalinks
<?php
if ( ! did_action( 'bbp_after_setup_actions' ) ) {
add_action( 'bbp_after_setup_actions', 'n5n_after_bbPress_setup' );
} else {
n5n_after_bbPress_setup();
}
/**
* After bbPress Setup.
@nash-ye
nash-ye / functions.php
Last active August 29, 2015 14:06
Retrieves post data given a post name, type and parent ID.
<?php
/**
* Retrieves post data given a post name, type and parent ID.
*
* @return WP_Post|NULL
*/
function get_post_by_name( array $args ) {
global $wpdb;