Skip to content

Instantly share code, notes, and snippets.

https://code.tutsplus.com/ru/tutorials/object-oriented-php-for-beginners--net-12762
@qwersk
qwersk / check_admin.php
Created August 4, 2017 10:41
Check if user is admin #joomla
$user = JFactory::getUser();
$isroot = $user->authorise('core.admin');
if($isroot){
}
@qwersk
qwersk / filter_by_category.php
Created July 25, 2017 04:45
ADD FILTER BY CATEGORY IN ADMIN AREA #WORDPRESS #WP
function pippin_add_taxonomy_filters() {
global $typenow;
// an array of all the taxonomyies you want to display. Use the taxonomy name or slug
$taxonomies = array('course_category');
// must set this to the post type you want the filter(s) displayed on
if( $typenow == 'course' ){
foreach ($taxonomies as $tax_slug) {
@qwersk
qwersk / gist:0488736e9686874122632653a32aa572
Last active July 19, 2017 10:35
MULTIDIMENSIONAL ARRAY TO ONE DIMENSIONAL #PHP
// $array - array to convert
// return array
$result = array_reduce($array, "array_merge", array());
@qwersk
qwersk / joomla_avatars.php
Last active July 14, 2017 10:06
DISPLAY USER AVATAR #JOOMLA @JOOMLA2
// Установить плагин CMAvatar (https://extensions.joomla.org/extension/cmavatar/)
<?php
$user = JFactory::getUser();
require_once JPATH_PLUGINS . '/user/cmavatar/helper.php';
$avatar = PlgUserCMAvatarHelper::getAvatar($user->id);
//print_r($avatar);
?>
@qwersk
qwersk / set_same_height.js
Last active July 11, 2017 09:44
SET SAME HEIGHT #JS #JAVASCRIPT
function set_same_height(selector){
var max_height = 0;
$(selector).each(function(){
if($(this).height() > max_height){
max_height = $(this).height();
}
});
$(selector).each(function(){
$(this).height(max_height);
@qwersk
qwersk / show_acf_in_admin.php
Created July 7, 2017 10:37
SHOW ACF FIELD IN ADMIN AREA #WP #WORDPRESS
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
'location' => __ ( 'Location' ),
'price' => __ ( 'Price' )
) );
}
add_filter ( 'manage_course_posts_columns', 'add_acf_columns' );
function course_custom_column ( $column, $post_id ) {
switch ( $column ) {
@qwersk
qwersk / add_field_user.php
Created July 4, 2017 08:45
ADD CUSTOM FIELD TO USER PROFILE #WP #WORDPRESS
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="phone">Phone Number</label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your phone number.</span>
@qwersk
qwersk / github-oauth2-client.php
Created July 4, 2017 05:32
Simple PHP example of using Github's OAuth 2 API
<?php
define('OAUTH2_CLIENT_ID', '');
define('OAUTH2_CLIENT_SECRET', '');
$authorizeURL = 'https://github.com/login/oauth/authorize';
$tokenURL = 'https://github.com/login/oauth/access_token';
$apiURLBase = 'https://api.github.com/';
session_start();
@qwersk
qwersk / remove_get_param.php
Created July 3, 2017 05:48
REMOVE GET PARAMETER FROM URL #PHP
$query = $_SERVER['QUERY_STRING'];
$query_arr = explode("&", $query);
$count_arr = count($query_arr);
for($j = 0; $j < $count_arr; $j++){
if(strpos($query_arr[$j], "pagen") !== false){
//echo $j . "<br />";