Changeset 2562917
- Timestamp:
- 07/12/2021 02:30:16 PM (5 years ago)
- Location:
- quick-child-theme-generator
- Files:
-
- 21 added
- 7 edited
-
assets/Screenshot-4.png (added)
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (modified) (previous)
-
assets/screenshot-3.png (modified) (previous)
-
tags/2.0.0 (added)
-
tags/2.0.0/assets (added)
-
tags/2.0.0/assets/css (added)
-
tags/2.0.0/assets/css/jquery-ui.css (added)
-
tags/2.0.0/assets/css/qcthg_custom_style.css (added)
-
tags/2.0.0/assets/images (added)
-
tags/2.0.0/assets/images/qcthg-logo.png (added)
-
tags/2.0.0/assets/js (added)
-
tags/2.0.0/assets/js/qcthg_custom_script.js (added)
-
tags/2.0.0/includes (added)
-
tags/2.0.0/includes/qcthg_function.php (added)
-
tags/2.0.0/includes/qcthg_helper.php (added)
-
tags/2.0.0/index.php (added)
-
tags/2.0.0/init.php (added)
-
tags/2.0.0/quick-child-theme-generator.php (added)
-
tags/2.0.0/readme.txt (added)
-
tags/2.0.0/views (added)
-
tags/2.0.0/views/qcthg_menu.php (added)
-
tags/2.0.0/views/qcthg_template.php (added)
-
trunk/includes/qcthg_function.php (modified) (6 diffs)
-
trunk/includes/qcthg_helper.php (modified) (4 diffs)
-
trunk/quick-child-theme-generator.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/views/qcthg_template.php (added)
Legend:
- Unmodified
- Added
- Removed
-
quick-child-theme-generator/trunk/includes/qcthg_function.php
r2446397 r2562917 17 17 add_action('admin_enqueue_scripts', array('QCTHG_Main', 'qcthgEnqueueAssets')); 18 18 add_action('admin_post_qcthg_create_theme', array('QCTHG_Main', 'qcthgCreateChildTheme')); 19 add_action('admin_post_qcthg_create_template', array('QCTHG_Main', 'qcthgCreateBlankTemplate')); 19 20 if (isset($_COOKIE['qcthg_adminNotices']) && $_COOKIE['qcthg_adminNotices'] !== 0) { 20 21 ob_start(); 21 22 add_action( 'admin_notices', array('QCTHG_Helper', 'adminNoticeError')); 22 23 } 24 if (isset($_COOKIE['qcthg_adminNoticesSuccess']) && $_COOKIE['qcthg_adminNoticesSuccess'] !== 0) { 25 ob_start(); 26 add_action( 'admin_notices', array('QCTHG_Helper', 'adminNoticeSuccess')); 27 } 23 28 } 24 29 … … 28 33 public function qcthgPluginMenu() 29 34 { 30 add_ theme_page(35 add_menu_page( 31 36 'Quick Child Theme Generator', 32 37 'Quick Child Theme', … … 34 39 'quick-child-theme-generator', 35 40 array('QCTHG_Main', 'qcthgMenuPage'), 36 0 41 'dashicons-groups', 42 60 37 43 ); 44 45 add_submenu_page( 46 'quick-child-theme-generator', 47 'Create Template', 48 'Template', 49 'manage_options', 50 'quick-blank-template-generator', 51 array('QCTHG_Main', 'qcthgSubMenuTemplatePage'), 52 1 53 ); 54 38 55 } 39 56 … … 55 72 public function qcthgEnqueueAssets($hook) 56 73 { 57 if($hook === 'toplevel_page_quick-child-theme-generator' || $_GET['page'] === 'quick-child-theme-generator') { 74 if($hook === 'toplevel_page_quick-child-theme-generator' 75 || $hook === 'quick-child-theme_page_quick-blank-template-generator' 76 || $_GET['page'] === 'quick-child-theme-generator' 77 || $_GET['page'] === 'quick-blank-template-generator') { 58 78 wp_enqueue_script('jquery'); 59 79 wp_enqueue_script('jquery-ui-core'); … … 72 92 { 73 93 require_once(QCTHG_PATH.'/views/qcthg_menu.php'); 94 } 95 96 /** 97 * Added sub menu plugin page 98 */ 99 public function qcthgSubMenuTemplatePage() 100 { 101 require_once(QCTHG_PATH.'/views/qcthg_template.php'); 74 102 } 75 103 … … 283 311 } 284 312 313 /** 314 * Validate and create custom template 315 */ 316 public function qcthgCreateBlankTemplate() 317 { 318 if(!empty($_POST)) { 319 if(!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'qcthg_create_template')) { 320 wp_die('Ooops!!! you are not auththorized user.'); 321 } else { 322 if(empty(trim($_POST['tmp_name']))) { 323 $cookieValue = '<b>ERROR: </b> Missing template name'; 324 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 325 wp_redirect(wp_get_referer()); 326 exit; 327 } 328 329 $postedData = array(); 330 $postedData['template_name'] = sanitize_text_field($_POST['tmp_name']); 331 $postedData['header_name'] = empty(trim($_POST['tmp_header_name'])) ? '' : sanitize_text_field($_POST['tmp_header_name']); 332 $postedData['footer_name'] = empty(trim($_POST['tmp_footer_name'])) ? '' : sanitize_text_field($_POST['tmp_footer_name']); 333 334 QCTHG_Main::qcthgGenerateTemplateAssets($postedData); 335 336 $cookieValue = '<b>SUCCESS: </b> Template successfully created'; 337 QCTHG_Helper::qcthgSetCookies('qcthg_adminNoticesSuccess', $cookieValue); 338 wp_redirect(wp_get_referer()); 339 exit; 340 } 341 } 342 } 343 344 /** 345 * Validate/Refined custom template data 346 * @param [array] $data 347 */ 348 public function qcthgGenerateTemplateAssets($data) 349 { 350 $themeRoot = get_theme_root(); 351 $childThemeDir = get_stylesheet_directory(); 352 $templateName = QCTHG_Helper::qcthgSanitizeText($data['template_name']); 353 $refTemplateName = QCTHG_Helper::qcthgRefSanitizeText($templateName); 354 $refTemplateNameLowerCase = strtolower($refTemplateName); 355 $getActiveTheme = wp_get_theme(); 356 $parentThemeDirName = $getActiveTheme["Template"]; 357 $parentThemeDirPath = $themeRoot.'/'.$parentThemeDirName; 358 $scanPath = scandir($parentThemeDirPath, 1); 359 $scanChildPath = scandir($childThemeDir, 1); 360 361 if(empty($templateName)) { 362 $cookieValue = '<b>ERROR: </b>Special characters are not allowed in the template name! please try again.'; 363 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 364 wp_redirect(wp_get_referer()); 365 exit; 366 } 367 368 $chkTemplate = QCTHG_Helper::qcthgChkTemplateName($refTemplateNameLowerCase); 369 370 if($chkTemplate) { 371 $cookieValue = '<b>ERROR: </b>The template name <b>( template-'.$refTemplateNameLowerCase.'.php )</b> already exists in theme root directory!'; 372 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 373 wp_redirect(wp_get_referer()); 374 exit; 375 } 376 377 if(!empty($data['header_name'])) { 378 $headerFileNm = $data['header_name'].'.php'; 379 $findHeader = QCTHG_Helper::findHeaderFooter($headerFileNm, $scanChildPath); 380 381 if(!$findHeader) { 382 $cookieValue = '<b>ERROR: </b>Unable to find theme header! Please enter header name correctly'; 383 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 384 wp_redirect(wp_get_referer()); 385 exit; 386 } 387 388 } else { 389 $headerFileNm = 'header.php'; 390 /* check default header exists in child/parent theme */ 391 if(!QCTHG_Helper::findHeaderFooter('header.php', $scanPath) && !QCTHG_Helper::findHeaderFooter('header.php', $scanChildPath)) { 392 $cookieValue = '<b>ERROR: </b>Unable to find theme header'; 393 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 394 wp_redirect(wp_get_referer()); 395 exit; 396 } 397 } 398 399 if(!empty($data['footer_name'])) { 400 $footerFileNm = $data['footer_name'].'.php'; 401 $findFooter = QCTHG_Helper::findHeaderFooter($footerFileNm, $scanChildPath); 402 403 if(!$findFooter) { 404 $cookieValue = '<b>ERROR: </b>Unable to find theme footer! Please enter footer name correctly'; 405 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 406 wp_redirect(wp_get_referer()); 407 exit; 408 } 409 410 } else { 411 $footerFileNm = 'footer.php'; 412 /* check default footer exists in child/parent theme */ 413 if(!QCTHG_Helper::findHeaderFooter('footer.php', $scanChildPath) && !QCTHG_Helper::findHeaderFooter('footer.php', $scanPath)) { 414 $cookieValue = '<b>ERROR: </b>Unable to find theme footer'; 415 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 416 wp_redirect(wp_get_referer()); 417 exit; 418 } 419 } 420 421 $result['template'] = QCTHG_Main::qcthgCreateBlankTemplatePhp($childThemeDir, $refTemplateNameLowerCase, $templateName, $headerFileNm, $footerFileNm); 422 return $result; 423 } 424 425 /** 426 * Create blank template php file (with header/footer) 427 * @param [string] $childThemeDir 428 * @param [string] $refTemplateNameLowerCase 429 * @param [string] $templateName 430 * @param [string] $headerFileNm 431 * @param [string] $footerFileNm 432 * @return [string] 433 */ 434 public function qcthgCreateBlankTemplatePhp($childThemeDir, $refTemplateNameLowerCase, $templateName, $headerFileNm, $footerFileNm) 435 { 436 $headerFileNmEx = explode('.', $headerFileNm); 437 $footerFileNmEx = explode('.', $footerFileNm); 438 $headerNm = 'get_header();'; 439 $footerNm = 'get_footer();'; 440 441 if($headerFileNmEx[0] != 'header') { 442 $headerExplode = explode('-', $headerFileNmEx[0]); 443 $hedrNm = ''; 444 foreach ($headerExplode as $k => $v) { 445 if($k > 0) { $hedrNm .= $v; } 446 } 447 $headerNm = 'get_header("'.$hedrNm.'");'; 448 } 449 450 if($footerFileNmEx[0] != 'footer') { 451 $footerExplode = explode('-', $footerFileNmEx[0]); 452 $fotrNm = ''; 453 foreach ($footerExplode as $k => $v) { 454 if($k > 0) { $fotrNm .= $v; } 455 } 456 $footerNm = 'get_footer("'.$fotrNm.'");'; 457 } 458 459 $phpContent = "<?php" . PHP_EOL; 460 $phpContent .= '/*' . PHP_EOL; 461 $phpContent .= 'Template Name: ' . $templateName . PHP_EOL; 462 $phpContent .= '*/' . PHP_EOL; 463 $phpContent .= "{$headerNm}" . PHP_EOL; 464 $phpContent .= "?>" . PHP_EOL . PHP_EOL; 465 $phpContent .= "<!-- Place your custom page code here -->" . PHP_EOL . PHP_EOL; 466 $phpContent .= "<?php" . PHP_EOL; 467 $phpContent .= "{$footerNm}" . PHP_EOL; 468 $phpContent .= "?>"; 469 470 if(file_put_contents($childThemeDir.'/template-'.$refTemplateNameLowerCase.'.php', $phpContent, LOCK_EX)) { 471 return 'success'; 472 } else { 473 $cookieValue = '<b>ERROR: </b>Permissions denied!' .PHP_EOL. 'Unable to create <b>template file</b>. Please set the write permissions for following path: ' .PHP_EOL. $childThemeDir; 474 QCTHG_Helper::qcthgSetCookies('', $cookieValue); 475 wp_redirect(wp_get_referer()); 476 exit; 477 } 478 } 479 285 480 } 286 481 } -
quick-child-theme-generator/trunk/includes/qcthg_helper.php
r2446397 r2562917 101 101 102 102 /** 103 * Set cookies for one hour103 * Set cookies for 60 seconds 104 104 * @param $cookieName 105 105 * @param $cookieValue … … 110 110 $cookieName = "qcthg_adminNotices"; 111 111 } 112 setcookie($cookieName, $cookieValue, time() + ( 3600), "/");112 setcookie($cookieName, $cookieValue, time() + (60), "/"); 113 113 } 114 114 … … 123 123 <?php 124 124 unset($_COOKIE['qcthg_adminNotices']); 125 setcookie('qcthg_adminNotices', 0, time() - 3600, '/'); 125 setcookie('qcthg_adminNotices', 0, time() - 60, '/'); 126 } 127 128 /** 129 * Display dynamic success notices (destroy current cookies) 130 */ 131 public function adminNoticeSuccess() { 132 ?> 133 <div class="notice notice-success is-dismissible qcthgErrNotice"> 134 <p><?php _e(str_replace('\\\\', '\\', $_COOKIE['qcthg_adminNoticesSuccess']), 'quck-child-theme-generator'); ?></p> 135 </div> 136 <?php 137 unset($_COOKIE['qcthg_adminNoticesSuccess']); 138 setcookie('qcthg_adminNoticesSuccess', 0, time() - 60, '/'); 126 139 } 127 140 … … 150 163 } 151 164 165 /** 166 * Check template name exist in theme root directory or not 167 * @param $templateName 168 * @return [boolean] 169 */ 170 public function qcthgChkTemplateName($templateName) 171 { 172 $res = locate_template('template-'.$templateName.'.php'); 173 174 if($res == false) { 175 return false; 176 } 177 return true; 178 } 179 180 /** 181 * find the files in specfic path 182 * @param $fileNm 183 * @param $scanPath 184 * @return [boolean] 185 */ 186 public function findHeaderFooter($fileNm, $scanPath) 187 { 188 $find = false; 189 if(in_array($fileNm, $scanPath)) { 190 $find = true; 191 } 192 return $find; 193 } 194 152 195 } 153 196 } -
quick-child-theme-generator/trunk/quick-child-theme-generator.php
r2446397 r2562917 3 3 * Plugin Name: Quick Child Theme Generator 4 4 * Plugin URI: https://sharmajay.com/quick-child-theme-generator 5 * Description: This plugin allows us to generate a quick and easy free child theme .6 * Version: 1.1.35 * Description: This plugin allows us to generate a quick and easy free child theme and you can create custom templates as well. 6 * Version: 2.0.0 7 7 * Author: Ajay Kumar 8 8 * Author URI: https://sharmajay.com -
quick-child-theme-generator/trunk/readme.txt
r2446397 r2562917 2 2 Contributors: ajay930 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HDAU63WNAT4TL 4 Tags: child theme, childtheme, design, theme, t hemes, quick theme, childthemes4 Tags: child theme, childtheme, design, theme, template, themes, quick theme, childthemes 5 5 Requires at least: 4.7 6 Tested up to: 5. 67 Stable tag: 1.1.36 Tested up to: 5.8 7 Stable tag: 2.0.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 14 14 15 15 Quick Child Theme Generator is a very easy, quick and user friendly plugin to create a child theme for any theme supported by WordPress CMS. It allows you to edit or add functionality to your template without having to overwrite any of the parent theme files and it will helpful for restrict losing data on WP update time. You do not need to deal with any code and configuration to create child themes. It will reduce your `time` and `effort` to create a child theme. 16 17 This plugin is providing you a way to create basic custom templates pages, those will help you to add custom code in specific pages. 16 18 17 19 == Installation == … … 42 44 2. Select a parent theme from the drop-down list and fill the fields. Then click on the Create Now button. 43 45 3. Here is information about the plugin and contact. 46 4. Enter any template name and fill other fields as per your requirements. Then click on the Create Template button. 44 47 45 48 == Changelog == 49 50 = 2.0.0 = 51 * Added create custom template feature. 52 * Updated menu and added sub menu. 53 * Added updated instruction images. 46 54 47 55 = 1.1.3 = … … 64 72 == Upgrade Notice == 65 73 74 = 2.0.0 = 75 Added create custom template feature. 76 66 77 = 1.1.3 = 67 78 Remove plugin page menu from the main menu and added sub menu for it to the Appearance menu.
Note: See TracChangeset
for help on using the changeset viewer.